Package org.zkoss.zul

Class SimpleGroupsModel<D,​H,​F,​E>

    • Field Detail

      • _data

        protected java.util.List<java.util.List<D>> _data
        member field to store group data
      • _heads

        protected java.util.List<H> _heads
        member field to store group head data
      • _foots

        protected java.util.List<F> _foots
        member field to store group foot data
      • _opens

        protected boolean[] _opens
        member field to store group close status
      • _sorting

        protected java.util.Comparator<D> _sorting
        the sorting comparator
      • _sortDir

        protected boolean _sortDir
        is the sort ascending?
    • Constructor Detail

      • SimpleGroupsModel

        public SimpleGroupsModel​(D[][] 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​(D[][] data,
                                 H[] 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​(D[][] data,
                                 H[] heads,
                                 F[] 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​(D[][] data,
                                 H[] heads,
                                 F[] 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.

        Notice that, for backward compatibility, the last argument is closes.

        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 isGroupOpened(int) will return true in corresponding index(i.e. group is default to open)
      • SimpleGroupsModel

        public SimpleGroupsModel​(java.util.List<java.util.List<D>> data)
        Constructs a groups data model with a two-dimensional list 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 list. Furthermore, list.get(0) is the elements of the first group, list.get(1) is the 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 list to represent groups data.
        Since:
        6.0.1
      • SimpleGroupsModel

        public SimpleGroupsModel​(java.util.List<java.util.List<D>> data,
                                 java.util.List<H> 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 two dimensional list to represent groups data
        heads - a list to represent head data of group
        Since:
        6.0.1
      • SimpleGroupsModel

        public SimpleGroupsModel​(java.util.List<java.util.List<D>> data,
                                 java.util.List<H> heads,
                                 java.util.List<F> 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 two dimensional list to represent groups data
        heads - a list to represent head data of group
        foots - a list to represent foot data of group, if an element in this list is null, then hasGroupfoot(int) will return false in corresponding index.
        Since:
        6.0.1
      • SimpleGroupsModel

        public SimpleGroupsModel​(java.util.List<java.util.List<D>> data,
                                 java.util.List<H> heads,
                                 java.util.List<F> 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.

        Notice that, for backward compatibility, the last argument is closes.

        Parameters:
        data - a two dimensional list to represent groups data
        heads - a list to represent head data of group
        foots - a list to represent foot data of group, if an element in this list 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 isGroupOpened(int) will return true in corresponding index(i.e. group is default to open)
        Since:
        6.0.1
    • Method Detail

      • getChild

        public D 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<D,​H,​F>
        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 group foot (GroupsModel.getGroupfoot(int)).

        Specified by:
        getChildCount in interface GroupsModel<D,​H,​F>
        Parameters:
        groupIndex - the index of the group.
      • getGroup

        public java.lang.Object getGroup​(int groupIndex)
        Returns the data representing the group. It is H, if heads is specified in the constructor, or D[] if not specified.
        Specified by:
        getGroup in interface GroupsModel<D,​H,​F>
        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<D,​H,​F>
      • 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<D,​H,​F>
        Parameters:
        groupIndex - the index of the group.
      • isGroupOpened

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

        Default: true

        Specified by:
        isGroupOpened in interface GroupsModel<D,​H,​F>
        Parameters:
        groupIndex - the index of the group.
      • addOpenGroup

        public boolean addOpenGroup​(int groupIndex)
        Description copied from interface: GroupsModel
        Opens the group at the specified index.
        Specified by:
        addOpenGroup in interface GroupsModel<D,​H,​F>
        Parameters:
        groupIndex - the index of the group.
        Returns:
        if it has been added successfully; false if it was opened.
      • removeOpenGroup

        public boolean removeOpenGroup​(int groupIndex)
        Description copied from interface: GroupsModel
        Closes the group at the specified index.
        Specified by:
        removeOpenGroup in interface GroupsModel<D,​H,​F>
        Parameters:
        groupIndex - the index of the group.
        Returns:
        if it has been removed successfully; false if it was closed.
      • setOpenGroup0

        public boolean setOpenGroup0​(int groupIndex,
                                     boolean open)
      • group

        public void group​(java.util.Comparator<D> 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 GroupsSortableModel<D>
        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<D> cmpr,
                         boolean ascending,
                         int colIndex)
        Sort each data in each group by Comparator, developer could override sortGroupData(Object, List, Comparator, boolean, int) (Since 6.0.1) to customize.
        Specified by:
        sort in interface GroupsSortableModel<D>
        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. 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.
        colIndex - the index of the column
      • sortGroupData

        protected void sortGroupData​(java.lang.Object group,
                                     java.util.List<D> groupdata,
                                     java.util.Comparator<D> cmpr,
                                     boolean ascending,
                                     int colIndex)
        Sorts a group of data.

        Default: Collections.sort(groupdata, cmpr)

        Parameters:
        group - the group (the same as getGroup(int))
        groupdata - the group of data to sort
        Since:
        6.0.1
      • willClone

        public java.lang.Object willClone​(Component comp)
        Allows the model to clone
        Specified by:
        willClone in interface ComponentCloneListener
        Parameters:
        comp - the cloned component (not the original one)
        Returns:
        the object to be used in the cloned component. If this object is returned, the same object is shared by the cloned and original components. If other object is returned, it is used by the cloned component. If null is returned, it is not used by the cloned component at all.
        Since:
        6.0.0
      • getSortDirection

        public java.lang.String getSortDirection​(java.util.Comparator<D> cmpr)
        Description copied from interface: Sortable
        Returns the sort direction of this model for the given comparator. It must be one of "ascending", "descending" and "natural".

        Default: "natural".

        Specified by:
        getSortDirection in interface GroupsSortableModel<D>
        Specified by:
        getSortDirection in interface Sortable<D>