Class HierarchicalWrapperComparator
- java.lang.Object
-
- org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapperComparator
-
- All Implemented Interfaces:
Comparator<HierarchicalWrapper>
public class HierarchicalWrapperComparator extends Object implements Comparator<HierarchicalWrapper>
Comparator
for collections ofHierarchicalWrapper
. Ensures that the objects are ordered in a way that the expected tree structure is kept. Additionally provides a way to sort by column if anISortModel
is set, by still keeping the tree structure. That means in deeper levels of the tree, only the sub nodes are sorted, not the tree itself is changed.- Since:
- 1.6
-
-
Constructor Summary
Constructors Constructor Description HierarchicalWrapperComparator(IColumnAccessor<HierarchicalWrapper> columnAccessor, Map<Integer,List<Integer>> levelIndexMapping)
Creates a newHierarchicalWrapperComparator
without anISortModel
.HierarchicalWrapperComparator(IColumnAccessor<HierarchicalWrapper> columnAccessor, Map<Integer,List<Integer>> levelIndexMapping, ISortModel sortModel)
Creates a newHierarchicalWrapperComparator
with anISortModel
to support dynamic configurable column based sorting.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(HierarchicalWrapper o1, HierarchicalWrapper o2)
protected int
compareColumn(HierarchicalWrapper o1, HierarchicalWrapper o2, int columnIndex, boolean useDefault)
Compares twoHierarchicalWrapper
objects based on the information in the given column.protected int
compareLevel(HierarchicalWrapper o1, HierarchicalWrapper o2, int level)
Compares twoHierarchicalWrapper
objects based on the information in the given level.protected Comparator
getComparator(int columnIndex, boolean useDefault)
Returns theComparator
that should be used to compare the values in a column for the given column index.ISortModel
getSortModel()
void
setSortModel(ISortModel sortModel)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
-
-
-
Constructor Detail
-
HierarchicalWrapperComparator
public HierarchicalWrapperComparator(IColumnAccessor<HierarchicalWrapper> columnAccessor, Map<Integer,List<Integer>> levelIndexMapping)
Creates a newHierarchicalWrapperComparator
without anISortModel
. Without anISortModel
theDefaultComparator
is used for comparison of column values to keep the tree structure. The sort order can not be influenced via column sorting, until aISortModel
is set viasetSortModel(ISortModel)
.- Parameters:
columnAccessor
- TheIColumnAccessor
needed to access the column values of theHierarchicalWrapper
row objects.levelIndexMapping
- The mapping of tree level to column indexes needed for level based sorting.
-
HierarchicalWrapperComparator
public HierarchicalWrapperComparator(IColumnAccessor<HierarchicalWrapper> columnAccessor, Map<Integer,List<Integer>> levelIndexMapping, ISortModel sortModel)
Creates a newHierarchicalWrapperComparator
with anISortModel
to support dynamic configurable column based sorting.- Parameters:
columnAccessor
- TheIColumnAccessor
needed to access the column values of theHierarchicalWrapper
row objects.levelIndexMapping
- The mapping of tree level to column indexes needed for level based sorting.sortModel
- TheISortModel
that provides access to configured column comparators and supports dynamic sorting per column.
-
-
Method Detail
-
compare
public int compare(HierarchicalWrapper o1, HierarchicalWrapper o2)
- Specified by:
compare
in interfaceComparator<HierarchicalWrapper>
-
compareLevel
protected int compareLevel(HierarchicalWrapper o1, HierarchicalWrapper o2, int level)
Compares twoHierarchicalWrapper
objects based on the information in the given level.- Parameters:
o1
- The firstHierarchicalWrapper
object to be compared.o2
- The secondHierarchicalWrapper
object to be compared.level
- The level that should be compared.- Returns:
- a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
-
compareColumn
protected int compareColumn(HierarchicalWrapper o1, HierarchicalWrapper o2, int columnIndex, boolean useDefault)
Compares twoHierarchicalWrapper
objects based on the information in the given column.- Parameters:
o1
- The firstHierarchicalWrapper
object to be compared.o2
- The secondHierarchicalWrapper
object to be compared.columnIndex
-useDefault
- flag to configure whether theDefaultComparator
should be used in case no dedicated comparator is configured. Should be set totrue
in case the comparator for a column is requested that is needed to ensure the tree structure.- Returns:
- a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
-
getComparator
protected Comparator getComparator(int columnIndex, boolean useDefault)
Returns theComparator
that should be used to compare the values in a column for the given column index.- Parameters:
columnIndex
- The column index of the column for which theComparator
is requested.useDefault
- flag to configure whether theDefaultComparator
should be used in case no dedicated comparator is configured. Should be set totrue
in case the comparator for a column is requested that is needed to ensure the tree structure.- Returns:
- The
Comparator
that should be used to compare the values for elements in the given column. Returns theDefaultComparator
in case there is noISortModel
configured, noComparator
is found for the given column or a NullComparator is configured for the given column.
-
getSortModel
public ISortModel getSortModel()
- Returns:
- The
ISortModel
that is set in thisHierarchicalWrapperComparator
to support dynamic column based sorting in combination with tree sorting.
-
setSortModel
public void setSortModel(ISortModel sortModel)
- Parameters:
sortModel
- TheISortModel
that should be used by thisHierarchicalWrapperComparator
to support dynamic column based sorting in combination with tree sorting.
-
-