Class HierarchicalTreeLayer

    • Field Detail

      • LEVEL_HEADER_CELL

        public static final String LEVEL_HEADER_CELL
        Label that gets applied to cells in the level header columns.
        See Also:
        Constant Field Values
      • COLLAPSED_CHILD

        public static final String COLLAPSED_CHILD
        Label that gets applied to child cells of a collapsed parent object.
        See Also:
        Constant Field Values
      • NO_OBJECT_IN_LEVEL

        public static final String NO_OBJECT_IN_LEVEL
        Label that gets applied to child level cells if the row object does not contain an object for that level.
        See Also:
        Constant Field Values
    • Constructor Detail

      • HierarchicalTreeLayer

        public HierarchicalTreeLayer​(IUniqueIndexLayer underlyingLayer,
                                     List<HierarchicalWrapper> underlyingList,
                                     String[] propertyNames)
        Parameters:
        underlyingLayer - The underlying layer this layer is stacked on.
        underlyingList - The collection with the HierarchicalWrapper objects that is shown in the table. Needed to perform expand/collapse actions.
        propertyNames - The property names to access the object properties of the wrapped objects inside the HierarchicalWrapper. Needed to determine the levels.
      • HierarchicalTreeLayer

        public HierarchicalTreeLayer​(IUniqueIndexLayer underlyingLayer,
                                     List<HierarchicalWrapper> underlyingList,
                                     String[] propertyNames,
                                     boolean useDefaultConfiguration)
        Parameters:
        underlyingLayer - The underlying layer this layer is stacked on.
        underlyingList - The collection with the HierarchicalWrapper objects that is shown in the table. Needed to perform expand/collapse actions.
        propertyNames - The property names to access the object properties of the wrapped objects inside the HierarchicalWrapper. Needed to determine the levels.
        useDefaultConfiguration - true if the DefaultHierarchicalTreeLayerConfiguration should be added, false if not.
      • HierarchicalTreeLayer

        public HierarchicalTreeLayer​(IUniqueIndexLayer underlyingLayer,
                                     List<HierarchicalWrapper> underlyingList,
                                     String[] propertyNames,
                                     SelectionLayer selectionLayer)
        Parameters:
        underlyingLayer - The underlying layer this layer is stacked on.
        underlyingList - The collection with the HierarchicalWrapper objects that is shown in the table. Needed to perform expand/collapse actions.
        propertyNames - The property names to access the object properties of the wrapped objects inside the HierarchicalWrapper. Needed to determine the levels.
        selectionLayer - The SelectionLayer needed to calculate selections for the level header column. Can be null which leads to not showing selections in the level header.
      • HierarchicalTreeLayer

        public HierarchicalTreeLayer​(IUniqueIndexLayer underlyingLayer,
                                     List<HierarchicalWrapper> underlyingList,
                                     String[] propertyNames,
                                     SelectionLayer selectionLayer,
                                     boolean useDefaultConfiguration)
        Parameters:
        underlyingLayer - The underlying layer this layer is stacked on.
        underlyingList - The collection with the HierarchicalWrapper objects that is shown in the table. Needed to perform expand/collapse actions.
        propertyNames - The property names to access the object properties of the wrapped objects inside the HierarchicalWrapper. Needed to determine the levels.
        selectionLayer - The SelectionLayer needed to calculate selections for the level header column. Can be null which leads to not showing selections in the level header.
        useDefaultConfiguration - true if the DefaultHierarchicalTreeLayerConfiguration should be added, false if not.
    • Method Detail

      • doCommand

        public boolean doCommand​(ILayerCommand command)
        Description copied from interface: ILayer
        Opportunity to respond to a command as it flows down the stack. If the layer is not interested in the command it should allow the command to keep traveling down the stack.

        Note: Before the layer can process a command it must convert the command to its local coordinates using ILayerCommand.convertToTargetLayer(ILayer)

        Specified by:
        doCommand in interface ILayer
        Overrides:
        doCommand in class AbstractLayerTransform
        Parameters:
        command - The command to execute.
        Returns:
        true if the command has been handled and was therefore consumed, false otherwise.
      • handleLayerEvent

        public void handleLayerEvent​(ILayerEvent event)
        Description copied from class: AbstractLayer
        Handle layer event notification. Convert it to your context and propagate UP. If you override this method you MUST NOT FORGET to raise the event up the layer stack by calling super.fireLayerEvent(event) - unless you plan to eat the event yourself.
        Specified by:
        handleLayerEvent in interface ILayerListener
        Overrides:
        handleLayerEvent in class AbstractRowHideShowLayer
        Parameters:
        event - the event
      • getConfigLabelsByPosition

        public LabelStack getConfigLabelsByPosition​(int columnPosition,
                                                    int rowPosition)
        Description copied from interface: ILayer
        Returns the config labels for the cell at the given coordinates. Needed to retrieve the corresponding configurations out of the IConfigRegistry.
        Specified by:
        getConfigLabelsByPosition in interface ILayer
        Overrides:
        getConfigLabelsByPosition in class AbstractLayerTransform
        Parameters:
        columnPosition - The column position of the cell.
        rowPosition - The row position of the cell.
        Returns:
        The LabelStack with the config labels for the cell at the given coordinates.
      • getCellByPosition

        public ILayerCell getCellByPosition​(int columnPosition,
                                            int rowPosition)
        Description copied from interface: ILayer
        Returns the cell for the given coordinates on this layer.
        Specified by:
        getCellByPosition in interface ILayer
        Overrides:
        getCellByPosition in class AbstractRowHideShowLayer
        Parameters:
        columnPosition - The column position of the requested cell.
        rowPosition - The row position of the requested cell.
        Returns:
        The ILayerCell for the given coordinates in this layer or null if the coordinates are invalid on this layer.
      • getDataValueByPosition

        public Object getDataValueByPosition​(int columnPosition,
                                             int rowPosition)
        Description copied from interface: ILayer
        Returns the data value for the cell at the given coordinates.
        Specified by:
        getDataValueByPosition in interface ILayer
        Overrides:
        getDataValueByPosition in class AbstractLayerTransform
        Parameters:
        columnPosition - The column position of the cell.
        rowPosition - The row position of the cell.
        Returns:
        The data value for the cell at the given coordinates.
      • isRowPositionInLevelSelected

        protected boolean isRowPositionInLevelSelected​(int levelHeaderColumnPosition,
                                                       int rowPosition)
        Test if a cell in the given row and a column belonging to the level of the given level header position is selected.
        Parameters:
        levelHeaderColumnPosition - The column position of the level header column.
        rowPosition - The row position.
        Returns:
        true if a cell in the given row is selected in the level of the level header position, false if not.
      • getNumberOfColumnsToSelect

        protected int getNumberOfColumnsToSelect​(int levelHeaderPosition)
        Calculates the number of header columns to the right of a given level header column position.
        Parameters:
        levelHeaderPosition - The column position of a level header column.
        Returns:
        The number of columns to select when a level header column is selected.
      • isTreeColumn

        protected boolean isTreeColumn​(int columnPosition)
        Test if the column at the given position is a tree column.
        Parameters:
        columnPosition - The column position to check.
        Returns:
        true if the given position is a tree column, false if it is a content column.
      • isLevelHeaderColumn

        public boolean isLevelHeaderColumn​(int columnPosition)
        Test if the column at the given position is a level header column.
        Parameters:
        columnPosition - The column position to check.
        Returns:
        true if the given position is a level header column, false if it is a content column.
      • hasLevelObject

        protected boolean hasLevelObject​(int columnPosition,
                                         int rowPosition)
        Test if the cell at the given coordinates belongs to a cell with an object for the corresponding level or not.
        Parameters:
        columnPosition - The column position to check.
        rowPosition - The row position to check.
        Returns:
        true if there is a level object for the corresponding level, false if there is no level object.
      • getLevelByColumnIndex

        public int getLevelByColumnIndex​(int columnIndex)
        Returns the level to which a given column index belongs to.
        Parameters:
        columnIndex - The column index for which the level is requested.
        Returns:
        The level to which the given column index belongs to or -1 if the columnIndex is invalid.
      • getColumnIndexesForLevel

        public List<Integer> getColumnIndexesForLevel​(int level)
        Returns all column indexes for a given level.
        Parameters:
        level - The level for which the column indexes are requested.
        Returns:
        The column indexes of the columns that belong to the given level.
      • getLevelIndexMapping

        public Map<Integer,​List<Integer>> getLevelIndexMapping()
        Returns:
        Mapping of the level to the list of the columns belonging to the level.
      • isRowIndexHidden

        public boolean isRowIndexHidden​(int rowIndex)
        Description copied from class: AbstractRowHideShowLayer
        Will check if the row at the specified index is hidden or not. Checks this layer and also the sublayers for the visibility.
        Specified by:
        isRowIndexHidden in class AbstractRowHideShowLayer
        Parameters:
        rowIndex - The row index of the row whose visibility state should be checked.
        Returns:
        true if the row at the specified index is hidden, false if it is visible.
      • getHiddenRowIndexes

        public Collection<Integer> getHiddenRowIndexes()
        Description copied from class: AbstractRowHideShowLayer
        Will collect and return all indexes of the rows that are hidden in this layer.

        Note: It is not intended that it also collects the row indexes of underlying layers. This would cause issues on calculating positions, as every layer is responsible for those calculations itself.

        Since 2.0 it is recommended to use AbstractRowHideShowLayer.getHiddenRowIndexesArray() to avoid unnecessary autoboxing operations.

        Specified by:
        getHiddenRowIndexes in class AbstractRowHideShowLayer
        Returns:
        Collection of all row indexes that are hidden in this layer.
      • getHiddenRowIndexesArray

        public int[] getHiddenRowIndexesArray()
        Description copied from class: AbstractRowHideShowLayer
        Will collect and return all indexes of the rows that are hidden in this layer.

        Note: It is not intended that it also collects the row indexes of underlying layers. This would cause issues on calculating positions, as every layer is responsible for those calculations itself.

        Specified by:
        getHiddenRowIndexesArray in class AbstractRowHideShowLayer
        Returns:
        All row indexes that are hidden in this layer.
      • expandOrCollapse

        public void expandOrCollapse​(int columnIndex,
                                     int rowIndex)
        Expands or collapses the node at the given index coordinates according to its current state.
        Parameters:
        columnIndex - The column index of the node to handle.
        rowIndex - The row index of the node to handle.
      • expandOrCollapse

        public void expandOrCollapse​(int columnIndex,
                                     int rowIndex,
                                     int toLevel)
        Expands or collapses the node at the given index coordinates according to its current state. Expands to the given level, e.g. if toLevel 0 is given, only the first level of a row is expanded, given toLevel is 1 and a node in the first level should be expanded, that node will be expanded as well as all collapsed nodes in the second level for this object.
        Parameters:
        columnIndex - The column index of the node to handle.
        rowIndex - The row index of the node to handle.
        toLevel - 0 based hierarchy level to expand to. Will be ignored on collapse or if value is -1.

        Note: This is the level to expand to, not the number of levels to expand from the expanded level.

      • collapseAll

        public void collapseAll()
        Collapses all tree nodes.
      • expandAll

        public void expandAll()
        Expands all tree nodes.
      • expandAllToLevel

        public void expandAllToLevel​(int toLevel)
        Expands all tree nodes starting from the first level to the specified level.
        Parameters:
        toLevel - 0 based hierarchy level to expand to. A negative value will be defaulted to 0 to at least expand the first level.
      • getChildIndexes

        protected int[] getChildIndexes​(int columnIndex,
                                        int rowIndex)
        Calculates the child row indexes for the node at the given coordinates.
        Parameters:
        columnIndex - The column index of the node whose children are requested.
        rowIndex - The row index of the node whose children are requested.
        Returns:
        The row indexes for the children of the node at the given coordinates.
        Since:
        2.0
      • findTopRowIndex

        public int findTopRowIndex​(int columnIndex,
                                   HierarchicalWrapper rowObject)
        Find the top row index for the given row object and the given column index. Used to determine the row index of the top row so the node coordinates can be correctly calculated.
        Parameters:
        columnIndex - The column index to determine the level for the necessary level object checks.
        rowObject - The row object that builds a node.
        Returns:
        The row index of the top most row of a spanned cell that determines a node.
      • isCollapsed

        public boolean isCollapsed​(int columnPosition,
                                   int rowPosition)
        Returns whether the cell at the given position is a collapsed node.
        Parameters:
        columnPosition - The column position of the cell to check.
        rowPosition - The row position of the cell to check.
        Returns:
        true if the cell at the given coordinates is a collapsed node, false if not.
      • isUseTreeColumnIndex

        public boolean isUseTreeColumnIndex()
        Returns:
        true if the column index is used to determine the tree column, false if the column position is used. Default is false.
      • setUseTreeColumnIndex

        public void setUseTreeColumnIndex​(boolean useTreeColumnIndex)
        Configure whether (column index == 0) or (column position == 0) should be performed to identify the tree column.
        Parameters:
        useTreeColumnIndex - true if the column index should be used to determine the tree column, false if the column position should be used.
      • isShowTreeLevelHeader

        public boolean isShowTreeLevelHeader()
        Returns:
        true if the tree level header is shown, false if not.
      • setShowTreeLevelHeader

        public void setShowTreeLevelHeader​(boolean show)
        Configure whether the tree level header should be shown or not.
        Parameters:
        show - true if the tree level header should be shown, false if not.
      • setHandleNoObjectsInLevel

        public void setHandleNoObjectsInLevel​(boolean handleNoObjectsInLevel)
        Configure whether getConfigLabelsByPosition(int, int) should add the NO_OBJECT_IN_LEVEL label to the LabelStack. Enabling this configuration allows a different configuration for child cells of row objects that have no object for a child level, e.g. making those cells not editable and different styles like no content painter or different background.

        Note: To identify level cells without a level object a deep inspection needs to be performed, which might cause a negative effect on the rendering performance. The handling is enabled by default, but if the underlying data model does not support empty level objects or the table configuration supports editing of such cells by automatically adding level objects on edit, it is recommended to disable this feature.

        Parameters:
        handleNoObjectsInLevel - true if getConfigLabelsByPosition(int, int) should add the NO_OBJECT_IN_LEVEL label to the LabelStack, false if that processing should not be performed.
      • isRetainRemovedRowObjectNodes

        public boolean isRetainRemovedRowObjectNodes()
        Returns:
        true if collapsed nodes are retained even if the corresponding row object is removed from the underlying list. false if the collapsed nodes are removed if the referenced row object is not contained anymore. Default is true.
      • setRetainRemovedRowObjectNodes

        public void setRetainRemovedRowObjectNodes​(boolean retainRemovedRowObjectNodes)
        Configure whether collapsed nodes should be retained in the collapsedNodes even if the row object is not contained in the underlying list anymore. This can for example happen when using a FilterList, as filtering will remove the row objects from that list. Without using a FilterList or supporting deleting rows, it is suggested to set this flag to false to avoid memory leaks on deleting an object.
        Parameters:
        retainRemovedRowObjectNodes - true to keep collapse nodes even if the corresponding row object is removed from the underlying list. false if the collapsed nodes should not contain references to removed row objects. Default is true.
      • cleanupRetainedCollapsedNodes

        public void cleanupRetainedCollapsedNodes()
        If retainRemovedRowObjectNodes is set to true, the collapsedNodes could contain references to row objects that were deleted meanwhile. To deal with this and avoid memory leaks, this method can be called to remove any collapsed node that has a reference to a non existing row object.
      • cleanupRetainedCollapsedNodes

        public void cleanupRetainedCollapsedNodes​(HierarchicalWrapper rowObject)
        If retainRemovedRowObjectNodes is set to true, the collapsedNodes could contain references to row objects that were deleted meanwhile. To deal with this and avoid memory leaks, this method can be called to remove a collapsed node that references the given row object which for example is removed from the underlying collection.
        Parameters:
        rowObject - The row object that was removed from the underlying list, to be able to cleanup a collapsed node reference.
      • isExpandOnSearch

        public boolean isExpandOnSearch()
        Returns:
        true if collapsed nodes are expanded if they contain rows that are found on search. false if only the found row is made visible by still keeping the nodes collapsed. Default is true.
      • setExpandOnSearch

        public void setExpandOnSearch​(boolean expandOnSearch)
        Configure whether collapsed nodes should be expanded if they contain rows that are found on search or only the found row should be made visible by still keeping the nodes collapsed.
        Parameters:
        expandOnSearch - true if collapsed nodes should be expanded if they contain rows that are found on search. false if only the found row should be made visible by still keeping the nodes collapsed.
      • isSelectSubLevels

        public boolean isSelectSubLevels()
        Return whether columns in sub levels should be selected when selecting a level header cell or if only the cells in the same level should be selected. Default is false.
        Returns:
        true if columns in sub levels are selected when selecting a level header cell, false if only the cells in the same level are selected.
      • setSelectSubLevels

        public void setSelectSubLevels​(boolean selectSubLevels)
        Configure whether columns in sub levels should be selected when selecting a level header cell or if only the cells in the same level should be selected. Default is false.
        Parameters:
        selectSubLevels - true if columns in sub levels should be selected when selecting a level header cell, false if only the cells in the same level should be selected.
      • getColumnIndexByPosition

        public int getColumnIndexByPosition​(int columnPosition)
        Description copied from interface: ILayer
        Gets the underlying non-transformed column index for the given column position on this layer.
        Specified by:
        getColumnIndexByPosition in interface ILayer
        Overrides:
        getColumnIndexByPosition in class AbstractLayerTransform
        Parameters:
        columnPosition - The column position relative to this layer.
        Returns:
        An underlying non-transformed column index, or -1 if the given column position does not exist within this coordinate system.
      • localToUnderlyingColumnPosition

        public int localToUnderlyingColumnPosition​(int localColumnPosition)
        Description copied from interface: ILayer
        Convert a column position to the coordinates of the underlying layer. This is possible since each layer is aware of its underlying layer.
        Specified by:
        localToUnderlyingColumnPosition in interface ILayer
        Overrides:
        localToUnderlyingColumnPosition in class AbstractLayerTransform
        Parameters:
        localColumnPosition - column position in local (the layer's own) coordinates
        Returns:
        column position in the underlying layer's coordinates
      • underlyingToLocalColumnPosition

        public int underlyingToLocalColumnPosition​(ILayer sourceUnderlyingLayer,
                                                   int underlyingColumnPosition)
        Description copied from interface: ILayer
        Transforms the column position relative to the given underlying layer to this layer coordinates.
        Specified by:
        underlyingToLocalColumnPosition in interface ILayer
        Overrides:
        underlyingToLocalColumnPosition in class AbstractLayerTransform
        Parameters:
        sourceUnderlyingLayer - The underlying layer to which the given column position matches.
        underlyingColumnPosition - The column position in the given underlying layer that should be converted to a local column position.
        Returns:
        The given column position transformed to be local to this layer.
      • underlyingToLocalColumnPositions

        public Collection<Range> underlyingToLocalColumnPositions​(ILayer sourceUnderlyingLayer,
                                                                  Collection<Range> underlyingColumnPositionRanges)
        Description copied from interface: ILayer
        Transforms the column position ranges relative to the given underlying layer to this layer coordinates.
        Specified by:
        underlyingToLocalColumnPositions in interface ILayer
        Overrides:
        underlyingToLocalColumnPositions in class AbstractLayerTransform
        Parameters:
        sourceUnderlyingLayer - The underlying layer to which the given column positions match.
        underlyingColumnPositionRanges - The column position ranges relative to the given underlying layer that should be converted to local column positions.
        Returns:
        The given column position ranges transformed to this layer.
      • isValidTargetColumnPosition

        public boolean isValidTargetColumnPosition​(int fromColumnPosition,
                                                   int toColumnPosition)
        Checks if the column at the given from position can be reordered to the given to position. Mainly performs a check if the column at the given from position is a level header (which can not be reordered) or if the reordering would mean to move a column into a different level, which is also forbidden.
        Parameters:
        fromColumnPosition - The position of the column to reorder.
        toColumnPosition - The position to move the column to.
        Returns:
        true if reordering would be valid, false in case the column at the from position is a level header column or the move would be a level change.
      • getLevelHeaderWidth

        public int getLevelHeaderWidth()
        Returns:
        The column width of the level header columns in pixel.
      • setLevelHeaderWidth

        public void setLevelHeaderWidth​(int width)
        Set the column width for the level header columns.
        Parameters:
        width - The column width in pixels that should be used for the level header columns.
      • getScaledLevelHeaderWidth

        protected int getScaledLevelHeaderWidth()
        Returns:
        The level header width in DPI.
      • getWidth

        public int getWidth()
        Description copied from interface: ILayer
        Returns the total width in pixels of this layer.
        Specified by:
        getWidth in interface ILayer
        Overrides:
        getWidth in class AbstractLayerTransform
        Returns:
        The total width in pixels of this layer.
      • getColumnWidthByPosition

        public int getColumnWidthByPosition​(int columnPosition)
        Description copied from interface: ILayer
        Returns the width in pixels of the given column. The width of invisible and non-existing columns is 0.
        Specified by:
        getColumnWidthByPosition in interface ILayer
        Overrides:
        getColumnWidthByPosition in class AbstractLayerTransform
        Parameters:
        columnPosition - The column position in this layer.
        Returns:
        The width of the column.
      • getStartXOfColumnPosition

        public int getStartXOfColumnPosition​(int columnPosition)
        Description copied from interface: ILayer
        Returns the x offset in pixels of the given column.
        Specified by:
        getStartXOfColumnPosition in interface ILayer
        Overrides:
        getStartXOfColumnPosition in class AbstractLayerTransform
        Parameters:
        columnPosition - The column position in this layer.
        Returns:
        The x offset of the column, or -1.
      • getColumnPositionByX

        public int getColumnPositionByX​(int x)
        Description copied from interface: ILayer
        Returns the column position that contains the given x coordinate.
        Specified by:
        getColumnPositionByX in interface ILayer
        Overrides:
        getColumnPositionByX in class AbstractLayerTransform
        Parameters:
        x - A horizontal pixel location relative to the pixel boundary of this layer.
        Returns:
        A column position relative to the associated coordinate system, or -1 if there is no column that contains x.