Search in sources :

Example 1 with DefaultSelectionStyleConfiguration

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

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

the class SortableGridExample method createExampleControl.

/**
 * @see GlazedListsGridLayer to see the required stack setup. Basically the
 *      {@link SortHeaderLayer} needs to be a part of the Column header
 *      layer stack.
 */
@Override
public Control createExampleControl(Composite parent) {
    EventList<RowDataFixture> eventList = GlazedLists.eventList(RowDataListFixture.getList());
    this.rowObjectsGlazedList = GlazedLists.threadSafeList(eventList);
    ConfigRegistry configRegistry = new ConfigRegistry();
    GlazedListsGridLayer<RowDataFixture> glazedListsGridLayer = new GlazedListsGridLayer<>(this.rowObjectsGlazedList, RowDataListFixture.getPropertyNames(), RowDataListFixture.getPropertyToLabelMap(), configRegistry);
    this.nattable = new NatTable(parent, glazedListsGridLayer, false);
    this.nattable.setConfigRegistry(configRegistry);
    this.nattable.addConfiguration(new DefaultNatTableStyleConfiguration());
    // Change the default sort key bindings. Note that 'auto configure' was
    // turned off for the SortHeaderLayer (setup in the
    // GlazedListsGridLayer)
    this.nattable.addConfiguration(new SingleClickSortConfiguration());
    this.nattable.addConfiguration(getCustomComparatorConfiguration(glazedListsGridLayer.getColumnHeaderLayerStack().getDataLayer()));
    this.nattable.addConfiguration(new DefaultSelectionStyleConfiguration());
    this.nattable.addConfiguration(new HeaderMenuConfiguration(this.nattable) {

        @Override
        protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
            return super.createColumnHeaderMenu(natTable).withStateManagerMenuItemProvider();
        }
    });
    this.nattable.configure();
    // add the DisplayPersistenceDialogCommandHandler with the created
    // NatTable instance after configure() so all configuration and states
    // are correctly applied before storing the default state
    glazedListsGridLayer.registerCommandHandler(new DisplayPersistenceDialogCommandHandler(this.nattable));
    return this.nattable;
}
Also used : GlazedListsGridLayer(org.eclipse.nebula.widgets.nattable.examples.fixtures.GlazedListsGridLayer) 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) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DisplayPersistenceDialogCommandHandler(org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommandHandler) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SingleClickSortConfiguration(org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) PopupMenuBuilder(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder)

Example 3 with DefaultSelectionStyleConfiguration

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

the class _000_Styled_grid method addCustomStyling.

private void addCustomStyling(NatTable natTable) {
    // Setup NatTable default styling
    // NOTE: Getting the colors and fonts from the GUIHelper ensures that
    // they are disposed properly (required by SWT)
    DefaultNatTableStyleConfiguration natTableConfiguration = new DefaultNatTableStyleConfiguration();
    natTableConfiguration.bgColor = GUIHelper.getColor(249, 172, 7);
    natTableConfiguration.fgColor = GUIHelper.getColor(30, 76, 19);
    natTableConfiguration.hAlign = HorizontalAlignmentEnum.LEFT;
    natTableConfiguration.vAlign = VerticalAlignmentEnum.TOP;
    // A custom painter can be plugged in to paint the cells differently
    natTableConfiguration.cellPainter = new PaddingDecorator(new TextPainter(), 1);
    // Setup even odd row colors - row colors override the NatTable default
    // colors
    DefaultRowStyleConfiguration rowStyleConfiguration = new DefaultRowStyleConfiguration();
    rowStyleConfiguration.oddRowBgColor = GUIHelper.getColor(254, 251, 243);
    rowStyleConfiguration.evenRowBgColor = GUIHelper.COLOR_WHITE;
    // Setup selection styling
    DefaultSelectionStyleConfiguration selectionStyle = new DefaultSelectionStyleConfiguration();
    selectionStyle.selectionFont = GUIHelper.getFont(new FontData("Verdana", 8, SWT.NORMAL));
    selectionStyle.selectionBgColor = GUIHelper.getColor(217, 232, 251);
    selectionStyle.selectionFgColor = GUIHelper.COLOR_BLACK;
    selectionStyle.anchorBorderStyle = new BorderStyle(1, GUIHelper.COLOR_DARK_GRAY, LineStyleEnum.SOLID);
    selectionStyle.anchorBgColor = GUIHelper.getColor(65, 113, 43);
    selectionStyle.selectedHeaderBgColor = GUIHelper.getColor(156, 209, 103);
    // Add all style configurations to NatTable
    natTable.addConfiguration(natTableConfiguration);
    natTable.addConfiguration(rowStyleConfiguration);
    natTable.addConfiguration(selectionStyle);
    // Column/Row header style and custom painters
    natTable.addConfiguration(new StyledRowHeaderConfiguration());
    natTable.addConfiguration(new StyledColumnHeaderConfiguration());
    // Add popup menu - build your own popup menu using the PopupMenuBuilder
    natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
}
Also used : StyledRowHeaderConfiguration(org.eclipse.nebula.widgets.nattable.examples.fixtures.StyledRowHeaderConfiguration) DefaultRowStyleConfiguration(org.eclipse.nebula.widgets.nattable.grid.layer.config.DefaultRowStyleConfiguration) DefaultSelectionStyleConfiguration(org.eclipse.nebula.widgets.nattable.selection.config.DefaultSelectionStyleConfiguration) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle) FontData(org.eclipse.swt.graphics.FontData) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) StyledColumnHeaderConfiguration(org.eclipse.nebula.widgets.nattable.examples.fixtures.StyledColumnHeaderConfiguration) PaddingDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter)

Aggregations

DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)3 DefaultSelectionStyleConfiguration (org.eclipse.nebula.widgets.nattable.selection.config.DefaultSelectionStyleConfiguration)3 HeaderMenuConfiguration (org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration)3 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)2 RowDataFixture (org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture)2 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)1 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)1 IRowIdAccessor (org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor)1 GlazedListsGridLayer (org.eclipse.nebula.widgets.nattable.examples.fixtures.GlazedListsGridLayer)1 SelectionExampleGridLayer (org.eclipse.nebula.widgets.nattable.examples.fixtures.SelectionExampleGridLayer)1 StyledColumnHeaderConfiguration (org.eclipse.nebula.widgets.nattable.examples.fixtures.StyledColumnHeaderConfiguration)1 StyledRowHeaderConfiguration (org.eclipse.nebula.widgets.nattable.examples.fixtures.StyledRowHeaderConfiguration)1 DefaultRowStyleConfiguration (org.eclipse.nebula.widgets.nattable.grid.layer.config.DefaultRowStyleConfiguration)1 TextPainter (org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter)1 PaddingDecorator (org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator)1 DisplayPersistenceDialogCommandHandler (org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommandHandler)1 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)1 RowOnlySelectionBindings (org.eclipse.nebula.widgets.nattable.selection.config.RowOnlySelectionBindings)1 SingleClickSortConfiguration (org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration)1 BorderStyle (org.eclipse.nebula.widgets.nattable.style.BorderStyle)1