Search in sources :

Example 86 with DefaultNatTableStyleConfiguration

use of org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration in project nebula.widgets.nattable by eclipse.

the class TableEditConfiguration method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // property names of the NumberValues class
    String[] propertyNames = { "columnOneNumber", "columnTwoNumber", "columnThreeNumber", "columnFourNumber", "columnFiveNumber" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("columnOneNumber", "Column 1");
    propertyToLabelMap.put("columnTwoNumber", "Column 2");
    propertyToLabelMap.put("columnThreeNumber", "Column 3");
    propertyToLabelMap.put("columnFourNumber", "Column 4");
    propertyToLabelMap.put("columnFiveNumber", "Column 5");
    DefaultGridLayer gridLayer = new DefaultGridLayer(createNumberValuesList(), propertyNames, propertyToLabelMap);
    DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
    bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
    registerColumnLabels(columnLabelAccumulator);
    NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new TableEditConfiguration());
    natTable.configure();
    return natTable;
}
Also used : DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) HashMap(java.util.HashMap) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)

Example 87 with DefaultNatTableStyleConfiguration

use of org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration in project nebula.widgets.nattable by eclipse.

the class _5013_PercentageSizingGridExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    Composite panel = new Composite(parent, SWT.NONE);
    panel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
    Composite gridPanel = new Composite(panel, SWT.NONE);
    gridPanel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(gridPanel);
    Composite buttonPanel = new Composite(panel, SWT.NONE);
    buttonPanel.setLayout(new RowLayout());
    GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);
    final DummyModifiableBodyDataProvider dataProvider = new DummyModifiableBodyDataProvider(3, 2);
    // example for percentage calculation with default sizing in a grid
    // all columns will be same size while the NatTable itself will have
    // 100%
    SimpleGridLayer gridLayer = new SimpleGridLayer(dataProvider);
    final DataLayer n4DataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    n4DataLayer.setColumnPercentageSizing(true);
    n4DataLayer.setRowPercentageSizing(true);
    // use different style bits to avoid rendering of inactive scrollbars
    // for small table when using percentage sizing, typically there should
    // be no scrollbars, as the table should take the available space
    // Note: The enabling/disabling and showing of the scrollbars is handled
    // by the ViewportLayer. Without the ViewportLayer the scrollbars will
    // always be visible with the default style bits of NatTable.
    final NatTable n4 = new NatTable(gridPanel, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED, gridLayer, false);
    n4.addConfiguration(new DefaultNatTableStyleConfiguration());
    n4.addConfiguration(new HeaderMenuConfiguration(n4));
    n4.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(n4);
    // example for fixed percentage sizing in a grid
    // ensure that the sum of column sizes is not greater than 100
    gridLayer = new SimpleGridLayer(dataProvider);
    final DataLayer n5DataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    n5DataLayer.setColumnWidthByPosition(0, 25);
    n5DataLayer.setColumnWidthByPosition(1, 25);
    n5DataLayer.setColumnWidthByPosition(2, 50);
    n5DataLayer.setColumnPercentageSizing(true);
    // use different style bits to avoid rendering of inactive scrollbars
    // for small table when using percentage sizing, typically there should
    // be no scrollbars, as the table should take the available space
    // Note: The enabling/disabling and showing of the scrollbars is handled
    // by the ViewportLayer. Without the ViewportLayer the scrollbars will
    // always be visible with the default style bits of NatTable.
    final NatTable n5 = new NatTable(gridPanel, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED, gridLayer, false);
    n5.addConfiguration(new DefaultNatTableStyleConfiguration());
    n5.addConfiguration(new HeaderMenuConfiguration(n5));
    n5.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(n5);
    // example for mixed percentage sizing in a grid configure not every
    // column with the exact percentage value, this way the columns for
    // which no exact values are set will use the remaining space
    gridLayer = new SimpleGridLayer(dataProvider);
    final DataLayer n6DataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    n6DataLayer.setColumnWidthByPosition(0, 20);
    n6DataLayer.setColumnWidthByPosition(2, 20);
    n6DataLayer.setColumnPercentageSizing(true);
    // use different style bits to avoid rendering of inactive scrollbars
    // for small table when using percentage sizing, typically there should
    // be no scrollbars, as the table should take the available space
    // Note: The enabling/disabling and showing of the scrollbars is handled
    // by the ViewportLayer. Without the ViewportLayer the scrollbars will
    // always be visible with the default style bits of NatTable.
    final NatTable n6 = new NatTable(gridPanel, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED, gridLayer, false);
    n6.addConfiguration(new DefaultNatTableStyleConfiguration());
    n6.addConfiguration(new HeaderMenuConfiguration(n6));
    n6.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(n6);
    // example for mixed fixed/percentage sizing in a grid configure not
    // every column with the exact percentage value, this way the columns
    // for which no exact values are set will use the remaining space
    gridLayer = new SimpleGridLayer(dataProvider);
    final DataLayer mixGridDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    mixGridDataLayer.setColumnPercentageSizing(true);
    mixGridDataLayer.setColumnPercentageSizing(0, false);
    mixGridDataLayer.setColumnPercentageSizing(1, false);
    mixGridDataLayer.setColumnWidthByPosition(0, 100);
    mixGridDataLayer.setColumnWidthByPosition(1, 100);
    // use different style bits to avoid rendering of inactive scrollbars
    // for small table when using percentage sizing, typically there should
    // be no scrollbars, as the table should take the available space
    // Note: The enabling/disabling and showing of the scrollbars is handled
    // by the ViewportLayer. Without the ViewportLayer the scrollbars will
    // always be visible with the default style bits of NatTable.
    final NatTable mixGrid = new NatTable(gridPanel, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED, gridLayer, false);
    mixGrid.addConfiguration(new DefaultNatTableStyleConfiguration());
    mixGrid.addConfiguration(new HeaderMenuConfiguration(mixGrid));
    mixGrid.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(mixGrid);
    Button addColumnButton = new Button(buttonPanel, SWT.PUSH);
    addColumnButton.setText("add column - no width");
    addColumnButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dataProvider.setColumnCount(dataProvider.getColumnCount() + 1);
            n4.refresh();
            n5.refresh();
            n6.refresh();
            mixGrid.refresh();
        }
    });
    Button addColumnButton2 = new Button(buttonPanel, SWT.PUSH);
    addColumnButton2.setText("add column - 20 percent width");
    addColumnButton2.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dataProvider.setColumnCount(dataProvider.getColumnCount() + 1);
            n4DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
            n5DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
            n6DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
            mixGridDataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
            n4.refresh();
            n5.refresh();
            n6.refresh();
            mixGrid.refresh();
        }
    });
    return panel;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) 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) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DummyModifiableBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyModifiableBodyDataProvider) NatTable(org.eclipse.nebula.widgets.nattable.NatTable)

Example 88 with DefaultNatTableStyleConfiguration

use of org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration in project nebula.widgets.nattable by eclipse.

the class _5014_SpanningDataLayerExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // To make the default edit and selection configurations work correctly,
    // the region label
    // GridRegion.BODY is necessary, which is directly set to the
    // ViewportLayer instance here.
    ViewportLayer layer = new ViewportLayer(new SelectionLayer(new SpanningDataLayer(new DummySpanningBodyDataProvider(100, 100))));
    layer.setRegionName(GridRegion.BODY);
    NatTable natTable = new NatTable(parent, layer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    // add configurations to enable editing
    // this is to verify that spanned cells are also editable and update the
    // data model correctly
    // @see Bug 414754
    layer.addConfiguration(new DefaultEditBindings());
    layer.addConfiguration(new DefaultEditConfiguration());
    layer.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE);
        }
    });
    natTable.configure();
    return natTable;
}
Also used : DefaultEditConfiguration(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) DefaultEditBindings(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings)

Example 89 with DefaultNatTableStyleConfiguration

use of org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration in project nebula.widgets.nattable by eclipse.

the class _5054_SelectionProviderExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    Composite panel = new Composite(parent, SWT.NONE);
    panel.setLayout(new GridLayout(2, true));
    // property names of the Person class
    String[] propertyNames = { "lastName", "firstName" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("lastName", "Lastname");
    propertyToLabelMap.put("firstName", "Firstname");
    IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    IRowIdAccessor<Person> rowIdAccessor = new IRowIdAccessor<Person>() {

        @Override
        public Serializable getRowId(Person rowObject) {
            return rowObject.getId();
        }
    };
    // create the first table
    // create the body layer stack
    final IRowDataProvider<Person> firstBodyDataProvider = new ListDataProvider<>(getSimpsonsList(), columnPropertyAccessor);
    final DataLayer firstBodyDataLayer = new DataLayer(firstBodyDataProvider);
    final SelectionLayer firstSelectionLayer = new SelectionLayer(firstBodyDataLayer);
    ViewportLayer firstViewportLayer = new ViewportLayer(firstSelectionLayer);
    // use a RowSelectionModel that will perform row selections and is able
    // to identify a row via unique ID
    firstSelectionLayer.setSelectionModel(new RowSelectionModel<>(firstSelectionLayer, firstBodyDataProvider, rowIdAccessor));
    // create the column header layer stack
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DataLayer firstColumnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
    ColumnHeaderLayer firstColumnHeaderLayer = new ColumnHeaderLayer(firstColumnHeaderDataLayer, firstViewportLayer, firstSelectionLayer);
    // register custom label styling to indicate if the table is active
    firstColumnHeaderDataLayer.setConfigLabelAccumulator(new IConfigLabelAccumulator() {

        @Override
        public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
            if (_5054_SelectionProviderExample.this.isFirstSelectionProvider) {
                configLabels.addLabelOnTop(ACTIVE_LABEL);
            }
        }
    });
    // set the region labels to make default configurations work, e.g.
    // selection
    CompositeLayer firstCompositeLayer = new CompositeLayer(1, 2);
    firstCompositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, firstColumnHeaderLayer, 0, 0);
    firstCompositeLayer.setChildLayer(GridRegion.BODY, firstViewportLayer, 0, 1);
    final NatTable firstNatTable = new NatTable(panel, firstCompositeLayer, false);
    firstNatTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    firstNatTable.addConfiguration(new ActiveTableStyleConfiguration());
    firstNatTable.configure();
    // set the modern theme
    firstNatTable.setTheme(new ModernNatTableThemeConfiguration());
    // add overlay painter for full borders
    firstNatTable.addOverlayPainter(new NatTableBorderOverlayPainter());
    // create the second table
    // create the body layer stack
    final IRowDataProvider<Person> secondBodyDataProvider = new ListDataProvider<>(getFlandersList(), columnPropertyAccessor);
    final DataLayer secondBodyDataLayer = new DataLayer(secondBodyDataProvider);
    final SelectionLayer secondSelectionLayer = new SelectionLayer(secondBodyDataLayer);
    ViewportLayer secondViewportLayer = new ViewportLayer(secondSelectionLayer);
    // use a RowSelectionModel that will perform row selections and is able
    // to identify a row via unique ID
    secondSelectionLayer.setSelectionModel(new RowSelectionModel<>(secondSelectionLayer, secondBodyDataProvider, rowIdAccessor));
    // create the column header layer stack
    DataLayer secondColumnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
    ILayer secondColumnHeaderLayer = new ColumnHeaderLayer(secondColumnHeaderDataLayer, secondViewportLayer, secondSelectionLayer);
    // register custom label styling to indicate if the table is active
    secondColumnHeaderDataLayer.setConfigLabelAccumulator(new IConfigLabelAccumulator() {

        @Override
        public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
            if (!_5054_SelectionProviderExample.this.isFirstSelectionProvider) {
                configLabels.addLabelOnTop(ACTIVE_LABEL);
            }
        }
    });
    // set the region labels to make default configurations work, e.g.
    // selection
    CompositeLayer secondCompositeLayer = new CompositeLayer(1, 2);
    secondCompositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, secondColumnHeaderLayer, 0, 0);
    secondCompositeLayer.setChildLayer(GridRegion.BODY, secondViewportLayer, 0, 1);
    final NatTable secondNatTable = new NatTable(panel, secondCompositeLayer, false);
    secondNatTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    secondNatTable.addConfiguration(new ActiveTableStyleConfiguration());
    secondNatTable.configure();
    // set the modern theme
    secondNatTable.setTheme(new ModernNatTableThemeConfiguration());
    // add overlay painter for full borders
    secondNatTable.addOverlayPainter(new NatTableBorderOverlayPainter());
    // set ISelectionProvider
    final RowSelectionProvider<Person> selectionProvider = new RowSelectionProvider<>(firstSelectionLayer, firstBodyDataProvider);
    // add a listener to the selection provider, in an Eclipse application
    // you would do this e.g. getSite().getPage().addSelectionListener()
    selectionProvider.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            log("Selection changed:");
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            @SuppressWarnings("rawtypes") Iterator it = selection.iterator();
            while (it.hasNext()) {
                Person selected = (Person) it.next();
                log("  " + selected.getFirstName() + " " + selected.getLastName());
            }
        }
    });
    // layout widgets
    GridDataFactory.fillDefaults().grab(true, true).applyTo(firstNatTable);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(secondNatTable);
    // add a region for buttons
    Composite buttonArea = new Composite(panel, SWT.NONE);
    buttonArea.setLayout(new RowLayout());
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(buttonArea);
    // create a button to enable selection provider change
    Button button = new Button(buttonArea, SWT.PUSH);
    button.setText("Change selection provider");
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            _5054_SelectionProviderExample.this.isFirstSelectionProvider = !_5054_SelectionProviderExample.this.isFirstSelectionProvider;
            if (_5054_SelectionProviderExample.this.isFirstSelectionProvider) {
                selectionProvider.updateSelectionProvider(firstSelectionLayer, firstBodyDataProvider);
            } else {
                selectionProvider.updateSelectionProvider(secondSelectionLayer, secondBodyDataProvider);
            }
            // refresh both tables to update the active rendering in the
            // column header/ this is not necessary for updating the
            // selection provider
            firstNatTable.doCommand(new VisualRefreshCommand());
            secondNatTable.doCommand(new VisualRefreshCommand());
        }
    });
    // add a log area to the example to show the log entries
    Text output = setupTextArea(panel);
    GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(output);
    return panel;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) IConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) IRowIdAccessor(org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor) GridLayout(org.eclipse.swt.layout.GridLayout) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) RowLayout(org.eclipse.swt.layout.RowLayout) Iterator(java.util.Iterator) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) NatTableBorderOverlayPainter(org.eclipse.nebula.widgets.nattable.painter.NatTableBorderOverlayPainter) VisualRefreshCommand(org.eclipse.nebula.widgets.nattable.command.VisualRefreshCommand) ModernNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration) Composite(org.eclipse.swt.widgets.Composite) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) RowSelectionProvider(org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person)

Example 90 with DefaultNatTableStyleConfiguration

use of org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration in project nebula.widgets.nattable by eclipse.

the class _5061_SimpleHoverStylingExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "gender", "married", "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.
    IDataProvider bodyDataProvider = new DefaultBodyDataProvider<>(PersonService.getPersons(10), propertyNames);
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    HoverLayer hoverLayer = new HoverLayer(bodyDataLayer, false);
    // we need to ensure that the hover styling is removed when the mouse
    // cursor moves out of the cell area
    hoverLayer.addConfiguration(new SimpleHoverStylingBindings(hoverLayer));
    SelectionLayer selectionLayer = new SelectionLayer(hoverLayer);
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    viewportLayer.setRegionName(GridRegion.BODY);
    // turn the auto configuration off as we want to add our hover styling
    // configuration
    NatTable natTable = new NatTable(parent, viewportLayer, false);
    // as the autoconfiguration of the NatTable is turned off, we have to
    // add the DefaultNatTableStyleConfiguration manually
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    // add the style configuration for hover
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            // style that is applied when cells are hovered
            Style style = new Style();
            style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.COLOR_YELLOW);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.HOVER);
            // style that is applied when selected cells are hovered
            style = new Style();
            style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.COLOR_GREEN);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.SELECT_HOVER);
        }
    });
    natTable.configure();
    return natTable;
}
Also used : AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) HoverLayer(org.eclipse.nebula.widgets.nattable.hover.HoverLayer) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) DefaultBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultBodyDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) Style(org.eclipse.nebula.widgets.nattable.style.Style) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) SimpleHoverStylingBindings(org.eclipse.nebula.widgets.nattable.hover.config.SimpleHoverStylingBindings)

Aggregations

DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)127 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)113 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)96 HashMap (java.util.HashMap)72 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)72 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)72 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)64 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)61 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)61 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)58 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)58 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)56 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)54 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)54 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)52 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)51 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)49 GridLayout (org.eclipse.swt.layout.GridLayout)47 Composite (org.eclipse.swt.widgets.Composite)43 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)41