Search in sources :

Example 1 with HierarchicalWrapperComparator

use of org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapperComparator in project nebula.widgets.nattable by eclipse.

the class HierarchicalWrapperSortModel method sort.

@Override
public void sort(int columnIndex, SortDirectionEnum sortDirection, boolean accumulate) {
    if (columnIndex >= 0) {
        if (!accumulate) {
            clear();
        }
        switch(sortDirection) {
            case NONE:
                // remove
                this.sortingState.remove(columnIndex);
                break;
            case ASC:
            case DESC:
                this.sortingState.remove(columnIndex);
                this.sortingState.put(columnIndex, sortDirection);
                break;
            default:
                break;
        }
        // perform the sorting
        this.sortedList.getReadWriteLock().writeLock().lock();
        try {
            this.sortedList.setComparator(new HierarchicalWrapperComparator(this.columnAccessor, this.levelIndexMapping, this));
        } finally {
            this.sortedList.getReadWriteLock().writeLock().unlock();
        }
    }
}
Also used : HierarchicalWrapperComparator(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapperComparator)

Example 2 with HierarchicalWrapperComparator

use of org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapperComparator in project nebula.widgets.nattable by eclipse.

the class HierarchicalTreeLayerGlazedListsTest method setup.

@Before
public void setup() {
    // de-normalize the object graph without parent structure objects
    List<HierarchicalWrapper> data = HierarchicalHelper.deNormalize(CarService.getInput(), false, CarService.PROPERTY_NAMES_COMPACT);
    EventList<HierarchicalWrapper> eventList = GlazedLists.eventList(data);
    TransformedList<HierarchicalWrapper, HierarchicalWrapper> rowObjectsGlazedList = GlazedLists.threadSafeList(eventList);
    this.columnPropertyAccessor = new HierarchicalReflectiveColumnPropertyAccessor(CarService.PROPERTY_NAMES_COMPACT);
    this.sortedList = new SortedList<>(rowObjectsGlazedList, new HierarchicalWrapperComparator(this.columnPropertyAccessor, HierarchicalHelper.getLevelIndexMapping(CarService.PROPERTY_NAMES_COMPACT)));
    this.filterList = new FilterList<>(this.sortedList);
    this.bodyDataProvider = new ListDataProvider<>(this.filterList, this.columnPropertyAccessor);
    HierarchicalSpanningDataProvider spanningDataProvider = new HierarchicalSpanningDataProvider(this.bodyDataProvider, CarService.PROPERTY_NAMES_COMPACT);
    this.bodyDataLayer = new SpanningDataLayer(spanningDataProvider);
    // simply apply labels for every column by index
    this.bodyDataLayer.setConfigLabelAccumulator(new ColumnLabelAccumulator());
    // layer for event handling of GlazedLists and PropertyChanges
    GlazedListsEventLayer<HierarchicalWrapper> glazedListsEventLayer = new GlazedListsEventLayer<>(this.bodyDataLayer, this.filterList);
    glazedListsEventLayer.setTestMode(true);
    this.selectionLayer = new SelectionLayer(glazedListsEventLayer);
    this.treeLayer = new HierarchicalTreeLayer(this.selectionLayer, this.filterList, CarService.PROPERTY_NAMES_COMPACT);
    // create a dummy config registry
    this.configRegistry = new ConfigRegistry();
    this.configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, DefaultComparator.getInstance());
    this.columnHeaderDataLayer = new DataLayer(new DefaultColumnHeaderDataProvider(CarService.PROPERTY_NAMES_COMPACT));
}
Also used : HierarchicalWrapper(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper) SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) GlazedListsEventLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) HierarchicalWrapperComparator(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapperComparator) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) HierarchicalReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalReflectiveColumnPropertyAccessor) HierarchicalSpanningDataProvider(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalSpanningDataProvider) HierarchicalTreeLayer(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer) Before(org.junit.Before)

Aggregations

HierarchicalWrapperComparator (org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapperComparator)2 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)1 GlazedListsEventLayer (org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer)1 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)1 HierarchicalReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalReflectiveColumnPropertyAccessor)1 HierarchicalSpanningDataProvider (org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalSpanningDataProvider)1 HierarchicalTreeLayer (org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer)1 HierarchicalWrapper (org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper)1 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)1 SpanningDataLayer (org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer)1 ColumnLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator)1 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)1 Before (org.junit.Before)1