Search in sources :

Example 1 with HierarchicalWrapper

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

the class _6044_HierarchicalTreeLayerGridExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("manufacturer", "Manufacturer");
    propertyToLabelMap.put("model", "Model");
    propertyToLabelMap.put("motors.identifier", "Identifier");
    propertyToLabelMap.put("motors.capacity", "Capacity");
    propertyToLabelMap.put("motors.capacityUnit", "Capacity Unit");
    propertyToLabelMap.put("motors.maximumSpeed", "Maximum Speed");
    propertyToLabelMap.put("motors.feedbacks.creationTime", "Creation Time");
    propertyToLabelMap.put("motors.feedbacks.classification", "Classification");
    propertyToLabelMap.put("motors.feedbacks.comment", "Comment");
    ConfigRegistry configRegistry = new ConfigRegistry();
    BodyLayerStack bodyLayerStack = new BodyLayerStack(CarService.getInput(), CarService.PROPERTY_NAMES);
    // create the column header layer stack
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(CarService.PROPERTY_NAMES, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
    // add the SortHeaderLayer to the column header layer stack
    final SortHeaderLayer<HierarchicalWrapper> sortHeaderLayer = new SortHeaderLayer<>(columnHeaderLayer, new HierarchicalWrapperSortModel(bodyLayerStack.getSortedList(), bodyLayerStack.getColumnPropertyAccessor(), bodyLayerStack.getTreeLayer().getLevelIndexMapping(), columnHeaderDataLayer, configRegistry), false);
    // create the row header layer stack
    IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyLayerStack.getBodyDataProvider());
    ILayer rowHeaderLayer = new RowHeaderLayer(new DataLayer(rowHeaderDataProvider, 40, 20), bodyLayerStack, bodyLayerStack.getSelectionLayer());
    // create the corner layer stack
    ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)), rowHeaderLayer, sortHeaderLayer);
    // create the grid layer composed with the prior created layer stacks
    GridLayer gridLayer = new GridLayer(bodyLayerStack, sortHeaderLayer, rowHeaderLayer, cornerLayer);
    NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.setConfigRegistry(configRegistry);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {

        {
            this.vAlign = VerticalAlignmentEnum.TOP;
            this.hAlign = HorizontalAlignmentEnum.LEFT;
            this.cellPainter = new PaddingDecorator(new TextPainter(), 2);
        }
    });
    // adds the key bindings that allows pressing space bar to
    // expand/collapse tree nodes
    natTable.addConfiguration(new TreeLayerExpandCollapseKeyBindings(bodyLayerStack.getTreeLayer(), bodyLayerStack.getSelectionLayer()));
    // add sorting configuration
    natTable.addConfiguration(new SingleClickSortConfiguration());
    natTable.configure();
    return natTable;
}
Also used : HierarchicalWrapper(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper) HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) TreeLayerExpandCollapseKeyBindings(org.eclipse.nebula.widgets.nattable.tree.config.TreeLayerExpandCollapseKeyBindings) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) SortHeaderLayer(org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer) PaddingDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) HierarchicalWrapperSortModel(org.eclipse.nebula.widgets.nattable.extension.glazedlists.hierarchical.HierarchicalWrapperSortModel) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) SingleClickSortConfiguration(org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)

Example 2 with HierarchicalWrapper

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

the class _6045_HierarchicalTreeLayerExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new GridLayout());
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("manufacturer", "Manufacturer");
    propertyToLabelMap.put("model", "Model");
    propertyToLabelMap.put("motors.identifier", "Identifier");
    propertyToLabelMap.put("motors.capacity", "Capacity");
    propertyToLabelMap.put("motors.capacityUnit", "Capacity Unit");
    propertyToLabelMap.put("motors.maximumSpeed", "Maximum Speed");
    propertyToLabelMap.put("motors.feedbacks.creationTime", "Creation Time");
    propertyToLabelMap.put("motors.feedbacks.classification", "Classification");
    propertyToLabelMap.put("motors.feedbacks.comment", "Comment");
    ConfigRegistry configRegistry = new ConfigRegistry();
    BodyLayerStack bodyLayerStack = new BodyLayerStack(CarService.getInput(), CarService.PROPERTY_NAMES);
    // create the column header layer stack
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(CarService.PROPERTY_NAMES, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
    // add the SortHeaderLayer to the column header layer stack
    final SortHeaderLayer<HierarchicalWrapper> sortHeaderLayer = new SortHeaderLayer<>(columnHeaderLayer, new HierarchicalWrapperSortModel(bodyLayerStack.getSortedList(), bodyLayerStack.getColumnPropertyAccessor(), bodyLayerStack.getTreeLayer().getLevelIndexMapping(), columnHeaderDataLayer, configRegistry), false);
    // add the filter row functionality
    final FilterRowHeaderComposite<HierarchicalWrapper> filterRowHeaderLayer = new FilterRowHeaderComposite<>(new DefaultGlazedListsFilterStrategy<>(bodyLayerStack.getFilterList(), bodyLayerStack.getColumnPropertyAccessor(), configRegistry), sortHeaderLayer, columnHeaderDataLayer.getDataProvider(), configRegistry);
    filterRowHeaderLayer.addConfigLabelAccumulatorForRegion(GridRegion.FILTER_ROW, new IConfigLabelAccumulator() {

        @Override
        public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
            int columnIndex = filterRowHeaderLayer.getColumnIndexByPosition(columnPosition);
            // header column
            if (columnIndex < 0) {
                configLabels.addLabelOnTop(HierarchicalTreeLayer.LEVEL_HEADER_CELL);
            }
        }
    });
    // create the composite layer composed with the prior created layer
    // stacks
    CompositeLayer compositeLayer = new CompositeLayer(1, 2);
    compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, filterRowHeaderLayer, 0, 0);
    compositeLayer.setChildLayer(GridRegion.BODY, bodyLayerStack, 0, 1);
    compositeLayer.addConfiguration(new DefaultGridLayerConfiguration(compositeLayer) {

        @Override
        protected void addAlternateRowColoringConfig(CompositeLayer gridLayer) {
        // do nothing to avoid the default grid alternate row coloring
        // needed because the alternate row coloring in the hierarchical
        // tree
        // is based on the spanned cells and not per individual row
        // position
        }
    });
    NatTable natTable = new NatTable(container, compositeLayer, false);
    natTable.setConfigRegistry(configRegistry);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {

        {
            this.vAlign = VerticalAlignmentEnum.TOP;
            this.hAlign = HorizontalAlignmentEnum.LEFT;
            this.cellPainter = new PaddingDecorator(new TextPainter(), 2);
        }
    });
    // add editing configuration
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            // make identifier editable
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, EditableRule.ALWAYS_EDITABLE, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 2);
            // make capacity unit editable
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, EditableRule.ALWAYS_EDITABLE, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new ComboBoxCellEditor("KW", "PS"), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new PaddingDecorator(new ComboBoxPainter(), 2), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
            // make comment editable
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, EditableRule.ALWAYS_EDITABLE, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 8);
        }
    });
    // adds the key bindings that allows pressing space bar to
    // expand/collapse tree nodes
    natTable.addConfiguration(new TreeLayerExpandCollapseKeyBindings(bodyLayerStack.getTreeLayer(), bodyLayerStack.getSelectionLayer()));
    // add sorting configuration
    natTable.addConfiguration(new SingleClickSortConfiguration());
    // add some additional filter configuration
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            Style style = new Style();
            style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.getColor(173, 216, 230));
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, GridRegion.FILTER_ROW);
        }
    });
    natTable.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
    Composite buttonPanel = new Composite(container, SWT.NONE);
    buttonPanel.setLayout(new RowLayout());
    GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);
    Button collapseAllButton = new Button(buttonPanel, SWT.PUSH);
    collapseAllButton.setText("Collapse All");
    collapseAllButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            natTable.doCommand(new TreeCollapseAllCommand());
        }
    });
    Button expandAllButton = new Button(buttonPanel, SWT.PUSH);
    expandAllButton.setText("Expand All");
    expandAllButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            natTable.doCommand(new TreeExpandAllCommand());
        }
    });
    Button expandAllFirstLevelButton = new Button(buttonPanel, SWT.PUSH);
    expandAllFirstLevelButton.setText("Expand All First Level");
    expandAllFirstLevelButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            natTable.doCommand(new TreeExpandToLevelCommand(0));
        }
    });
    Button toggleExpandButton = new Button(buttonPanel, SWT.PUSH);
    toggleExpandButton.setText("Enable Advanced Expand");
    toggleExpandButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            _6045_HierarchicalTreeLayerExample.this.advancedExpandEnabled = !_6045_HierarchicalTreeLayerExample.this.advancedExpandEnabled;
            if (_6045_HierarchicalTreeLayerExample.this.advancedExpandEnabled) {
                toggleExpandButton.setText("Disable Advanced Expand");
                // configure advanced action
                natTable.getUiBindingRegistry().registerFirstSingleClickBinding(_6045_HierarchicalTreeLayerExample.this.treeImagePainterMouseEventMatcher, _6045_HierarchicalTreeLayerExample.this.advancedTreeExpandCollapseAction);
            } else {
                toggleExpandButton.setText("Enable Advanced Expand");
                // configure simple action
                natTable.getUiBindingRegistry().registerFirstSingleClickBinding(_6045_HierarchicalTreeLayerExample.this.treeImagePainterMouseEventMatcher, _6045_HierarchicalTreeLayerExample.this.simpleTreeExpandCollapseAction);
            }
        }
    });
    Button multiReorderButton = new Button(buttonPanel, SWT.PUSH);
    multiReorderButton.setText("Reorder Second Level");
    multiReorderButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            List<Integer> fromColumnPositions = Arrays.asList(4, 5);
            natTable.doCommand(new MultiColumnReorderCommand(natTable, fromColumnPositions, 8));
        }
    });
    Button deleteButton = new Button(buttonPanel, SWT.PUSH);
    deleteButton.setText("Delete Row 4");
    deleteButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // remove the element
            HierarchicalWrapper rowObject = bodyLayerStack.getFilterList().remove(3);
            // fire the event to refresh
            bodyLayerStack.getBodyDataLayer().fireLayerEvent(new RowDeleteEvent(bodyLayerStack.getBodyDataLayer(), 3));
            bodyLayerStack.getTreeLayer().cleanupRetainedCollapsedNodes(rowObject);
        }
    });
    return container;
}
Also used : HierarchicalWrapper(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper) LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) IConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) GridLayout(org.eclipse.swt.layout.GridLayout) SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) TreeCollapseAllCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeCollapseAllCommand) TreeExpandToLevelCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandToLevelCommand) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) TreeLayerExpandCollapseKeyBindings(org.eclipse.nebula.widgets.nattable.tree.config.TreeLayerExpandCollapseKeyBindings) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Style(org.eclipse.nebula.widgets.nattable.style.Style) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) SortedList(ca.odell.glazedlists.SortedList) TransformedList(ca.odell.glazedlists.TransformedList) List(java.util.List) EventList(ca.odell.glazedlists.EventList) FilterList(ca.odell.glazedlists.FilterList) FilterRowHeaderComposite(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowHeaderComposite) Composite(org.eclipse.swt.widgets.Composite) FilterRowHeaderComposite(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowHeaderComposite) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ComboBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ComboBoxPainter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SortHeaderLayer(org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer) PaddingDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator) ComboBoxCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) HierarchicalWrapperSortModel(org.eclipse.nebula.widgets.nattable.extension.glazedlists.hierarchical.HierarchicalWrapperSortModel) TreeExpandAllCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandAllCommand) SingleClickSortConfiguration(org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) DefaultGridLayerConfiguration(org.eclipse.nebula.widgets.nattable.grid.layer.config.DefaultGridLayerConfiguration)

Example 3 with HierarchicalWrapper

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

the class HierarchicalTreeLayerGlazedListsTest method shouldFindIndex.

@Test
public void shouldFindIndex() {
    HierarchicalWrapper wrapper = this.sortedList.get(0);
    assertEquals(0, this.sortedList.indexOf(wrapper));
}
Also used : HierarchicalWrapper(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper) Test(org.junit.Test)

Example 4 with HierarchicalWrapper

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

the class HierarchicalTreeLayerGlazedListsTest method shouldCleanupRetainedCollapsedStates.

@Test
public void shouldCleanupRetainedCollapsedStates() throws InterruptedException, ExecutionException, TimeoutException {
    // collapse first level of first item
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 0));
    assertEquals(7, this.treeLayer.getRowCount());
    assertEquals(1, this.treeLayer.getCollapsedNodes().size());
    HierarchicalTreeNode node = this.treeLayer.getCollapsedNodes().iterator().next();
    assertEquals(0, node.rowIndex);
    assertEquals(0, node.columnIndex);
    assertNotNull(node.rowObject);
    assertEquals(4, this.treeLayer.getHiddenRowIndexes().size());
    assertEquals("McLaren", this.treeLayer.getDataValueByPosition(1, 1));
    // filter out BMW which is the first row that is collapsed
    this.filterList.setMatcher(new Matcher<HierarchicalWrapper>() {

        @Override
        public boolean matches(HierarchicalWrapper item) {
            return !((Car) item.getObject(0)).getManufacturer().equals("BMW");
        }
    });
    // refresh the layers to ensure the state is current
    // sometimes in the tests list change events where missing
    this.treeLayer.doCommand(new StructuralRefreshCommand());
    assertEquals(6, this.treeLayer.getRowCount());
    assertEquals(1, this.treeLayer.getCollapsedNodes().size());
    node = this.treeLayer.getCollapsedNodes().iterator().next();
    // row index -1 as we retain but the object is not available anymore
    assertEquals(-1, node.rowIndex);
    assertEquals(0, node.columnIndex);
    assertNotNull(node.rowObject);
    // nothing hidden as it is filtered
    assertEquals(0, this.treeLayer.getHiddenRowIndexes().size());
    assertEquals("McLaren", this.treeLayer.getDataValueByPosition(1, 0));
    // cleanup retained
    this.treeLayer.cleanupRetainedCollapsedNodes();
    assertEquals(6, this.treeLayer.getRowCount());
    // nothing collapsed anymore as collapsed node was removed/filtered
    assertEquals(0, this.treeLayer.getCollapsedNodes().size());
    assertEquals(0, this.treeLayer.getHiddenRowIndexes().size());
    assertEquals("McLaren", this.treeLayer.getDataValueByPosition(1, 0));
    this.filterList.setMatcher(null);
    // refresh the layers to ensure the state is current
    // sometimes in the tests list change events where missing
    this.treeLayer.doCommand(new StructuralRefreshCommand());
    // no restore of collapsed nodes
    assertEquals(11, this.treeLayer.getRowCount());
    assertEquals(0, this.treeLayer.getCollapsedNodes().size());
    assertEquals(0, this.treeLayer.getHiddenRowIndexes().size());
    assertEquals("BMW", this.treeLayer.getDataValueByPosition(1, 1));
}
Also used : StructuralRefreshCommand(org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand) HierarchicalWrapper(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper) HierarchicalTreeNode(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode) TreeExpandCollapseCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand) Test(org.junit.Test)

Example 5 with HierarchicalWrapper

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

the class HierarchicalTreeLayerGlazedListsTest method shouldRetainCollapsedStateOnDescSorting.

@Test
public void shouldRetainCollapsedStateOnDescSorting() throws InterruptedException, ExecutionException, TimeoutException {
    HierarchicalWrapper rowObject = this.sortedList.get(0);
    // collapse first level of first item
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 0));
    assertEquals(7, this.treeLayer.getRowCount());
    assertEquals(1, this.treeLayer.getCollapsedNodes().size());
    HierarchicalTreeNode node = this.treeLayer.getCollapsedNodes().iterator().next();
    assertEquals(0, node.rowIndex);
    assertEquals(0, node.columnIndex);
    assertNotNull(node.rowObject);
    assertEquals(4, this.treeLayer.getHiddenRowIndexes().size());
    // sort column index 2 DESC
    HierarchicalWrapperSortModel sortModel = new HierarchicalWrapperSortModel(this.sortedList, this.columnPropertyAccessor, this.treeLayer.getLevelIndexMapping(), this.columnHeaderDataLayer, this.configRegistry);
    sortModel.sort(2, SortDirectionEnum.DESC, false);
    // refresh the layers to ensure the state is current
    // sometimes in the tests list change events where missing
    this.treeLayer.doCommand(new StructuralRefreshCommand());
    int row = this.treeLayer.findTopRowIndex(0, rowObject);
    assertEquals(0, row);
    assertEquals(7, this.treeLayer.getRowCount());
    assertEquals(1, this.treeLayer.getCollapsedNodes().size());
    node = this.treeLayer.getCollapsedNodes().iterator().next();
    assertEquals(0, node.rowIndex);
    assertEquals(0, node.columnIndex);
    assertNotNull(node.rowObject);
    assertEquals(4, this.treeLayer.getHiddenRowIndexes().size());
}
Also used : StructuralRefreshCommand(org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand) HierarchicalWrapper(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper) HierarchicalTreeNode(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode) TreeExpandCollapseCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand) Test(org.junit.Test)

Aggregations

HierarchicalWrapper (org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper)8 Test (org.junit.Test)5 StructuralRefreshCommand (org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand)4 HierarchicalTreeNode (org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode)4 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)3 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)3 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)3 SpanningDataLayer (org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer)3 TreeExpandCollapseCommand (org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand)3 HashMap (java.util.HashMap)2 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)2 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)2 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)2 HierarchicalWrapperSortModel (org.eclipse.nebula.widgets.nattable.extension.glazedlists.hierarchical.HierarchicalWrapperSortModel)2 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)2 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)2 TextPainter (org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter)2 PaddingDecorator (org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator)2 SortHeaderLayer (org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer)2 SingleClickSortConfiguration (org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration)2