Search in sources :

Example 31 with LabelStack

use of org.eclipse.nebula.widgets.nattable.layer.LabelStack in project nebula.widgets.nattable by eclipse.

the class _001_Custom_styling_of_specific_cells method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    List<SimplePerson> myList = new ArrayList<>();
    for (int i = 1; i <= 100; i++) {
        myList.add(new SimplePerson(i, "Joe" + i, new Date()));
    }
    String[] propertyNames = { "id", "name", "birthDate" };
    IColumnPropertyAccessor<SimplePerson> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    ListDataProvider<SimplePerson> listDataProvider = new ListDataProvider<>(myList, columnPropertyAccessor);
    DefaultGridLayer gridLayer = new DefaultGridLayer(listDataProvider, new DummyColumnHeaderDataProvider(listDataProvider));
    final DefaultBodyLayerStack bodyLayer = gridLayer.getBodyLayer();
    // Custom label "FOO" for cell at column, row index (1, 5)
    IConfigLabelAccumulator cellLabelAccumulator = new IConfigLabelAccumulator() {

        @Override
        public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
            int columnIndex = bodyLayer.getColumnIndexByPosition(columnPosition);
            int rowIndex = bodyLayer.getRowIndexByPosition(rowPosition);
            if (columnIndex == 1 && rowIndex == 5) {
                configLabels.addLabel(FOO_LABEL);
            }
            if (columnIndex == 1 && rowIndex == 10) {
                configLabels.addLabel(BAR_LABEL);
            }
            // add labels for surrounding borders
            if (rowIndex == 13) {
                configLabels.addLabel(CustomLineBorderDecorator.TOP_LINE_BORDER_LABEL);
                configLabels.addLabel(CustomLineBorderDecorator.BOTTOM_LINE_BORDER_LABEL);
                if (columnIndex == 0) {
                    configLabels.addLabel(CustomLineBorderDecorator.LEFT_LINE_BORDER_LABEL);
                }
                if (columnIndex == 2) {
                    configLabels.addLabel(CustomLineBorderDecorator.RIGHT_LINE_BORDER_LABEL);
                }
            }
        }
    };
    bodyLayer.setConfigLabelAccumulator(cellLabelAccumulator);
    NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {

        {
            // override the LineBorderDecorator here to show how to paint
            // borders on single sides of a cell
            this.cellPainter = new CustomLineBorderDecorator(new TextPainter());
            // set a border style
            this.borderStyle = new BorderStyle(2, GUIHelper.COLOR_BLUE, LineStyleEnum.DASHDOT);
        }
    });
    // Custom style for label "FOO"
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            Style cellStyle = new Style();
            cellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.COLOR_GREEN);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, FOO_LABEL);
            cellStyle = new Style();
            cellStyle.setAttributeValue(CellStyleAttributes.TEXT_DECORATION, TextDecorationEnum.UNDERLINE_STRIKETHROUGH);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, BAR_LABEL);
        }
    });
    natTable.configure();
    return natTable;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) ArrayList(java.util.ArrayList) IConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) Style(org.eclipse.nebula.widgets.nattable.style.Style) BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) Date(java.util.Date) DummyColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) CustomLineBorderDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CustomLineBorderDecorator) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack) SimplePerson(org.eclipse.nebula.widgets.nattable.dataset.person.SimplePerson)

Example 32 with LabelStack

use of org.eclipse.nebula.widgets.nattable.layer.LabelStack 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 33 with LabelStack

use of org.eclipse.nebula.widgets.nattable.layer.LabelStack in project nebula.widgets.nattable by eclipse.

the class GroupByDataLayerTest method testOneLevelGroupSortSummary.

@Test
public void testOneLevelGroupSortSummary() {
    addSortingCapability();
    addSummaryConfiguration();
    // increase the money amount for all flanders to show that the sort
    // order is related to the summary value and not the groupBy value
    double value = 600.0d;
    for (int i = 10; i < this.sortedList.size(); i++) {
        if ((i - 10) % 2 == 0) {
            value -= 100.0d;
        }
        this.sortedList.get(i).setMoney(value);
    }
    // groupBy lastname
    this.groupByModel.addGroupByColumnIndex(1);
    // 18 data rows + 2 GroupBy rows
    assertEquals(20, this.dataLayer.getRowCount());
    Object o = this.dataLayer.getTreeList().get(0);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Flanders", ((GroupByObject) o).getValue());
    LabelStack labelStack = this.dataLayer.getConfigLabelsByPosition(2, 0);
    assertEquals(2800.0d, this.dataLayer.getDataValueByPosition(2, 0, labelStack, false));
    o = this.dataLayer.getTreeList().get(1);
    assertTrue("Object is not a Person", o instanceof Person);
    assertEquals("Ned", ((Person) o).getFirstName());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, 1);
    assertEquals(500.0d, this.dataLayer.getDataValueByPosition(2, 1, labelStack, false));
    o = this.dataLayer.getTreeList().get(9);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Simpson", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, 9);
    assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, 9, labelStack, false));
    // sort ascending by money
    this.sortModel.sort(2, SortDirectionEnum.ASC, false);
    o = this.dataLayer.getTreeList().get(0);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Simpson", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, 0);
    assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, 0, labelStack, false));
    o = this.dataLayer.getTreeList().get(11);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Flanders", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, 11);
    assertEquals(2800.0d, this.dataLayer.getDataValueByPosition(2, 11, labelStack, false));
    o = this.dataLayer.getTreeList().get(12);
    assertTrue("Object is not a Person", o instanceof Person);
    assertEquals("Todd", ((Person) o).getFirstName());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, 1);
    assertEquals(100.0d, this.dataLayer.getDataValueByPosition(2, 1, labelStack, false));
    // sort descending by money
    this.sortModel.sort(2, SortDirectionEnum.DESC, false);
    o = this.dataLayer.getTreeList().get(0);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Flanders", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, 0);
    assertEquals(2800.0d, this.dataLayer.getDataValueByPosition(2, 0, labelStack, false));
    o = this.dataLayer.getTreeList().get(9);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Simpson", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, 9);
    assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, 9, labelStack, false));
    o = this.dataLayer.getTreeList().get(1);
    assertTrue("Object is not a Person", o instanceof Person);
    assertEquals("Ned", ((Person) o).getFirstName());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, 1);
    assertEquals(500.0d, this.dataLayer.getDataValueByPosition(2, 1, labelStack, false));
}
Also used : LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) GroupByObject(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject) GroupByObject(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) Test(org.junit.Test)

Example 34 with LabelStack

use of org.eclipse.nebula.widgets.nattable.layer.LabelStack in project nebula.widgets.nattable by eclipse.

the class GroupByDataLayerTest method testConfigLabelsWithoutGrouping.

@Test
public void testConfigLabelsWithoutGrouping() {
    // there should be never a groupBy label or groupBySummary label
    for (int row = 0; row < this.dataLayer.getRowCount(); row++) {
        for (int column = 0; column < this.dataLayer.getColumnCount(); column++) {
            LabelStack stack = this.dataLayer.getConfigLabelsByPosition(column, row);
            assertTrue("column label not found", stack.hasLabel(ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + column));
            assertFalse("groupBy object label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_OBJECT));
            assertFalse("groupBy column label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + column));
            assertFalse("groupBy summary label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_SUMMARY));
            assertFalse("groupBy summary column label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_SUMMARY_COLUMN_PREFIX + column));
        }
    }
}
Also used : LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) Test(org.junit.Test)

Example 35 with LabelStack

use of org.eclipse.nebula.widgets.nattable.layer.LabelStack in project nebula.widgets.nattable by eclipse.

the class GroupByDataLayerTest method addConditionalStyling.

void addConditionalStyling() {
    IConfigLabelAccumulator conditional = new IConfigLabelAccumulator() {

        @Override
        public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
            if (columnPosition == 2 && configLabels.hasLabel(GroupByDataLayer.GROUP_BY_OBJECT)) {
                Double value = (Double) GroupByDataLayerTest.this.dataLayer.getDataValueByPosition(columnPosition, rowPosition, configLabels, false);
                if (value > 800d) {
                    configLabels.addLabelOnTop(MY_LABEL);
                }
            }
        }
    };
    AggregateConfigLabelAccumulator aggregate = new AggregateConfigLabelAccumulator();
    aggregate.add(new ColumnLabelAccumulator());
    aggregate.add(conditional);
    this.dataLayer.setConfigLabelAccumulator(aggregate);
}
Also used : LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) IConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) AggregateConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator)

Aggregations

LabelStack (org.eclipse.nebula.widgets.nattable.layer.LabelStack)80 Test (org.junit.Test)30 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)14 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)13 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)11 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)10 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)10 HashMap (java.util.HashMap)9 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)9 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)9 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)9 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 GridLayout (org.eclipse.swt.layout.GridLayout)9 Composite (org.eclipse.swt.widgets.Composite)9 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)8 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)8 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)8 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)8 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)8