Package org.zkoss.zul

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

    • Field Detail

      • _nativedata

        protected D[] _nativedata
        member field to store native (original) array data
      • _comparator

        protected java.util.Comparator<D> _comparator
        member field to store Comparator for initial grouping.
      • _data

        protected D[][] _data
        member field to store group 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

      • GroupsModelArray

        public GroupsModelArray​(D[] data,
                                java.util.Comparator<D> cmpr,
                                int col)
        Constructor with an array of data. It is the same as GroupsModelArray(data, cmpr, col, true), i.e., data will be cloned first, so data's content won't be changed.
        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.
      • GroupsModelArray

        public GroupsModelArray​(D[] data,
                                java.util.Comparator<D> cmpr,
                                int col,
                                boolean clone)
        Constructor with an array of data.
        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.
        clone - whether to clone data. If not cloning, data's content will be changed.
        Since:
        5.0.6
    • 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 H 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<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.
      • sort

        public void sort​(java.util.Comparator<D> cmpr,
                         boolean ascending,
                         int col)
        Description copied from interface: GroupsSortableModel
        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. 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)

        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.
        col - the index of the column
      • group

        public void group​(java.util.Comparator<D> cmpr,
                          boolean ascending,
                          int col)
        Description copied from interface: GroupsSortableModel
        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 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)
        col - the index of the column
      • 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.
      • 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.
      • createGroupHead

        protected H createGroupHead​(D[] 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 F createGroupFoot​(D[] 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
      • createGroupOpen

        protected boolean createGroupOpen​(D[] groupdata,
                                          int index,
                                          int col)
        create group open status, default implementation return true, which means open the group. you can override this method to return your group open status.
        Parameters:
        groupdata - data the already in a group.
        index - group index
        col - column to group
        Since:
        6.0.0
      • 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
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • 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>