use of org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration in project nebula.widgets.nattable by eclipse.
the class _5113_RowGroupingExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// Body
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("firstName", "Firstname");
propertyToLabelMap.put("lastName", "Lastname");
propertyToLabelMap.put("gender", "Gender");
propertyToLabelMap.put("married", "Married");
propertyToLabelMap.put("birthday", "Birthday");
// build the body layer stack
// Usually you would create a new layer stack by extending
// AbstractIndexLayerTransform and setting the ViewportLayer as
// underlying layer. But in this case using the ViewportLayer directly
// as body layer is also working.
IRowDataProvider<Person> bodyDataProvider = new DefaultBodyDataProvider<>(getStaticPersonList(), propertyNames);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(bodyDataLayer);
ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
RowHideShowLayer rowHideShowLayer = new RowHideShowLayer(columnHideShowLayer);
RowGroupModel<Person> rowGroupModel = new RowGroupModel<>();
rowGroupModel.setDataProvider(bodyDataProvider);
RowGroupExpandCollapseLayer<Person> rowExpandCollapseLayer = new RowGroupExpandCollapseLayer<>(rowHideShowLayer, rowGroupModel);
SelectionLayer selectionLayer = new SelectionLayer(rowExpandCollapseLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// Column header
DefaultColumnHeaderDataProvider defaultColumnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DefaultColumnHeaderDataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(defaultColumnHeaderDataProvider);
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
// Row header
DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer, false);
rowHeaderLayer.addConfiguration(new RowHeaderConfiguration());
RowGroupHeaderLayer<Person> rowGroupHeaderLayer = new RowGroupHeaderLayer<>(rowHeaderLayer, selectionLayer, rowGroupModel);
rowGroupHeaderLayer.setColumnWidth(20);
// Create a group of rows for the model.
RowGroup<Person> rowGroup = new RowGroup<>(rowGroupModel, "Simpson", false);
rowGroup.addMemberRow(bodyDataProvider.getRowObject(0));
rowGroup.addStaticMemberRow(bodyDataProvider.getRowObject(1));
rowGroup.addMemberRow(bodyDataProvider.getRowObject(2));
rowGroup.addMemberRow(bodyDataProvider.getRowObject(3));
rowGroup.addMemberRow(bodyDataProvider.getRowObject(4));
rowGroupModel.addRowGroup(rowGroup);
rowGroup = new RowGroup<>(rowGroupModel, "Flanders", false);
rowGroup.addMemberRow(bodyDataProvider.getRowObject(5));
rowGroup.addStaticMemberRow(bodyDataProvider.getRowObject(6));
rowGroup.addMemberRow(bodyDataProvider.getRowObject(7));
rowGroup.addMemberRow(bodyDataProvider.getRowObject(8));
rowGroupModel.addRowGroup(rowGroup);
rowGroup = new RowGroup<>(rowGroupModel, "Lovejoy", true);
rowGroup.addMemberRow(bodyDataProvider.getRowObject(9));
rowGroup.addStaticMemberRow(bodyDataProvider.getRowObject(10));
rowGroup.addMemberRow(bodyDataProvider.getRowObject(11));
rowGroupModel.addRowGroup(rowGroup);
// Corner
final DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(defaultColumnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowGroupHeaderLayer, columnHeaderLayer);
// Grid
GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowGroupHeaderLayer, cornerLayer);
NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
natTable.configure();
natTable.setTheme(new ModernNatTableThemeConfiguration());
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration in project nebula.widgets.nattable by eclipse.
the class _5121_SummaryRowExample method createExampleControl.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.nebula.widgets.nattable.examples.INatExample#createExampleControl
* (org.eclipse.swt.widgets.Composite)
*/
@Override
public Control createExampleControl(Composite parent) {
// property names of the NumberValues class
String[] propertyNames = { "columnOneNumber", "columnTwoNumber", "columnThreeNumber", "columnFourNumber", "columnFiveNumber" };
IColumnPropertyAccessor<NumberValues> cpa = new ReflectiveColumnPropertyAccessor<>(propertyNames);
IDataProvider dataProvider = new ListDataProvider<>(createNumberValueList(), cpa);
ConfigRegistry configRegistry = new ConfigRegistry();
DataLayer dataLayer = new DataLayer(dataProvider);
// Plug in the SummaryRowLayer
SummaryRowLayer summaryRowLayer = new SummaryRowLayer(dataLayer, configRegistry, false);
ViewportLayer viewportLayer = new ViewportLayer(summaryRowLayer);
NatTable natTable = new NatTable(parent, viewportLayer, false);
// Configure custom summary formula for a column
natTable.addConfiguration(new ExampleSummaryRowConfiguration(dataProvider));
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.setConfigRegistry(configRegistry);
natTable.configure();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration in project nebula.widgets.nattable by eclipse.
the class ExampleSummaryRowGridConfiguration method createExampleControl.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.nebula.widgets.nattable.examples.INatExample#createExampleControl
* (org.eclipse.swt.widgets.Composite)
*/
@Override
public Control createExampleControl(Composite parent) {
// property names of the NumberValues class
String[] propertyNames = { "columnOneNumber", "columnTwoNumber", "columnThreeNumber", "columnFourNumber", "columnFiveNumber" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("columnOneNumber", "Column 1");
propertyToLabelMap.put("columnTwoNumber", "Column 2");
propertyToLabelMap.put("columnThreeNumber", "Column 3");
propertyToLabelMap.put("columnFourNumber", "Column 4");
propertyToLabelMap.put("columnFiveNumber", "Column 5");
IColumnPropertyAccessor<NumberValues> cpa = new ReflectiveColumnPropertyAccessor<>(propertyNames);
IDataProvider dataProvider = new ListDataProvider<>(createNumberValueList(), cpa);
ConfigRegistry configRegistry = new ConfigRegistry();
SummaryRowGridLayer gridLayer = new SummaryRowGridLayer(dataProvider, configRegistry, propertyNames, propertyToLabelMap);
NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.configure();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration in project nebula.widgets.nattable by eclipse.
the class _5124_SummaryRowPositionGridExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
Composite panel = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.verticalSpacing = 20;
panel.setLayout(layout);
// property names of the NumberValues class
String[] propertyNames = { "columnOneNumber", "columnTwoNumber", "columnThreeNumber", "columnFourNumber", "columnFiveNumber" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("columnOneNumber", "Column 1");
propertyToLabelMap.put("columnTwoNumber", "Column 2");
propertyToLabelMap.put("columnThreeNumber", "Column 3");
propertyToLabelMap.put("columnFourNumber", "Column 4");
propertyToLabelMap.put("columnFiveNumber", "Column 5");
IColumnPropertyAccessor<NumberValues> cpa = new ReflectiveColumnPropertyAccessor<>(propertyNames);
IDataProvider dataProvider = new ListDataProvider<>(createNumberValueList(), cpa);
ConfigRegistry configRegistry = new ConfigRegistry();
// Summary row on top
// The summary row is within the grid so it can be placed BETWEEN
// column header and body
// The body itself is a CompositeLayer with 1 column and 2 rows
// The first row is the SummaryRowLayer configured as standalone
// The second row is the body layer stack
// for correct rendering of the row header you should use the
// FixedSummaryRowHeaderLayer which is adding the correct labels and
// shows a special configurable label for the summary row
final SummaryRowGridLayer gridLayerWithSummary = new SummaryRowGridLayer(dataProvider, configRegistry, propertyNames, propertyToLabelMap, true);
NatTable natTable = new NatTable(panel, gridLayerWithSummary, false);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new DebugMenuConfiguration(natTable));
natTable.configure();
// Summary row at bottom
// The grid doesn't contain a summary row
// Instead create a CompositeLayer 1 column 2 rows
// first row = GridLayer
// second row = FixedGridSummaryRowLayer
final SummaryRowGridLayer gridLayer = new SummaryRowGridLayer(dataProvider, configRegistry, propertyNames, propertyToLabelMap, false);
// since the summary row should stay at a fixed position we need to add
// a new composite row
// this is necessary as also the row header cell needs to be fixed
// create a standalone summary row
// for a grid this is the FixedGridSummaryRowLayer
FixedSummaryRowLayer summaryRowLayer = new FixedSummaryRowLayer(gridLayer.getBodyDataLayer(), gridLayer, configRegistry, false);
summaryRowLayer.addConfiguration(new ExampleSummaryRowGridConfiguration(gridLayer.getBodyDataLayer().getDataProvider()));
summaryRowLayer.setSummaryRowLabel("\u2211");
// create a composition that has the grid on top and the summary row on
// the bottom
CompositeLayer composite = new CompositeLayer(1, 2);
composite.setChildLayer("GRID", gridLayer, 0, 0);
composite.setChildLayer(SUMMARY_REGION, summaryRowLayer, 0, 1);
natTable = new NatTable(panel, composite, false);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
// configure a painter that renders a line on top of the summary row
// this is necessary because the CompositeLayerPainter does not render
// lines on the top of a region
natTable.addOverlayPainter(new IOverlayPainter() {
@Override
public void paintOverlay(GC gc, ILayer layer) {
// render a line on top of the summary row
Color beforeColor = gc.getForeground();
gc.setForeground(GUIHelper.COLOR_GRAY);
int gridBorderY = gridLayer.getHeight() - 1;
gc.drawLine(0, gridBorderY, layer.getWidth() - 1, gridBorderY);
gc.setForeground(beforeColor);
}
});
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new DebugMenuConfiguration(natTable));
natTable.configure();
return panel;
}
use of org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration in project nebula.widgets.nattable by eclipse.
the class _513_FreezeExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
Composite panel = new Composite(parent, SWT.NONE);
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("firstName", "Firstname");
propertyToLabelMap.put("lastName", "Lastname");
propertyToLabelMap.put("gender", "Gender");
propertyToLabelMap.put("married", "Married");
propertyToLabelMap.put("birthday", "Birthday");
// build the body layer stack
// Usually you would create a new layer stack by extending
// AbstractIndexLayerTransform and setting the ViewportLayer as
// underlying layer. But in this case using the ViewportLayer directly
// as body layer is also working.
IDataProvider bodyDataProvider = new DefaultBodyDataProvider<>(PersonService.getPersons(10), propertyNames);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(bodyDataLayer);
ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
final SelectionLayer selectionLayer = new SelectionLayer(columnHideShowLayer);
final ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
final FreezeLayer freezeLayer = new FreezeLayer(selectionLayer);
final CompositeFreezeLayer compositeFreezeLayer = new CompositeFreezeLayer(freezeLayer, viewportLayer, selectionLayer);
// build the column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, compositeFreezeLayer, selectionLayer);
// build the row header layer
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, compositeFreezeLayer, selectionLayer);
// build the corner layer
IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnHeaderLayer);
// build the grid layer
GridLayer gridLayer = new GridLayer(compositeFreezeLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
// turn the auto configuration off as we want to add our header menu
// configuration
final NatTable natTable = new NatTable(panel, gridLayer, false);
// as the autoconfiguration of the NatTable is turned off, we have to
// add the DefaultNatTableStyleConfiguration manually
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new DefaultFreezeGridBindings());
// add the corner menu configuration for adding the view management
// action
natTable.addConfiguration(new AbstractHeaderMenuConfiguration(natTable) {
@Override
protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
return super.createColumnHeaderMenu(natTable).withHideColumnMenuItem().withShowAllColumnsMenuItem().withColumnChooserMenuItem();
}
@Override
protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
return super.createCornerMenu(natTable).withShowAllColumnsMenuItem().withStateManagerMenuItemProvider();
}
});
natTable.configure();
panel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
gridLayer.registerCommandHandler(new DisplayPersistenceDialogCommandHandler(natTable));
DisplayColumnChooserCommandHandler columnChooserCommandHandler = new DisplayColumnChooserCommandHandler(selectionLayer, columnHideShowLayer, columnHeaderLayer, columnHeaderDataLayer, null, null);
gridLayer.registerCommandHandler(columnChooserCommandHandler);
return panel;
}
Aggregations