use of org.eclipse.nebula.widgets.nattable.NatTable 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.NatTable 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.NatTable 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;
}
use of org.eclipse.nebula.widgets.nattable.NatTable in project nebula.widgets.nattable by eclipse.
the class _5064_GridHeaderHoverStylingExample 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);
SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// build the column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
HoverLayer columnHoverLayer = new HoverLayer(columnHeaderDataLayer, false);
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHoverLayer, viewportLayer, selectionLayer, false);
// add ColumnHeaderHoverLayerConfiguration to ensure that hover styling
// and resizing is working together
columnHeaderLayer.addConfiguration(new ColumnHeaderHoverLayerConfiguration(columnHoverLayer));
// build the row header layer
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
HoverLayer rowHoverLayer = new HoverLayer(rowHeaderDataLayer, false);
RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(rowHoverLayer, viewportLayer, selectionLayer, false);
// add RowHeaderHoverLayerConfiguration to ensure that hover styling and
// resizing is working together
rowHeaderLayer.addConfiguration(new RowHeaderHoverLayerConfiguration(rowHoverLayer));
// 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());
natTable.addConfiguration(new AbstractUiBindingConfiguration() {
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerMouseMoveBinding(new MouseEventMatcher(GridRegion.BODY), new ClearHoverStylingAction());
}
});
// 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_RED);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.HOVER, GridRegion.ROW_HEADER);
Image bgImage = GUIHelper.getImageByURL("columnHeaderBg", getClass().getResource("/org/eclipse/nebula/widgets/nattable/examples/resources/column_header_bg.png"));
Image hoverBgImage = GUIHelper.getImageByURL("hoverColumnHeaderBg", getClass().getResource("/org/eclipse/nebula/widgets/nattable/examples/resources/hovered_column_header_bg.png"));
Image selectedBgImage = GUIHelper.getImageByURL("selectedColumnHeaderBg", getClass().getResource("/org/eclipse/nebula/widgets/nattable/examples/resources/selected_column_header_bg.png"));
TextPainter txtPainter = new TextPainter(false, false);
ICellPainter bgImagePainter = new BackgroundImagePainter(txtPainter, bgImage, GUIHelper.getColor(192, 192, 192));
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, bgImagePainter, DisplayMode.NORMAL, GridRegion.COLUMN_HEADER);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, bgImagePainter, DisplayMode.NORMAL, GridRegion.CORNER);
ICellPainter hoveredHeaderPainter = new BackgroundImagePainter(txtPainter, hoverBgImage, GUIHelper.getColor(192, 192, 192));
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, hoveredHeaderPainter, DisplayMode.HOVER, GridRegion.COLUMN_HEADER);
ICellPainter selectedHeaderPainter = new BackgroundImagePainter(txtPainter, selectedBgImage, GUIHelper.getColor(192, 192, 192));
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, selectedHeaderPainter, DisplayMode.SELECT, GridRegion.COLUMN_HEADER);
}
});
natTable.configure();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.NatTable in project nebula.widgets.nattable by eclipse.
the class _5071_ColumnHideShowExample 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);
ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(bodyDataLayer);
SelectionLayer selectionLayer = new SelectionLayer(columnHideShowLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// build the column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
// build the row header layer
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, 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(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 header menu configuration for adding the column header menu
// with hide/show actions
natTable.addConfiguration(new AbstractHeaderMenuConfiguration(natTable) {
@Override
protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
return super.createColumnHeaderMenu(natTable).withHideColumnMenuItem().withShowAllColumnsMenuItem();
}
@Override
protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
return super.createCornerMenu(natTable).withShowAllColumnsMenuItem();
}
});
natTable.configure();
return natTable;
}
Aggregations