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;
}
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;
}
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;
}
Aggregations