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 of HierarchicalWrapper. 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 an ISortModel
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
ConstructorsConstructorDescriptionHierarchicalWrapperComparator(IColumnAccessor<HierarchicalWrapper> columnAccessor, Map<Integer, List<Integer>> levelIndexMapping) Creates a newHierarchicalWrapperComparatorwithout anISortModel.HierarchicalWrapperComparator(IColumnAccessor<HierarchicalWrapper> columnAccessor, Map<Integer, List<Integer>> levelIndexMapping, ISortModel sortModel) Creates a newHierarchicalWrapperComparatorwith anISortModelto support dynamic configurable column based sorting. -
Method Summary
Modifier and TypeMethodDescriptionintprotected intcompareColumn(HierarchicalWrapper o1, HierarchicalWrapper o2, int columnIndex, boolean useDefault) Compares twoHierarchicalWrapperobjects based on the information in the given column.protected intcompareLevel(HierarchicalWrapper o1, HierarchicalWrapper o2, int level) Compares twoHierarchicalWrapperobjects based on the information in the given level.protected ComparatorgetComparator(int columnIndex, boolean useDefault) Returns theComparatorthat should be used to compare the values in a column for the given column index.voidsetSortModel(ISortModel sortModel) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
HierarchicalWrapperComparator
public HierarchicalWrapperComparator(IColumnAccessor<HierarchicalWrapper> columnAccessor, Map<Integer, List<Integer>> levelIndexMapping) Creates a newHierarchicalWrapperComparatorwithout anISortModel. Without anISortModeltheDefaultComparatoris used for comparison of column values to keep the tree structure. The sort order can not be influenced via column sorting, until aISortModelis set viasetSortModel(ISortModel).- Parameters:
columnAccessor- TheIColumnAccessorneeded to access the column values of theHierarchicalWrapperrow 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 newHierarchicalWrapperComparatorwith anISortModelto support dynamic configurable column based sorting.- Parameters:
columnAccessor- TheIColumnAccessorneeded to access the column values of theHierarchicalWrapperrow objects.levelIndexMapping- The mapping of tree level to column indexes needed for level based sorting.sortModel- TheISortModelthat provides access to configured column comparators and supports dynamic sorting per column.
-
-
Method Details
-
compare
- Specified by:
comparein interfaceComparator<HierarchicalWrapper>
-
compareLevel
Compares twoHierarchicalWrapperobjects based on the information in the given level.- Parameters:
o1- The firstHierarchicalWrapperobject to be compared.o2- The secondHierarchicalWrapperobject 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 twoHierarchicalWrapperobjects based on the information in the given column.- Parameters:
o1- The firstHierarchicalWrapperobject to be compared.o2- The secondHierarchicalWrapperobject to be compared.columnIndex-useDefault- flag to configure whether theDefaultComparatorshould be used in case no dedicated comparator is configured. Should be set totruein 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
Returns theComparatorthat 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 theComparatoris requested.useDefault- flag to configure whether theDefaultComparatorshould be used in case no dedicated comparator is configured. Should be set totruein case the comparator for a column is requested that is needed to ensure the tree structure.- Returns:
- The
Comparatorthat should be used to compare the values for elements in the given column. Returns theDefaultComparatorin case there is noISortModelconfigured, noComparatoris found for the given column or a NullComparator is configured for the given column.
-
getSortModel
- Returns:
- The
ISortModelthat is set in thisHierarchicalWrapperComparatorto support dynamic column based sorting in combination with tree sorting.
-
setSortModel
- Parameters:
sortModel- TheISortModelthat should be used by thisHierarchicalWrapperComparatorto support dynamic column based sorting in combination with tree sorting.
-