org.zkoss.zul
Class SimpleGroupsModel

java.lang.Object
  extended by org.zkoss.zul.AbstractGroupsModel
      extended by org.zkoss.zul.SimpleGroupsModel
All Implemented Interfaces:
GroupsModel, GroupsModelExt

public class SimpleGroupsModel
extends AbstractGroupsModel
implements GroupsModelExt

A simple implementation of GroupsModel. Note: It assumes the content is immutable.

Since:
3.5.0
Author:
Dennis.Chen
See Also:
GroupsModel

Field Summary
protected  boolean[] _closes
          memeber field to store group close status
protected  java.lang.Object[][] _data
          member field to store group data
protected  java.lang.Object[] _foots
          member field to store group foot data
protected  java.lang.Object[] _heads
          member field to store group head data
 
Constructor Summary
SimpleGroupsModel(java.lang.Object[][] data)
          Constructs a groups data model with a two-dimensional array of data.
SimpleGroupsModel(java.lang.Object[][] data, java.lang.Object[] heads)
          Constructor When using this constructor , getGroup(int) will return the corresponding Object depends on heads.
SimpleGroupsModel(java.lang.Object[][] data, java.lang.Object[] heads, java.lang.Object[] foots)
          Constructor When using this constructor , getGroup(int) will return the corresponding Object depends on heads.
SimpleGroupsModel(java.lang.Object[][] data, java.lang.Object[] heads, java.lang.Object[] foots, boolean[] closes)
          Constructor When using this constructor , getGroup(int) will return the corresponding Object depends on heads.
 
Method Summary
 java.lang.Object getChild(int groupIndex, int index)
          Returns the child value of the specified group at the specified index.
 int getChildCount(int groupIndex)
          Returns the number of children of the specified group.
 java.lang.Object getGroup(int groupIndex)
          Returns the group value at the specified index.
 int getGroupCount()
          Returns the number of groups.
 java.lang.Object getGroupfoot(int groupIndex)
          Returns the foot value of the specified group.
 void group(java.util.Comparator cmpr, boolean ascending, int colIndex)
          Do nothing in default implementation, however developer can override it to re-group by manipulating _data,_heads,_foots
 boolean hasGroupfoot(int groupIndex)
          Returns if the specified group has a foot value.
 boolean isClose(int groupIndex)
          Whether the group is close at the specified index.
 void setClose(int groupIndex, boolean close)
          Sets whether the group is close at the specified index.
 void sort(java.util.Comparator cmpr, boolean ascending, int colIndex)
          Sort each data in each group by Comparator, developer could override sortGroupData(Object, Object[], Comparator, boolean, int) to customize.
protected  void sortGroupData(java.lang.Object group, java.lang.Object[] groupdata, java.util.Comparator cmpr, boolean ascending, int colIndex)
           
 
Methods inherited from class org.zkoss.zul.AbstractGroupsModel
addGroupsDataListener, fireEvent, removeGroupsDataListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_data

protected java.lang.Object[][] _data
member field to store group data


_heads

protected java.lang.Object[] _heads
member field to store group head data


_foots

protected java.lang.Object[] _foots
member field to store group foot data


_closes

protected boolean[] _closes
memeber field to store group close status

Constructor Detail

SimpleGroupsModel

public SimpleGroupsModel(java.lang.Object[][] data)
Constructs a groups data model with a two-dimensional array of data. For example, if you have three groups and each of them have 5 elements, then the data argument must be a 3 x 5 array. Furthermore, data[0] is the array of elements of the first group, data[1] is elements of the second group, and so on. Of course, each group might have different number of elements.

This constructor assumes there is no group foot at all.

Parameters:
data - a two-dimensional array to represent groups data, where data[0] is the array of element of the first group, data[1] is of the second group and so on.

SimpleGroupsModel

public SimpleGroupsModel(java.lang.Object[][] data,
                         java.lang.Object[] heads)
Constructor When using this constructor , getGroup(int) will return the corresponding Object depends on heads. hasGroupfoot(int) will always return false

Parameters:
data - a 2 dimension array to represent groups data
heads - an array to represent head data of group

SimpleGroupsModel

public SimpleGroupsModel(java.lang.Object[][] data,
                         java.lang.Object[] heads,
                         java.lang.Object[] foots)
Constructor When using this constructor , getGroup(int) will return the corresponding Object depends on heads. The return value of hasGroupfoot(int) and getGroupfoot(int) are depends on foots.

Parameters:
data - a 2 dimension array to represent groups data
heads - an array to represent head data of group
foots - an array to represent foot data of group, if an element in this array is null, then hasGroupfoot(int) will return false in corresponding index.

SimpleGroupsModel

public SimpleGroupsModel(java.lang.Object[][] data,
                         java.lang.Object[] heads,
                         java.lang.Object[] foots,
                         boolean[] closes)
Constructor When using this constructor , getGroup(int) will return the corresponding Object depends on heads. The return value of hasGroupfoot(int) and getGroupfoot(int) are depends on foots.

Parameters:
data - a 2 dimension array to represent groups data
heads - an array to represent head data of group
foots - an array to represent foot data of group, if an element in this array is null, then hasGroupfoot(int) will return false in corresponding index.
closes - an array of boolean to represent close status of group. If not specified, then isClose(int) will return false in corresponding index(i.e. group is default to open)
Method Detail

getChild

public java.lang.Object getChild(int groupIndex,
                                 int index)
Description copied from interface: GroupsModel
Returns the child value of the specified group at the specified index.

Specified by:
getChild in interface GroupsModel
Parameters:
groupIndex - the index of the group.
index - the index of the element in the group.

getChildCount

public int getChildCount(int groupIndex)
Description copied from interface: GroupsModel
Returns the number of children of the specified group.

Note: it does not include the groot foot (GroupsModel.getGroupfoot(int)).

Specified by:
getChildCount in interface GroupsModel
Parameters:
groupIndex - the index of the group.

getGroup

public java.lang.Object getGroup(int groupIndex)
Description copied from interface: GroupsModel
Returns the group value at the specified index. It is used to render Group and Listgroup.

Specified by:
getGroup in interface GroupsModel
Parameters:
groupIndex - the index of the group.

getGroupCount

public int getGroupCount()
Description copied from interface: GroupsModel
Returns the number of groups.

Specified by:
getGroupCount in interface GroupsModel

getGroupfoot

public java.lang.Object getGroupfoot(int groupIndex)
Description copied from interface: GroupsModel
Returns the foot value of the specified group. It is used to render Groupfoot and Listgroupfoot.

Note: it is ignored if GroupsModel.hasGroupfoot(int) returns false.

Specified by:
getGroupfoot in interface GroupsModel
Parameters:
groupIndex - the index of the group.

hasGroupfoot

public boolean hasGroupfoot(int groupIndex)
Description copied from interface: GroupsModel
Returns if the specified group has a foot value.

Specified by:
hasGroupfoot in interface GroupsModel
Parameters:
groupIndex - the index of the group.

isClose

public boolean isClose(int groupIndex)
Description copied from interface: GroupsModel
Whether the group is close at the specified index. It is used to render Group and Listgroup.

Specified by:
isClose in interface GroupsModel
Parameters:
groupIndex - the index of the group.

setClose

public void setClose(int groupIndex,
                     boolean close)
Description copied from interface: GroupsModel
Sets whether the group is close at the specified index. It is used to render Group and Listgroup.

Specified by:
setClose in interface GroupsModel
Parameters:
groupIndex - the index of the group.
close - true to close the Group.

group

public void group(java.util.Comparator cmpr,
                  boolean ascending,
                  int colIndex)
Do nothing in default implementation, however developer can override it to re-group by manipulating _data,_heads,_foots

Specified by:
group in interface GroupsModelExt
Parameters:
cmpr - the comparator assigned to Column.setSortAscending(java.util.Comparator) and other relative methods. If developers didn't assign any one, the method is returned directly.
ascending - whether to sort in the ascending order (or in the descending order)
colIndex - the index of the column

sort

public void sort(java.util.Comparator cmpr,
                 boolean ascending,
                 int colIndex)
Sort each data in each group by Comparator, developer could override sortGroupData(Object, Object[], Comparator, boolean, int) to customize.

Specified by:
sort in interface GroupsModelExt
Parameters:
cmpr - the comparator assigned to Listheader.setSortAscending(java.util.Comparator) and other relative methods. If developers didn't assign any one, the default comparator is used.
ascending - whether to sort in the ascending order (or in the descending order)
colIndex - the index of the column

sortGroupData

protected void sortGroupData(java.lang.Object group,
                             java.lang.Object[] groupdata,
                             java.util.Comparator cmpr,
                             boolean ascending,
                             int colIndex)


Copyright © 2005-2009 Potix Corporation. All Rights Reserved. SourceForge.net Logo