Search in sources :

Example 1 with GlazedListsGridLayer

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

the class DynamicColumnExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // start with 3 columns
    this.columns.add("Column_0");
    this.columns.add("Column_1");
    this.columns.add("Column_2");
    this.values.add(createValueRow("Homer"));
    this.values.add(createValueRow("Marge"));
    this.values.add(createValueRow("Bart"));
    this.values.add(createValueRow("Lisa"));
    this.values.add(createValueRow("Maggie"));
    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 GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(buttonPanel);
    ConfigRegistry configRegistry = new ConfigRegistry();
    final GlazedListsGridLayer<Map<String, String>> glazedListsGridLayer = new GlazedListsGridLayer<>(this.values, new MyColumnPropertyAccessor(), new SimpleColumnHeaderDataProvider(), configRegistry, true);
    final NatTable natTable = new NatTable(gridPanel, glazedListsGridLayer, false);
    natTable.setConfigRegistry(configRegistry);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
    natTable.addConfiguration(new SingleClickSortConfiguration());
    natTable.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
    Button addColumnButton = new Button(buttonPanel, SWT.PUSH);
    addColumnButton.setText("add column");
    addColumnButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String newColumn = "Column_" + DynamicColumnExample.this.columns.size();
            DynamicColumnExample.this.columns.add(newColumn);
            for (Map<String, String> value : DynamicColumnExample.this.values) {
                String prefix = value.get("Column_0");
                prefix = prefix.substring(0, prefix.indexOf("_"));
                value.put(newColumn, prefix + "_" + (DynamicColumnExample.this.columns.size() - 1));
            }
            glazedListsGridLayer.getBodyDataLayer().fireLayerEvent(new ColumnInsertEvent(glazedListsGridLayer.getBodyDataLayer(), DynamicColumnExample.this.columns.size() - 1));
            natTable.refresh();
        }
    });
    natTable.doCommand(new ColumnHideCommand(glazedListsGridLayer.getBodyLayer(), 1));
    return panel;
}
Also used : GlazedListsGridLayer(org.eclipse.nebula.widgets.nattable.examples.fixtures.GlazedListsGridLayer) Composite(org.eclipse.swt.widgets.Composite) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SingleClickSortConfiguration(org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ColumnInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with GlazedListsGridLayer

use of org.eclipse.nebula.widgets.nattable.examples.fixtures.GlazedListsGridLayer 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 GlazedListsGridLayer

use of org.eclipse.nebula.widgets.nattable.examples.fixtures.GlazedListsGridLayer 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)3 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)3 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)3 GlazedListsGridLayer (org.eclipse.nebula.widgets.nattable.examples.fixtures.GlazedListsGridLayer)3 SingleClickSortConfiguration (org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration)3 RowDataFixture (org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture)2 HeaderMenuConfiguration (org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)1 IRowIdAccessor (org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor)1 ColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand)1 ColumnInsertEvent (org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent)1 DisplayPersistenceDialogCommandHandler (org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommandHandler)1 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)1 DefaultSelectionStyleConfiguration (org.eclipse.nebula.widgets.nattable.selection.config.DefaultSelectionStyleConfiguration)1 RowOnlySelectionBindings (org.eclipse.nebula.widgets.nattable.selection.config.RowOnlySelectionBindings)1 RowOnlySelectionConfiguration (org.eclipse.nebula.widgets.nattable.selection.config.RowOnlySelectionConfiguration)1 PopupMenuBuilder (org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder)1