Search in sources :

Example 1 with AggregateConfigLabelAccumulator

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

the class TickUpdateCommandHandlerTest method registerCellStyleAccumulators.

private void registerCellStyleAccumulators(DataLayer bodyDataLayer) {
    AggregateConfigLabelAccumulator aggregrateConfigLabelAccumulator = new AggregateConfigLabelAccumulator();
    this.columnLabelAccumulator = new ColumnOverrideLabelAccumulator(new DataLayerFixture());
    aggregrateConfigLabelAccumulator.add(this.columnLabelAccumulator, new AlternatingRowConfigLabelAccumulator());
    bodyDataLayer.setConfigLabelAccumulator(aggregrateConfigLabelAccumulator);
}
Also used : DataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) AggregateConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator) AlternatingRowConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.grid.cell.AlternatingRowConfigLabelAccumulator)

Example 2 with AggregateConfigLabelAccumulator

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

the class _423_ThemeStylingExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new GridLayout());
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("firstName", "Firstname");
    propertyToLabelMap.put("lastName", "Lastname");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("married", "Married");
    propertyToLabelMap.put("birthday", "Birthday");
    // build the body layer stack
    // Usually you would create a new layer stack by extending
    // AbstractIndexLayerTransform and setting the ViewportLayer
    // as underlying layer. But in this case using the ViewportLayer
    // directly as body layer is also working.
    final ListDataProvider<Person> bodyDataProvider = new DefaultBodyDataProvider<>(PersonService.getPersons(10), propertyNames);
    final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    HoverLayer bodyHoverLayer = new HoverLayer(bodyDataLayer);
    SelectionLayer selectionLayer = new SelectionLayer(bodyHoverLayer);
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    // add labels to provider conditional styling
    AggregateConfigLabelAccumulator labelAccumulator = new AggregateConfigLabelAccumulator();
    labelAccumulator.add(new ColumnLabelAccumulator());
    labelAccumulator.add(new IConfigLabelAccumulator() {

        @Override
        public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
            Person p = bodyDataProvider.getRowObject(rowPosition);
            if (p != null) {
                configLabels.addLabel(p.getGender().equals(Gender.FEMALE) ? FEMALE_LABEL : MALE_LABEL);
            }
        }
    });
    bodyDataLayer.setConfigLabelAccumulator(labelAccumulator);
    // build the column header layer
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    final DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
    HoverLayer columnHoverLayer = new HoverLayer(columnHeaderDataLayer, false);
    final ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHoverLayer, viewportLayer, selectionLayer, false);
    // add ColumnHeaderHoverLayerConfiguration to ensure that hover styling
    // and resizing is working together
    columnHeaderLayer.addConfiguration(new ColumnHeaderHoverLayerConfiguration(columnHoverLayer));
    // build the row header layer
    IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
    DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
    HoverLayer rowHoverLayer = new HoverLayer(rowHeaderDataLayer, false);
    RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(rowHoverLayer, viewportLayer, selectionLayer, false);
    // add RowHeaderHoverLayerConfiguration to ensure that hover styling and
    // resizing is working together
    rowHeaderLayer.addConfiguration(new RowHeaderHoverLayerConfiguration(rowHoverLayer));
    // build the corner layer
    IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
    DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
    final CornerLayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnHeaderLayer);
    // build the grid layer
    final GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
    final NatTable natTable = new NatTable(container, gridLayer);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
    // adding a full border
    natTable.addOverlayPainter(new NatTableBorderOverlayPainter(natTable.getConfigRegistry()));
    Composite buttonPanel = new Composite(container, SWT.NONE);
    buttonPanel.setLayout(new GridLayout(3, true));
    GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);
    final ThemeConfiguration defaultTheme = new DefaultNatTableThemeConfiguration();
    final ThemeConfiguration modernTheme = new ModernNatTableThemeConfiguration();
    final ThemeConfiguration darkTheme = new DarkNatTableThemeConfiguration();
    final ThemeConfiguration conditionalDefaultTheme = new DefaultNatTableThemeConfiguration();
    conditionalDefaultTheme.addThemeExtension(new ConditionalStylingThemeExtension());
    final ThemeConfiguration conditionalModernTheme = new ModernNatTableThemeConfiguration();
    conditionalModernTheme.addThemeExtension(new ConditionalStylingThemeExtension());
    final ThemeConfiguration conditionalDarkTheme = new DarkNatTableThemeConfiguration();
    conditionalDarkTheme.addThemeExtension(new ConditionalStylingThemeExtension());
    final ThemeConfiguration hoverTheme = new HoverThemeConfiguration();
    final ThemeConfiguration fontTheme = new FontStylingThemeConfiguration();
    Button defaultThemeButton = new Button(buttonPanel, SWT.PUSH);
    defaultThemeButton.setText("NatTable Default Theme");
    defaultThemeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            natTable.setTheme(defaultTheme);
            // reset to default state
            cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
        }
    });
    Button modernThemeButton = new Button(buttonPanel, SWT.PUSH);
    modernThemeButton.setText("NatTable Modern Theme");
    modernThemeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            natTable.setTheme(modernTheme);
            // reset to default state
            cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
        }
    });
    Button darkThemeButton = new Button(buttonPanel, SWT.PUSH);
    darkThemeButton.setText("NatTable Dark Theme");
    darkThemeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            natTable.setTheme(darkTheme);
            // reset to default state
            cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
        }
    });
    Button conditionalThemeButton = new Button(buttonPanel, SWT.PUSH);
    conditionalThemeButton.setText("Conditional Default Theme");
    conditionalThemeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            natTable.setTheme(conditionalDefaultTheme);
            // reset to default state
            cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
        }
    });
    Button conditionalModernThemeButton = new Button(buttonPanel, SWT.PUSH);
    conditionalModernThemeButton.setText("Conditional Modern Theme");
    conditionalModernThemeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            natTable.setTheme(conditionalModernTheme);
            // reset to default state
            cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
        }
    });
    Button conditionalDarkThemeButton = new Button(buttonPanel, SWT.PUSH);
    conditionalDarkThemeButton.setText("Conditional Dark Theme");
    conditionalDarkThemeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            natTable.setTheme(conditionalDarkTheme);
            // reset to default state
            cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
        }
    });
    Button hoverThemeButton = new Button(buttonPanel, SWT.PUSH);
    hoverThemeButton.setText("Hover Theme");
    hoverThemeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            natTable.setTheme(hoverTheme);
            // reset to default state
            cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
        }
    });
    Button fontThemeButton = new Button(buttonPanel, SWT.PUSH);
    fontThemeButton.setText("Increased Font Theme");
    fontThemeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            natTable.setTheme(fontTheme);
            // we are simply increasing the default width and height in this
            // example we could also register TextPainters that calculate
            // their height by content but they are not able to shrink again
            columnHeaderDataLayer.setDefaultRowHeight(30);
            columnHeaderDataLayer.setDefaultColumnWidth(130);
            bodyDataLayer.setDefaultRowHeight(30);
            bodyDataLayer.setDefaultColumnWidth(130);
        }
    });
    return container;
}
Also used : LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) ColumnHeaderHoverLayerConfiguration(org.eclipse.nebula.widgets.nattable.hover.config.ColumnHeaderHoverLayerConfiguration) HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) IConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) HoverLayer(org.eclipse.nebula.widgets.nattable.hover.HoverLayer) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) DefaultBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultBodyDataProvider) AggregateConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator) DarkNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.DarkNatTableThemeConfiguration) GridLayout(org.eclipse.swt.layout.GridLayout) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) NatTableBorderOverlayPainter(org.eclipse.nebula.widgets.nattable.painter.NatTableBorderOverlayPainter) ModernNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration) DefaultNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.DefaultNatTableThemeConfiguration) ModernNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration) ThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.ThemeConfiguration) DarkNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.DarkNatTableThemeConfiguration) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) DefaultNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.DefaultNatTableThemeConfiguration) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) RowHeaderHoverLayerConfiguration(org.eclipse.nebula.widgets.nattable.hover.config.RowHeaderHoverLayerConfiguration) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person)

Example 3 with AggregateConfigLabelAccumulator

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

the class _000_Styled_grid method setup.

private NatTable setup(Composite parent) {
    DummyGridLayerStack gridLayer = new DummyGridLayerStack();
    final NatTable natTable = new NatTable(parent, gridLayer, false);
    DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    // Add an AggregateConfigLabelAccumulator - we can add other
    // accumulators to this as required
    AggregateConfigLabelAccumulator aggregrateConfigLabelAccumulator = new AggregateConfigLabelAccumulator();
    bodyDataLayer.setConfigLabelAccumulator(aggregrateConfigLabelAccumulator);
    ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
    ColumnOverrideLabelAccumulator bodyLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
    aggregrateConfigLabelAccumulator.add(columnLabelAccumulator);
    aggregrateConfigLabelAccumulator.add(bodyLabelAccumulator);
    // Add a label for the highlighted column
    // We will add a style for this label to the config registry in a bit
    bodyLabelAccumulator.registerColumnOverrides(2, BODY_LABEL_1);
    columnLabelAccumulator.registerColumnOverrides(2, COLUMN_LABEL_1);
    // Register a command handler for the StyleEditorDialog
    DisplayColumnStyleEditorCommandHandler styleChooserCommandHandler = new DisplayColumnStyleEditorCommandHandler(gridLayer.getBodyLayer().getSelectionLayer(), columnLabelAccumulator, natTable.getConfigRegistry());
    DefaultBodyLayerStack bodyLayer = gridLayer.getBodyLayer();
    bodyLayer.registerCommandHandler(styleChooserCommandHandler);
    // Register the style editor as persistable
    // This will persist the style applied to the columns when
    // NatTable#saveState is invoked
    bodyLayer.registerPersistable(styleChooserCommandHandler);
    bodyLayer.registerPersistable(columnLabelAccumulator);
    return natTable;
}
Also used : DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DummyGridLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) DisplayColumnStyleEditorCommandHandler(org.eclipse.nebula.widgets.nattable.style.editor.command.DisplayColumnStyleEditorCommandHandler) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack) AggregateConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator)

Example 4 with AggregateConfigLabelAccumulator

use of org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator 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)

Example 5 with AggregateConfigLabelAccumulator

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

the class BodyLayerStack method setupAggregateLabelAccumulator.

private void setupAggregateLabelAccumulator() {
    aggregateLabelAccumulator = new AggregateConfigLabelAccumulator();
    getDataLayer().setConfigLabelAccumulator(aggregateLabelAccumulator);
}
Also used : AggregateConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator)

Aggregations

AggregateConfigLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator)10 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)4 ColumnLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator)4 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)3 ColumnOverrideLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator)3 IConfigLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator)3 HashMap (java.util.HashMap)2 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)2 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)2 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)2 DefaultEditBindings (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings)2 DefaultEditConfiguration (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration)2 AlternatingRowConfigLabelAccumulator (org.eclipse.nebula.widgets.nattable.grid.cell.AlternatingRowConfigLabelAccumulator)2 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)2 LabelStack (org.eclipse.nebula.widgets.nattable.layer.LabelStack)2 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 PostConstruct (javax.annotation.PostConstruct)1 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)1 AbstractUiBindingConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration)1