Search in sources :

Example 1 with RowOnlySelectionBindings

use of org.eclipse.nebula.widgets.nattable.selection.config.RowOnlySelectionBindings 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)

Example 2 with RowOnlySelectionBindings

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

the class Real_time_data_updates method createExampleControl.

/**
 * @see GlazedListsGridLayer to see the required stack setup. Basically the
 *      {@link DataLayer} needs to be wrapped up with a
 *      {@link GlazedListsEventLayer} and the backing list needs to be an
 *      {@link EventList}
 */
@Override
public Control createExampleControl(Composite parent) {
    this.eventList = GlazedLists.eventList(RowDataListFixture.getList(this.defaultDatasetSize));
    ConfigRegistry configRegistry = new ConfigRegistry();
    GlazedListsGridLayer<RowDataFixture> glazedListsGridLayer = new GlazedListsGridLayer<>(this.eventList, RowDataListFixture.getPropertyNames(), RowDataListFixture.getPropertyToLabelMap(), configRegistry);
    this.nattable = new NatTable(parent, glazedListsGridLayer, false);
    this.nattable.setConfigRegistry(configRegistry);
    this.nattable.addConfiguration(new DefaultNatTableStyleConfiguration());
    this.nattable.addConfiguration(new SingleClickSortConfiguration());
    SelectionLayer selectionLayer = glazedListsGridLayer.getBodyLayerStack().getSelectionLayer();
    ListDataProvider<RowDataFixture> bodyDataProvider = glazedListsGridLayer.getBodyDataProvider();
    // Select complete rows
    RowOnlySelectionConfiguration<RowDataFixture> selectionConfig = new RowOnlySelectionConfiguration<>();
    selectionLayer.addConfiguration(selectionConfig);
    this.nattable.addConfiguration(new RowOnlySelectionBindings());
    // Preserve selection on updates and sort
    selectionLayer.setSelectionModel(new RowSelectionModel<>(selectionLayer, bodyDataProvider, new IRowIdAccessor<RowDataFixture>() {

        @Override
        public Serializable getRowId(RowDataFixture rowObject) {
            return rowObject.getSecurity_id();
        }
    }));
    this.nattable.configure();
    // Layout widgets
    parent.setLayout(new GridLayout(1, true));
    this.nattable.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    setupTextArea(parent);
    setupButtons(parent);
    return this.nattable;
}
Also used : GlazedListsGridLayer(org.eclipse.nebula.widgets.nattable.examples.fixtures.GlazedListsGridLayer) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) RowOnlySelectionConfiguration(org.eclipse.nebula.widgets.nattable.selection.config.RowOnlySelectionConfiguration) IRowIdAccessor(org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) GridLayout(org.eclipse.swt.layout.GridLayout) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SingleClickSortConfiguration(org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration) 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)2 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)2 IRowIdAccessor (org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor)2 RowDataFixture (org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture)2 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)2 RowOnlySelectionBindings (org.eclipse.nebula.widgets.nattable.selection.config.RowOnlySelectionBindings)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)1 GlazedListsGridLayer (org.eclipse.nebula.widgets.nattable.examples.fixtures.GlazedListsGridLayer)1 SelectionExampleGridLayer (org.eclipse.nebula.widgets.nattable.examples.fixtures.SelectionExampleGridLayer)1 DefaultSelectionStyleConfiguration (org.eclipse.nebula.widgets.nattable.selection.config.DefaultSelectionStyleConfiguration)1 RowOnlySelectionConfiguration (org.eclipse.nebula.widgets.nattable.selection.config.RowOnlySelectionConfiguration)1 SingleClickSortConfiguration (org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration)1 HeaderMenuConfiguration (org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration)1