org.zkoss.zul
Class ArrayGroupsModel

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

public class ArrayGroupsModel
extends AbstractGroupsModel
implements GroupsModelExt

An array implementation of GroupsModel. This implementation supports regroup array to groups depends on Comparator and GroupComparator.

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

Field Summary
protected  boolean[] _closes
          member field to store group close status
protected  java.util.Comparator _comparator
          member field to store Comparator for initial grouping.
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
protected  java.lang.Object[] _nativedata
          member field to store native array data
 
Constructor Summary
ArrayGroupsModel(java.lang.Object[] data, java.util.Comparator cmpr)
          Constructor
ArrayGroupsModel(java.lang.Object[] data, java.util.Comparator cmpr, int col)
           
 
Method Summary
protected  boolean createGroupClose(java.lang.Object[] groupdata, int index, int col)
          create group close status, default implementation return false, which means open the group.
protected  java.lang.Object createGroupFoot(java.lang.Object[] groupdata, int index, int col)
          create group foot Object, default implementation return null, which means no foot .
protected  java.lang.Object createGroupHead(java.lang.Object[] groupdata, int index, int col)
          create group head Object, default implementation return first element of groupdata.
 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 col)
          Groups and sorts the data by the specified column.
 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.
protected  void organizeGroup(java.util.Comparator cmpr, int col)
          Organizes groups based sorted data.
 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 col)
          It called when Listbox or Grid has to sort the content.
protected  void sortDataInGroupOrder(java.util.Comparator cmpr, boolean ascending, int colIndex)
          Sorts the native data in the group order.
protected  void sortGroupData(java.lang.Object group, java.lang.Object[] groupdata, java.util.Comparator cmpr, boolean ascending, int col)
          Sorts data within a group.
 
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

_nativedata

protected java.lang.Object[] _nativedata
member field to store native array data


_comparator

protected java.util.Comparator _comparator
member field to store Comparator for initial grouping.


_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
member field to store group close status

Constructor Detail

ArrayGroupsModel

public ArrayGroupsModel(java.lang.Object[] data,
                        java.util.Comparator cmpr)
Constructor

Parameters:
data - an array data to be grouping.
cmpr - a comparator implementation help group the data. you could implements GroupComparator to do more grouping control.
At 1st phase, it calls Comparator.compare(Object, Object) or GroupComparator.compareGroup(Object, Object) to sort the data.
At 2nd phase, it calls Comparator.compare(Object, Object) or GroupComparator.compareGroup(Object, Object) to decide which data belong to which group. In this phase it also invoke createGroupHead(Object[], int, int) and createGroupFoot(Object[], int, int) to create head of foot Object of each group.
At 3rd phase, it calls Comparator.compare(Object, Object) to sort data in each group.

ArrayGroupsModel

public ArrayGroupsModel(java.lang.Object[] data,
                        java.util.Comparator cmpr,
                        int col)
Parameters:
data - an array data to be grouping.
cmpr - a comparator implementation help group the data. you could implements GroupComparator to do more grouping control.
At 1st phase, it calls Comparator.compare(Object, Object) or GroupComparator.compareGroup(Object, Object) to sort the data.
At 2nd phase, it calls Comparator.compare(Object, Object) or GroupComparator.compareGroup(Object, Object) to decide which data belong to which group. In this phase it also invoke createGroupHead(Object[], int, int) and createGroupFoot(Object[], int, int) to create head of foot Object of each group.
At 3rd phase, it calls Comparator.compare(Object, Object) to sort data in each group.
col - column index associate with cmpr.
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.

sort

public void sort(java.util.Comparator cmpr,
                 boolean ascending,
                 int col)
Description copied from interface: GroupsModelExt
It called when Listbox or Grid has to sort the content.

After sorting, this model shall notify the instances of ListDataListener (registered thru ListModel.addListDataListener(org.zkoss.zul.event.ListDataListener)) to update the content. Typically you have to notify with

new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, -1, -1)
to denote all data are changed (and reloading is required).

The comparator assigned to, say, Listheader.setSortAscending(java.util.Comparator) is passed to method as the cmpr argument. Thus, developers could use it as a tag to know which column or what kind of order to sort.

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)
col - the index of the column

group

public void group(java.util.Comparator cmpr,
                  boolean ascending,
                  int col)
Description copied from interface: GroupsModelExt
Groups and sorts the data by the specified column. It only called when Listbox or Grid has the sort function.

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)
col - the index of the column

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.

sortGroupData

protected void sortGroupData(java.lang.Object group,
                             java.lang.Object[] groupdata,
                             java.util.Comparator cmpr,
                             boolean ascending,
                             int col)
Sorts data within a group. Notice that this method doesn't fire event.

There are three steps to re-group data: sortDataInGroupOrder(java.util.Comparator, boolean, int), organizeGroup(java.util.Comparator, int) and then sortGroupData(java.lang.Object, java.lang.Object[], java.util.Comparator, boolean, int).

It is the last step of grouping. It sorts data in the specified group.


organizeGroup

protected void organizeGroup(java.util.Comparator cmpr,
                             int col)
Organizes groups based sorted data.

There are three steps to re-group data: sortDataInGroupOrder(java.util.Comparator, boolean, int), organizeGroup(java.util.Comparator, int) and then sortGroupData(java.lang.Object, java.lang.Object[], java.util.Comparator, boolean, int).

It is the second step of grouping. It creates group data based on the data sorted in the group order by sortDataInGroupOrder(java.util.Comparator, boolean, int).

Parameters:
cmpr - the comparator used to compare data in the group order. Notice that the comparator is never an instance of GroupComparator. The implementation just uses Comparator.compare(java.lang.Object, java.lang.Object) to sort the data.
col - column index

createGroupHead

protected java.lang.Object createGroupHead(java.lang.Object[] groupdata,
                                           int index,
                                           int col)
create group head Object, default implementation return first element of groupdata. you can override this method to return your Object.

Parameters:
groupdata - data the already in a group.
index - group index
col - column to group

createGroupFoot

protected java.lang.Object createGroupFoot(java.lang.Object[] groupdata,
                                           int index,
                                           int col)
create group foot Object, default implementation return null, which means no foot . you can override this method to return your Object.

Parameters:
groupdata - data the already in a group.
index - group index
col - column to group

sortDataInGroupOrder

protected void sortDataInGroupOrder(java.util.Comparator cmpr,
                                    boolean ascending,
                                    int colIndex)
Sorts the native data in the group order. After sorted, all data in the first group shall be placed in front of the second group, and so on.

There are three steps to re-group data: sortDataInGroupOrder(java.util.Comparator, boolean, int), organizeGroup(java.util.Comparator, int) and then sortGroupData(java.lang.Object, java.lang.Object[], java.util.Comparator, boolean, int).

Parameters:
cmpr - the comparator used to compare data in the group order. Notice that the comparator is never an instance of GroupComparator. The implementation just uses Comparator.compare(java.lang.Object, java.lang.Object) to sort the data.

createGroupClose

protected boolean createGroupClose(java.lang.Object[] groupdata,
                                   int index,
                                   int col)
create group close status, default implementation return false, which means open the group. you can override this method to return your group close status.

Parameters:
groupdata - data the already in a group.
index - group index
col - column to group
Since:
5.0.0


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