public class GroupsModelArray<D,H,F,E> extends AbstractGroupsModel<D,H,F,E> implements GroupsSortableModel<D>, ComponentCloneListener, java.lang.Cloneable
GroupsModel
.
This implementation takes a list of elements that are not grouped yet,
and a comparator that will be used to group them.
The c supports regroup array to groups depends on Comparator
and GroupComparator
.
For immutable content (no re-grouping allowed), please use SimpleGroupsModel
instead.
Generics:
For more information, please refer to ZK Developer's Reference: Groups Model
By default, the model support cloneable when the component is cloned. (since 6.0.0)
GroupsModel
,
SimpleGroupsModel
,
GroupComparator
,
ComponentCloneListener
,
Serialized FormAbstractGroupsModel.DefaultSelectionControl<E>
Modifier and Type | Field and Description |
---|---|
protected java.util.Comparator<D> |
_comparator
member field to store Comparator for initial grouping.
|
protected D[][] |
_data
member field to store group data
|
protected java.lang.Object[] |
_foots
member field to store group foot data (generated in
organizeGroup(java.util.Comparator<D>, int) ) |
protected java.lang.Object[] |
_heads
member field to store group head data (generated in
organizeGroup(java.util.Comparator<D>, int) ) |
protected D[] |
_nativedata
member field to store native (original) array data
|
protected boolean[] |
_opens
member field to store group close status
|
_selection
Constructor and Description |
---|
GroupsModelArray(D[] data,
java.util.Comparator<D> cmpr)
Constructor with an array of data.
|
GroupsModelArray(D[] data,
java.util.Comparator<D> cmpr,
int col)
Constructor with an array of data.
|
GroupsModelArray(D[] data,
java.util.Comparator<D> cmpr,
int col,
boolean clone)
Constructor with an array of data.
|
GroupsModelArray(java.util.List<D> data,
java.util.Comparator cmpr)
Deprecated.
As of release 6.0.1, there is no way to instantiate
the array with the correct type.
|
GroupsModelArray(java.util.List<D> data,
java.util.Comparator cmpr,
int col)
Deprecated.
As of release 6.0.1, there is no way to instantiate
the array with the correct type.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addOpenGroup(int groupIndex)
Opens the group at the specified index.
|
java.lang.Object |
clone() |
protected F |
createGroupFoot(D[] groupdata,
int index,
int col)
create group foot Object, default implementation return null, which means no foot .
|
protected H |
createGroupHead(D[] groupdata,
int index,
int col)
create group head Object, default implementation return first element of groupdata.
|
protected boolean |
createGroupOpen(D[] groupdata,
int index,
int col)
create group open status, default implementation return true, which means open the group.
|
boolean |
equals(java.lang.Object o) |
D |
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.
|
H |
getGroup(int groupIndex)
Returns the group value at the specified index.
|
int |
getGroupCount()
Returns the number of groups.
|
F |
getGroupfoot(int groupIndex)
Returns the foot value of the specified group, or null if the specified group
does not have any foot.
|
void |
group(java.util.Comparator<D> 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.
|
int |
hashCode() |
boolean |
isClose(int groupIndex)
Deprecated.
As of release 6.0.0, replace with
isGroupOpened(int) |
boolean |
isGroupOpened(int groupIndex)
Whether the group is open at the specified index.
|
protected void |
organizeGroup(java.util.Comparator<D> cmpr,
int col)
Organizes groups based sorted data.
|
boolean |
removeOpenGroup(int groupIndex)
Closes the group at the specified index.
|
void |
setClose(int groupIndex,
boolean close)
Deprecated.
As of release 6.0.0, replace with
addOpenGroup(int)
and removeOpenGroup(int) . |
void |
sort(java.util.Comparator<D> cmpr,
boolean ascending,
int col)
|
protected void |
sortDataInGroupOrder(java.util.Comparator<D> cmpr,
boolean ascending,
int colIndex)
Sorts the native data in the group order.
|
protected void |
sortGroupData(H group,
D[] groupdata,
java.util.Comparator<D> cmpr,
boolean ascending,
int col)
Sorts data within a group.
|
java.lang.String |
toString() |
java.lang.Object |
willClone(Component comp)
Allows the model to clone
|
addGroupsDataListener, addToSelection, clearSelection, fireEvent, fireSelectionEvent, getSelection, getSelectionControl, isGroupSelectable, isMultiple, isSelected, isSelectionEmpty, newEmptySelection, readSelection, removeAllSelection, removeFromSelection, removeGroupsDataListener, retainAllSelection, setGroupSelectable, setMultiple, setSelection, setSelectionControl, writeSelection
protected D[] _nativedata
protected java.util.Comparator<D> _comparator
protected D[][] _data
protected java.lang.Object[] _heads
organizeGroup(java.util.Comparator<D>, int)
)protected java.lang.Object[] _foots
organizeGroup(java.util.Comparator<D>, int)
)protected boolean[] _opens
public GroupsModelArray(D[] data, java.util.Comparator<D> cmpr)
data
- an array data to be grouping.cmpr
- a comparator implementation help group the data. you could implements GroupComparator
to do more grouping control.Comparator.compare(Object, Object)
or GroupComparator.compareGroup(Object, Object)
to sort the data.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.Comparator.compare(Object, Object)
to sort data in each group.public GroupsModelArray(D[] data, java.util.Comparator<D> cmpr, int col)
data
will be cloned first, so data
's content
won't be changed.data
- an array data to be grouping.cmpr
- a comparator implementation help group the data. you could implements GroupComparator
to do more grouping control.Comparator.compare(Object, Object)
or GroupComparator.compareGroup(Object, Object)
to sort the data.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.Comparator.compare(Object, Object)
to sort data in each group.col
- column index associate with cmpr.public GroupsModelArray(D[] data, java.util.Comparator<D> cmpr, int col, boolean clone)
data
- an array data to be grouping.cmpr
- a comparator implementation help group the data. you could implements GroupComparator
to do more grouping control.Comparator.compare(Object, Object)
or GroupComparator.compareGroup(Object, Object)
to sort the data.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.Comparator.compare(Object, Object)
to sort data in each group.col
- column index associate with cmpr.clone
- whether to clone data
. If not cloning,
data's content will be changed.public GroupsModelArray(java.util.List<D> data, java.util.Comparator cmpr, int col)
public GroupsModelArray(java.util.List<D> data, java.util.Comparator cmpr)
public D getChild(int groupIndex, int index)
GroupsModel
getChild
in interface GroupsModel<D,H,F>
groupIndex
- the index of the group.index
- the index of the element in the group.public int getChildCount(int groupIndex)
GroupsModel
Note: it does not include the group foot (GroupsModel.getGroupfoot(int)
).
getChildCount
in interface GroupsModel<D,H,F>
groupIndex
- the index of the group.public H getGroup(int groupIndex)
GroupsModel
getGroup
in interface GroupsModel<D,H,F>
groupIndex
- the index of the group.public int getGroupCount()
GroupsModel
getGroupCount
in interface GroupsModel<D,H,F>
public F getGroupfoot(int groupIndex)
GroupsModel
Groupfoot
and Listgroupfoot
.
Note: it is ignored if GroupsModel.hasGroupfoot(int)
returns false.
getGroupfoot
in interface GroupsModel<D,H,F>
groupIndex
- the index of the group.public boolean hasGroupfoot(int groupIndex)
GroupsModel
hasGroupfoot
in interface GroupsModel<D,H,F>
groupIndex
- the index of the group.public void sort(java.util.Comparator<D> cmpr, boolean ascending, int col)
GroupsSortableModel
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.
Notice that the comparator is capable to sort under the order specified
in the ascending parameter. In other words, you could ignore the
ascending parameter (which is used only for providing additional information)
sort
in interface GroupsSortableModel<D>
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.
Notice that it is capable to sort the data in the correct order,
you could ignore the ascending parameter.ascending
- whether to sort in the ascending order (or in
the descending order, if false). Notice that it is used only to
provide additional information. To sort the data correctly, you could
count on the cmpr parameter only.col
- the index of the columnpublic void group(java.util.Comparator<D> cmpr, boolean ascending, int col)
GroupsSortableModel
Listbox
or Grid
has the sort function.group
in interface GroupsSortableModel<D>
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 columnpublic boolean isClose(int groupIndex)
isGroupOpened(int)
public void setClose(int groupIndex, boolean close)
addOpenGroup(int)
and removeOpenGroup(int)
.public boolean addOpenGroup(int groupIndex)
GroupsModel
addOpenGroup
in interface GroupsModel<D,H,F>
groupIndex
- the index of the group.public boolean removeOpenGroup(int groupIndex)
GroupsModel
removeOpenGroup
in interface GroupsModel<D,H,F>
groupIndex
- the index of the group.public boolean isGroupOpened(int groupIndex)
GroupsModel
Group
and Listgroup
.
Default: true
isGroupOpened
in interface GroupsModel<D,H,F>
groupIndex
- the index of the group.protected void sortGroupData(H group, D[] groupdata, java.util.Comparator<D> cmpr, boolean ascending, int col)
There are three steps to re-group data:
sortDataInGroupOrder(java.util.Comparator<D>, boolean, int)
, organizeGroup(java.util.Comparator<D>, int)
and then
sortGroupData(H, D[], java.util.Comparator<D>, boolean, int)
.
It is the last step of grouping. It sorts data in the specified group.
protected void organizeGroup(java.util.Comparator<D> cmpr, int col)
There are three steps to re-group data:
sortDataInGroupOrder(java.util.Comparator<D>, boolean, int)
, organizeGroup(java.util.Comparator<D>, int)
and then
sortGroupData(H, D[], java.util.Comparator<D>, 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<D>, boolean, int)
.
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(T, T)
to sort
the data.col
- column indexprotected H createGroupHead(D[] groupdata, int index, int col)
groupdata
- data the already in a group.index
- group indexcol
- column to groupprotected F createGroupFoot(D[] groupdata, int index, int col)
groupdata
- data the already in a group.index
- group indexcol
- column to groupprotected void sortDataInGroupOrder(java.util.Comparator<D> cmpr, boolean ascending, int colIndex)
There are three steps to re-group data:
sortDataInGroupOrder(java.util.Comparator<D>, boolean, int)
, organizeGroup(java.util.Comparator<D>, int)
and then
sortGroupData(H, D[], java.util.Comparator<D>, boolean, int)
.
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(T, T)
to sort
the data.protected boolean createGroupOpen(D[] groupdata, int index, int col)
groupdata
- data the already in a group.index
- group indexcol
- column to grouppublic java.lang.Object willClone(Component comp)
willClone
in interface ComponentCloneListener
comp
- the cloned component (not the original one)public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2005-2021 Potix Corporation. All Rights Reserved.