use of org.eclipse.nebula.widgets.nattable.layer.DataLayer in project nebula.widgets.nattable by eclipse.
the class _4471_EditorTraversalExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "birthday", "married", "gender" };
// 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("married", "Married");
propertyToLabelMap.put("gender", "Gender");
propertyToLabelMap.put("birthday", "Birthday");
IRowDataProvider<Person> bodyDataProvider = new ListDataProvider<>(PersonService.getPersons(10), new ExtendedReflectiveColumnPropertyAccessor<Person>(propertyNames));
DefaultGridLayer gridLayer = new DefaultGridLayer(bodyDataProvider, new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap));
final DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
registerColumnLabels(columnLabelAccumulator);
final NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new EditorConfiguration());
natTable.configure();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.layer.DataLayer in project nebula.widgets.nattable by eclipse.
the class _447_EditorExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "password", "description", "age", "money", "married", "gender", "birthday", "address.street", "address.city", "favouriteFood", "favouriteDrinks", "filename" };
// 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("password", "Password");
propertyToLabelMap.put("description", "Description");
propertyToLabelMap.put("age", "Age");
propertyToLabelMap.put("money", "Money");
propertyToLabelMap.put("married", "Married");
propertyToLabelMap.put("gender", "Gender");
propertyToLabelMap.put("birthday", "Birthday");
propertyToLabelMap.put("address.street", "Street");
propertyToLabelMap.put("address.city", "City");
propertyToLabelMap.put("favouriteFood", "Food");
propertyToLabelMap.put("favouriteDrinks", "Drinks");
propertyToLabelMap.put("filename", "Filename");
IDataProvider bodyDataProvider = new ListDataProvider<>(PersonService.getExtendedPersonsWithAddress(10), new ExtendedReflectiveColumnPropertyAccessor<ExtendedPersonWithAddress>(propertyNames));
DefaultGridLayer gridLayer = new DefaultGridLayer(bodyDataProvider, new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap));
final DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
registerColumnLabels(columnLabelAccumulator);
final NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new EditorConfiguration());
natTable.configure();
new NatTableContentTooltip(natTable, GridRegion.BODY);
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.layer.DataLayer in project nebula.widgets.nattable by eclipse.
the class _448_CDateTimeEditorExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
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, false).applyTo(buttonPanel);
// property names of the DateValues class
String[] propertyNames = { "columnOneDate", "columnTwoDate", "columnThreeDate", "columnFourDate", "columnFiveDate", "columnSixCalendar" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("columnOneDate", "Date/Time");
propertyToLabelMap.put("columnTwoDate", "Date");
propertyToLabelMap.put("columnThreeDate", "Time");
propertyToLabelMap.put("columnFourDate", "Time Discrete");
propertyToLabelMap.put("columnFiveDate", "Date/Time text only");
propertyToLabelMap.put("columnSixCalendar", "Calendar");
this.valuesToShow.add(createDateValues());
this.valuesToShow.add(createDateValues());
ConfigRegistry configRegistry = new ConfigRegistry();
DateGridLayer gridLayer = new DateGridLayer(this.valuesToShow, configRegistry, propertyNames, propertyToLabelMap);
DataLayer bodyDataLayer = gridLayer.getBodyDataLayer();
final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
registerColumnLabels(columnLabelAccumulator);
final NatTable natTable = new NatTable(gridPanel, gridLayer, false);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new DateEditConfiguration());
natTable.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
return panel;
}
use of org.eclipse.nebula.widgets.nattable.layer.DataLayer in project nebula.widgets.nattable by eclipse.
the class _5012_PercentageSizingDataLayerExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
Composite panel = new Composite(parent, SWT.NONE);
panel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
Composite simplePanel = new Composite(panel, SWT.NONE);
simplePanel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(simplePanel);
Composite buttonPanel = new Composite(panel, SWT.NONE);
buttonPanel.setLayout(new RowLayout());
GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);
final DummyModifiableBodyDataProvider dataProvider = new DummyModifiableBodyDataProvider(3, 2);
// example for percentage calculation with default sizing
// all columns will be same size while the NatTable itself will have
// 100%
final DataLayer n1DataLayer = new DataLayer(dataProvider);
n1DataLayer.setColumnPercentageSizing(true);
n1DataLayer.setRowPercentageSizing(true);
SelectionLayer layer = new SelectionLayer(n1DataLayer);
layer.setRegionName(GridRegion.BODY);
// use different style bits to avoid rendering of inactive scrollbars
// for small table when using percentage sizing, typically there should
// be no scrollbars, as the table should take the available space
// Note: The enabling/disabling and showing of the scrollbars is handled
// by the ViewportLayer. Without the ViewportLayer the scrollbars will
// always be visible with the default style bits of NatTable.
final NatTable n1 = new NatTable(simplePanel, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED, layer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(n1);
// example for fixed percentage sizing
// ensure that the sum of column sizes is not greater than 100
final DataLayer n2DataLayer = new DataLayer(dataProvider);
n2DataLayer.setColumnWidthPercentageByPosition(0, 25);
n2DataLayer.setColumnWidthPercentageByPosition(1, 25);
n2DataLayer.setColumnWidthPercentageByPosition(2, 50);
layer = new SelectionLayer(n2DataLayer);
layer.setRegionName(GridRegion.BODY);
// use different style bits to avoid rendering of inactive scrollbars
// for small table when using percentage sizing, typically there should
// be no scrollbars, as the table should take the available space
// Note: The enabling/disabling and showing of the scrollbars is handled
// by the ViewportLayer. Without the ViewportLayer the scrollbars will
// always be visible with the default style bits of NatTable.
final NatTable n2 = new NatTable(simplePanel, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED, layer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(n2);
// example for mixed percentage sizing
// configure not every column with the exact percentage value, this way
// the columns for which no exact values are set will use the remaining
// space
final DataLayer n3DataLayer = new DataLayer(dataProvider);
n3DataLayer.setColumnPercentageSizing(true);
n3DataLayer.setColumnWidthPercentageByPosition(0, 40);
n3DataLayer.setColumnWidthPercentageByPosition(2, 40);
layer = new SelectionLayer(n3DataLayer);
layer.setRegionName(GridRegion.BODY);
// use different style bits to avoid rendering of inactive scrollbars
// for small table when using percentage sizing, typically there should
// be no scrollbars, as the table should take the available space
// Note: The enabling/disabling and showing of the scrollbars is handled
// by the ViewportLayer. Without the ViewportLayer the scrollbars will
// always be visible with the default style bits of NatTable.
final NatTable n3 = new NatTable(simplePanel, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED, layer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(n3);
// example for mixed fixed/percentage sizing
// configure not every column with the exact percentage value, this way
// the columns for which no exact values are set will use the remaining
// space
final DataLayer mixDataLayer = new DataLayer(dataProvider);
mixDataLayer.setColumnPercentageSizing(true);
mixDataLayer.setColumnPercentageSizing(0, false);
mixDataLayer.setColumnPercentageSizing(1, false);
mixDataLayer.setColumnWidthByPosition(0, 100);
mixDataLayer.setColumnWidthByPosition(1, 100);
layer = new SelectionLayer(mixDataLayer);
layer.setRegionName(GridRegion.BODY);
// use different style bits to avoid rendering of inactive scrollbars
// for small table when using percentage sizing, typically there should
// be no scrollbars, as the table should take the available space
// Note: The enabling/disabling and showing of the scrollbars is handled
// by the ViewportLayer. Without the ViewportLayer the scrollbars will
// always be visible with the default style bits of NatTable.
final NatTable mix = new NatTable(simplePanel, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED, layer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(mix);
Button addColumnButton = new Button(buttonPanel, SWT.PUSH);
addColumnButton.setText("add column - no width");
addColumnButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
dataProvider.setColumnCount(dataProvider.getColumnCount() + 1);
n1.refresh();
n2.refresh();
n3.refresh();
mix.refresh();
}
});
Button addColumnButton2 = new Button(buttonPanel, SWT.PUSH);
addColumnButton2.setText("add column - 20 percent width");
addColumnButton2.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
dataProvider.setColumnCount(dataProvider.getColumnCount() + 1);
n1DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
n2DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
n3DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
mixDataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
n1.refresh();
n2.refresh();
n3.refresh();
mix.refresh();
}
});
return panel;
}
use of org.eclipse.nebula.widgets.nattable.layer.DataLayer in project nebula.widgets.nattable by eclipse.
the class _5063_GridBodyHoverStylingExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// 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);
HoverLayer hoverLayer = new HoverLayer(bodyDataLayer);
SelectionLayer selectionLayer = new SelectionLayer(hoverLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// build the column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer, false);
// add ColumnHeaderHoverLayerConfiguration to ensure that hover styling
// and resizing is working together
columnHeaderLayer.addConfiguration(new ColumnHeaderHoverLayerConfiguration(null));
// build the row header layer
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer, false);
// add RowHeaderHoverLayerConfiguration to ensure that hover styling and
// resizing is working together
rowHeaderLayer.addConfiguration(new RowHeaderHoverLayerConfiguration(null));
// 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(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
// turn the auto configuration off as we want to add our header menu
// configuration
NatTable natTable = new NatTable(parent, gridLayer, false);
// as the autoconfiguration of the NatTable is turned off, we have to
// add the DefaultNatTableStyleConfiguration manually
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
// add the style configuration for hover
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
Style style = new Style();
style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.COLOR_YELLOW);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.HOVER);
}
});
natTable.configure();
return natTable;
}
Aggregations