Search in sources :

Example 91 with ConfigRegistry

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

the class ColumnStructureUpdatesGridExample method createExampleControl.

/**
 * NOTE - Glazed {@link EventList} class is thread ready but not thread
 * safe.
 */
@Override
public Control createExampleControl(Composite parent) {
    EventList<PricingDataBean> eventList = GlazedLists.eventList(PricingDataBeanGenerator.getData(10));
    this.rowObjectsGlazedList = GlazedLists.threadSafeList(eventList);
    Map<String, String> propertyToLabelMap = populateColHeaderPropertiesToLabelsMap();
    String[] propertyNames = propertyToLabelMap.keySet().toArray(ArrayUtil.STRING_TYPE_ARRAY);
    ConfigRegistry configRegistry = new ConfigRegistry();
    final ColumnStructureUpdatesExampleGridLayer<PricingDataBean> glazedListsGridLayer = new ColumnStructureUpdatesExampleGridLayer<>(this.rowObjectsGlazedList, propertyNames, propertyToLabelMap, configRegistry, true);
    final NatTable natTable = new NatTable(parent, glazedListsGridLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.setConfigRegistry(configRegistry);
    natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE, DisplayMode.EDIT, "ODD_BODY");
    natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE, DisplayMode.EDIT, "EVEN_BODY");
    natTable.configure();
    glazedListsGridLayer.bodyDataProvider.setColumnCount(2);
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));
    Button button = new Button(composite, SWT.PUSH);
    button.setText("Clear list, add 6 items, Change column count");
    button.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.getReadWriteLock().writeLock().lock();
            try {
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.clear();
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.add(new PricingDataBean());
                glazedListsGridLayer.bodyDataProvider.setColumnCount(8);
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.add(new PricingDataBean());
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.add(new PricingDataBean());
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.add(new PricingDataBean());
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.add(new PricingDataBean());
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.add(new PricingDataBean());
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.add(new PricingDataBean());
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.add(new PricingDataBean());
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.add(new PricingDataBean());
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.add(new PricingDataBean());
            } finally {
                ColumnStructureUpdatesGridExample.this.rowObjectsGlazedList.getReadWriteLock().writeLock().unlock();
            }
        }
    });
    return natTable;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) ColumnStructureUpdatesExampleGridLayer(org.eclipse.nebula.widgets.nattable.examples.fixtures.ColumnStructureUpdatesExampleGridLayer) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) PricingDataBean(org.eclipse.nebula.widgets.nattable.dataset.pricing.PricingDataBean) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 92 with ConfigRegistry

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

ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)92 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)72 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)61 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)54 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)54 HashMap (java.util.HashMap)40 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)38 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)38 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)34 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)34 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)33 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)33 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)33 GridLayout (org.eclipse.swt.layout.GridLayout)33 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)32 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)31 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)31 Composite (org.eclipse.swt.widgets.Composite)31 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)28 SelectionEvent (org.eclipse.swt.events.SelectionEvent)28