Search in sources :

Example 1 with SelectionExampleGridLayer

use of org.eclipse.nebula.widgets.nattable.examples.fixtures.SelectionExampleGridLayer in project nebula.widgets.nattable by eclipse.

the class Rendering_cells_as_a_link_and_button method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    this.gridLayer = new SelectionExampleGridLayer();
    NatTable natTable = new NatTable(parent, this.gridLayer, false);
    IConfigRegistry configRegistry = new ConfigRegistry();
    DataLayer bodyDataLayer = this.gridLayer.getBodyDataLayer();
    // Step 1: Create a label accumulator - adds custom labels to all cells
    // which we wish to render differently. In this case render as a button.
    ColumnOverrideLabelAccumulator cellLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
    cellLabelAccumulator.registerColumnOverrides(0, LINK_CELL_LABEL);
    cellLabelAccumulator.registerColumnOverrides(2, BUTTON_CELL_LABEL);
    // Step 2: Register label accumulator
    bodyDataLayer.setConfigLabelAccumulator(cellLabelAccumulator);
    // Step 3: Register your custom cell style and , against the
    // label applied to the link cell.
    LinkClickConfiguration<RowDataFixture> linkClickConfiguration = new LinkClickConfiguration<>();
    addLinkToColumn(configRegistry, natTable.getDisplay().getSystemColor(SWT.COLOR_BLUE), linkClickConfiguration);
    natTable.addConfiguration(linkClickConfiguration);
    // Step 4: Register your custom cell painter, cell style, against the
    // label applied to the button cell.
    addButtonToColumn(configRegistry);
    natTable.addConfiguration(new ButtonClickConfiguration<RowDataFixture>(this.buttonPainter));
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new DebugMenuConfiguration(natTable));
    natTable.setConfigRegistry(configRegistry);
    natTable.configure();
    // Layout SWT widgets. Not relevant to example code.
    parent.setLayout(new GridLayout(1, true));
    natTable.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    setupTextArea(parent);
    return natTable;
}
Also used : SelectionExampleGridLayer(org.eclipse.nebula.widgets.nattable.examples.fixtures.SelectionExampleGridLayer) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) GridLayout(org.eclipse.swt.layout.GridLayout) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) GridData(org.eclipse.swt.layout.GridData) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) DebugMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.DebugMenuConfiguration) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator)

Example 2 with SelectionExampleGridLayer

use of org.eclipse.nebula.widgets.nattable.examples.fixtures.SelectionExampleGridLayer in project nebula.widgets.nattable by eclipse.

the class Applying_style_to_a_cell method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    SelectionExampleGridLayer gridLayer = new SelectionExampleGridLayer();
    NatTable natTable = new NatTable(parent, gridLayer, false);
    DataLayer bodyDataLayer = gridLayer.getBodyDataLayer();
    // Label accumulator - adds labels to all cells with the given data
    // value
    CellOverrideLabelAccumulator<RowDataFixture> cellLabelAccumulator = new CellOverrideLabelAccumulator<>(gridLayer.getBodyDataProvider());
    cellLabelAccumulator.registerOverride("AAA", 2, CELL_LABEL);
    // Register your cell style, against the label applied to the cell
    // Other configuration which can be added (apart from style) include
    // CellConfigAttributes, EditConfigAttributes, SortConfigAttributes etc.
    IConfigRegistry configRegistry = new ConfigRegistry();
    addColumnHighlight(configRegistry);
    // Register label accumulator
    bodyDataLayer.setConfigLabelAccumulator(cellLabelAccumulator);
    gridLayer.getSelectionLayer().addConfiguration(new DefaultSelectionLayerConfiguration());
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.setConfigRegistry(configRegistry);
    natTable.configure();
    return natTable;
}
Also used : SelectionExampleGridLayer(org.eclipse.nebula.widgets.nattable.examples.fixtures.SelectionExampleGridLayer) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) CellOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.CellOverrideLabelAccumulator) DefaultSelectionLayerConfiguration(org.eclipse.nebula.widgets.nattable.selection.config.DefaultSelectionLayerConfiguration)

Example 3 with SelectionExampleGridLayer

use of org.eclipse.nebula.widgets.nattable.examples.fixtures.SelectionExampleGridLayer in project nebula.widgets.nattable by eclipse.

the class Selection_events method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    this.gridLayer = new SelectionExampleGridLayer();
    this.nattable = new NatTable(parent, this.gridLayer, false);
    this.nattable.addConfiguration(new DefaultNatTableStyleConfiguration());
    this.nattable.addConfiguration(new HeaderMenuConfiguration(this.nattable));
    this.nattable.addConfiguration(new DefaultSelectionStyleConfiguration());
    // Custom selection configuration
    SelectionLayer selectionLayer = this.gridLayer.getSelectionLayer();
    selectionLayer.setSelectionModel(new RowSelectionModel<>(selectionLayer, this.gridLayer.getBodyDataProvider(), new IRowIdAccessor<RowDataFixture>() {

        @Override
        public Serializable getRowId(RowDataFixture rowObject) {
            return rowObject.getSecurity_id();
        }
    }));
    selectionLayer.addConfiguration(new RowOnlySelectionConfiguration<RowDataFixture>());
    this.nattable.addConfiguration(new RowOnlySelectionBindings());
    this.nattable.configure();
    addCustomSelectionBehaviour();
    // Layout widgets
    parent.setLayout(new GridLayout(1, true));
    this.nattable.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    setupTextArea(parent);
    return this.nattable;
}
Also used : SelectionExampleGridLayer(org.eclipse.nebula.widgets.nattable.examples.fixtures.SelectionExampleGridLayer) DefaultSelectionStyleConfiguration(org.eclipse.nebula.widgets.nattable.selection.config.DefaultSelectionStyleConfiguration) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) IRowIdAccessor(org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor) GridLayout(org.eclipse.swt.layout.GridLayout) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) GridData(org.eclipse.swt.layout.GridData) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) RowOnlySelectionBindings(org.eclipse.nebula.widgets.nattable.selection.config.RowOnlySelectionBindings)

Aggregations

NatTable (org.eclipse.nebula.widgets.nattable.NatTable)3 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)3 RowDataFixture (org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture)3 SelectionExampleGridLayer (org.eclipse.nebula.widgets.nattable.examples.fixtures.SelectionExampleGridLayer)3 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)2 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)2 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 IRowIdAccessor (org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor)1 CellOverrideLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.CellOverrideLabelAccumulator)1 ColumnOverrideLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator)1 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)1 DefaultSelectionLayerConfiguration (org.eclipse.nebula.widgets.nattable.selection.config.DefaultSelectionLayerConfiguration)1 DefaultSelectionStyleConfiguration (org.eclipse.nebula.widgets.nattable.selection.config.DefaultSelectionStyleConfiguration)1 RowOnlySelectionBindings (org.eclipse.nebula.widgets.nattable.selection.config.RowOnlySelectionBindings)1 DebugMenuConfiguration (org.eclipse.nebula.widgets.nattable.ui.menu.DebugMenuConfiguration)1 HeaderMenuConfiguration (org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration)1