Class GroupModel

  • All Implemented Interfaces:
    IPersistable

    public class GroupModel
    extends Object
    implements IPersistable
    Model implementation to track groups of columns/rows.
    Since:
    1.6
    • Constructor Detail

      • GroupModel

        public GroupModel()
    • Method Detail

      • saveState

        public void saveState​(String prefix,
                              Properties properties)
        Description copied from interface: IPersistable
        Saves the state to the given Properties using the specified prefix. Note: The prefix must be prepended to the property key to support multiple states within one Properties instance.
        Specified by:
        saveState in interface IPersistable
        Parameters:
        prefix - The prefix to use for the state keys. Is also used as the state configuration name.
        properties - The Properties instance to save the state to.
      • loadState

        public void loadState​(String prefix,
                              Properties properties)
        Description copied from interface: IPersistable
        Restore the state out of the given Properties identified by the specified prefix. Note: The prefix must be prepended to the property key to support multiple states within one Properties instance.
        Specified by:
        loadState in interface IPersistable
        Parameters:
        prefix - The prefix to use for the state keys. Is also used as the state configuration name.
        properties - The Properties instance to load the state from.
      • addPositionsToGroup

        public void addPositionsToGroup​(GroupModel.Group group,
                                        int... positions)
        Adds the given positions to the given group.
        Parameters:
        group - The GroupModel.Group to which the positions should be added.
        positions - The positions to add.
      • removePositionsFromGroup

        public void removePositionsFromGroup​(GroupModel.Group group,
                                             int... positions)
        Removes the given positions from the given group.

        Note:
        A removal will only happen for positions at the beginning or the end of a group. Removing a position in the middle will cause removal of positions at the end of the group to avoid splitting a group.

        Note:
        A removal does only work for visible positions. That means removing something from a collapsed group does not work.

        Parameters:
        group - The GroupModel.Group from which the positions should be removed.
        positions - The positions to remove.
      • removePositionsFromGroup

        public Collection<GroupModel.Group> removePositionsFromGroup​(int... positions)
        Removes the given positions from corresponding groups. Searches the groups by position and removes the position in case the group is not unbreakable.

        Note:
        A removal will only happen for positions at the beginning or the end of a group. Removing a position in the middle will cause removal of positions at the end of the group to avoid splitting a group.

        Note:
        A removal does only work for visible positions. That means removing something from a collapsed group does not work.

        Parameters:
        positions - The positions to remove.
        Returns:
        The collection of GroupModel.Groups that have been modified.
      • addStaticIndexesToGroup

        public void addStaticIndexesToGroup​(String groupName,
                                            int... indexes)
        This method will add static indexes to the given group.

        Static indexes remain visible when a group is collapsed.

        Parameters:
        groupName - The name of the group on which the static indexes should be inserted.
        indexes - The static indexes to add.
      • addStaticIndexesToGroup

        public void addStaticIndexesToGroup​(int position,
                                            int... indexes)
        This method will add static indexes to the given group.

        Static indexes remain visible when a group is collapsed.

        Parameters:
        position - The position of a group on which the static indexes should be inserted.
        indexes - The static indexes to add.
      • addStaticIndexesToGroup

        public void addStaticIndexesToGroup​(GroupModel.Group group,
                                            int... indexes)
        This method will add static indexes to the given group.

        Static indexes remain visible when a group is collapsed.

        Parameters:
        group - The group on which the static indexes should be inserted.
        indexes - The static indexes to add.
      • getGroupByName

        public GroupModel.Group getGroupByName​(String groupName)
        Parameters:
        groupName - The name of the requested group.
        Returns:
        The group with the given group name or null if there is no group with such a name.
      • getGroupByPosition

        public GroupModel.Group getGroupByPosition​(int position)
        Checks if the given position is part of a group and returns the group if the position is part of it.
        Parameters:
        position - The position to check.
        Returns:
        The Group to which the given position belongs to or null if the position is not part of a group.
      • getGroupByStaticIndex

        public GroupModel.Group getGroupByStaticIndex​(int staticIndex)
        Checks if there is a group that has the given index as static index.

        Note: This method iterates over all groups and checks if the static index collection contains the given index. Could have a bad performance in case of huge groups.

        Parameters:
        staticIndex - The index to check.
        Returns:
        The Group in which the given index is configured as static index or null if the index is not a static index in any group.
      • findGroupByMemberIndex

        public GroupModel.Group findGroupByMemberIndex​(int memberIndex)
        Searches for a group that has a given member index.

        Note: This method iterates over all groups and checks if the member collection contains the given index. Could have a bad performance in case of huge groups.

        Parameters:
        memberIndex - The index to check.
        Returns:
        The Group that contains the given index or null if the index is not a member in any group.
      • isPartOfAGroup

        public boolean isPartOfAGroup​(int position)
        Check if the given position is part of a group in this GroupModel.
        Parameters:
        position - The position to check.
        Returns:
        true if the position is part of a group, false if not.
      • addGroup

        public void addGroup​(String groupName,
                             int startIndex,
                             int span)
        Creates and adds a group.
        Parameters:
        groupName - The name of the group. Typically used as value in the cell.
        startIndex - The index of the first item in the group.
        span - The configured number of items that belong to this group.
      • addGroup

        public void addGroup​(GroupModel.Group group)
        Adds the given group.
        Parameters:
        group - The group to add.
      • removeGroup

        public GroupModel.Group removeGroup​(String groupName)
        Removes the group identified by the given name.
        Parameters:
        groupName - The name of the group to remove.
        Returns:
        The group that was removed from the model.
      • removeGroup

        public GroupModel.Group removeGroup​(int position)
        Removes the group identified by the given position.
        Parameters:
        position - The group that contains the given position.
        Returns:
        The group that was removed from the model.
      • removeGroup

        public void removeGroup​(GroupModel.Group group)
        Removes the given group.
        Parameters:
        group - The group to remove.
      • clear

        public void clear()
        Removes all groups from this GroupModel.
      • isEmpty

        public boolean isEmpty()
        Returns:
        true if no group is configured in this GroupModel.
      • isStatic

        public boolean isStatic​(int position)
        Checks if the given position is configured to be static in one of the groups.
        Parameters:
        position - The position to check.
        Returns:
        true if the given position is configured to be static in a group.
      • isPartOfACollapseableGroup

        public boolean isPartOfACollapseableGroup​(int position)
        Check if the specified position belongs to a GroupModel.Group and if this GroupModel.Group is collabseable.
        Parameters:
        position - The position used to retrieve the corresponding group.
        Returns:
        true if the specified position belongs to a GroupModel.Group and this GroupModel.Group is collabseable, false if not.
      • setGroupCollapseable

        public void setGroupCollapseable​(String groupName,
                                         boolean collabseable)
        Set the GroupModel.Group with the given group name to be collapseable or not.
        Parameters:
        groupName - The name of the group that should be modified.
        collabseable - true to set the group collapseable, false to set it not to be collapseable.
      • setGroupCollapseable

        public void setGroupCollapseable​(int position,
                                         boolean collabseable)
        Set the GroupModel.Group to which the specified position belongs to, to be collapseable or not.
        Parameters:
        position - The position used to retrieve the corresponding group.
        collabseable - true to set the group collapseable, false to set it not to be collapseable.
      • isPartOfAnUnbreakableGroup

        public boolean isPartOfAnUnbreakableGroup​(int position)
        Check if the specified position belongs to a GroupModel.Group and if this GroupModel.Group is unbreakable.
        Parameters:
        position - The position used to retrieve the corresponding group.
        Returns:
        true if the specified position belongs to a GroupModel.Group and this GroupModel.Group is unbreakable, false if not.
      • setGroupUnbreakable

        public void setGroupUnbreakable​(String groupName,
                                        boolean unbreakable)
        Set the group with the given name to unbreakable/breakable.
        Parameters:
        groupName - The name of the group that should be modified.
        unbreakable - true to set the group unbreakable, false to remove the unbreakable state.
      • setGroupUnbreakable

        public void setGroupUnbreakable​(int position,
                                        boolean unbreakable)
        Set the GroupModel.Group to which the position belongs to unbreakable/breakable.
        Parameters:
        position - The position used to retrieve the corresponding group.
        unbreakable - true to set the group unbreakable, false to remove the unbreakable state.
      • isDefaultCollapseable

        public boolean isDefaultCollapseable()
        Returns:
        The default value for the collapseable flag of newly created GroupModel.Group objects.
      • setDefaultCollapseable

        public void setDefaultCollapseable​(boolean defaultCollapseable)
        Sets the default value for the collapseable flag when creating GroupModel.Group objects.
        Parameters:
        defaultCollapseable - the default value for GroupModel.Group.collapseable that should be set on creating GroupModel.Group.
      • isDefaultUnbreakable

        public boolean isDefaultUnbreakable()
        Returns:
        The default value for the unbreakable flag of newly created GroupModel.Group objects.
      • setDefaultUnbreakable

        public void setDefaultUnbreakable​(boolean defaultUnbreakable)
        Sets the default value for the unbreakable flag when creating GroupModel.Group objects.
        Parameters:
        defaultUnbreakable - the default value for GroupModel.Group.unbreakable that should be set on creating GroupModel.Group.