use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class Rendering_cells_as_a_link_and_button method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
this.gridLayer = new SelectionExampleGridLayer();
NatTable natTable = new NatTable(parent, this.gridLayer, false);
IConfigRegistry configRegistry = new ConfigRegistry();
DataLayer bodyDataLayer = this.gridLayer.getBodyDataLayer();
// Step 1: Create a label accumulator - adds custom labels to all cells
// which we wish to render differently. In this case render as a button.
ColumnOverrideLabelAccumulator cellLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
cellLabelAccumulator.registerColumnOverrides(0, LINK_CELL_LABEL);
cellLabelAccumulator.registerColumnOverrides(2, BUTTON_CELL_LABEL);
// Step 2: Register label accumulator
bodyDataLayer.setConfigLabelAccumulator(cellLabelAccumulator);
// Step 3: Register your custom cell style and , against the
// label applied to the link cell.
LinkClickConfiguration<RowDataFixture> linkClickConfiguration = new LinkClickConfiguration<>();
addLinkToColumn(configRegistry, natTable.getDisplay().getSystemColor(SWT.COLOR_BLUE), linkClickConfiguration);
natTable.addConfiguration(linkClickConfiguration);
// Step 4: Register your custom cell painter, cell style, against the
// label applied to the button cell.
addButtonToColumn(configRegistry);
natTable.addConfiguration(new ButtonClickConfiguration<RowDataFixture>(this.buttonPainter));
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new DebugMenuConfiguration(natTable));
natTable.setConfigRegistry(configRegistry);
natTable.configure();
// Layout SWT widgets. Not relevant to example code.
parent.setLayout(new GridLayout(1, true));
natTable.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
setupTextArea(parent);
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class _000_Styled_grid method setup.
private NatTable setup(Composite parent) {
DummyGridLayerStack gridLayer = new DummyGridLayerStack();
final NatTable natTable = new NatTable(parent, gridLayer, false);
DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
// Add an AggregateConfigLabelAccumulator - we can add other
// accumulators to this as required
AggregateConfigLabelAccumulator aggregrateConfigLabelAccumulator = new AggregateConfigLabelAccumulator();
bodyDataLayer.setConfigLabelAccumulator(aggregrateConfigLabelAccumulator);
ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
ColumnOverrideLabelAccumulator bodyLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
aggregrateConfigLabelAccumulator.add(columnLabelAccumulator);
aggregrateConfigLabelAccumulator.add(bodyLabelAccumulator);
// Add a label for the highlighted column
// We will add a style for this label to the config registry in a bit
bodyLabelAccumulator.registerColumnOverrides(2, BODY_LABEL_1);
columnLabelAccumulator.registerColumnOverrides(2, COLUMN_LABEL_1);
// Register a command handler for the StyleEditorDialog
DisplayColumnStyleEditorCommandHandler styleChooserCommandHandler = new DisplayColumnStyleEditorCommandHandler(gridLayer.getBodyLayer().getSelectionLayer(), columnLabelAccumulator, natTable.getConfigRegistry());
DefaultBodyLayerStack bodyLayer = gridLayer.getBodyLayer();
bodyLayer.registerCommandHandler(styleChooserCommandHandler);
// Register the style editor as persistable
// This will persist the style applied to the columns when
// NatTable#saveState is invoked
bodyLayer.registerPersistable(styleChooserCommandHandler);
bodyLayer.registerPersistable(columnLabelAccumulator);
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class _774_MultiExportExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
Composite panel = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
panel.setLayout(layout);
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 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");
GridLayer grid = createGrid(propertyNames, propertyToLabelMap, PersonService.getPersons(5));
final NatTable natTable = new NatTable(gridPanel, grid, false);
// add labels to show that alignment configurations are also exported
// correctly
final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(grid.getBodyLayer());
((AbstractLayer) grid.getBodyLayer()).setConfigLabelAccumulator(columnLabelAccumulator);
columnLabelAccumulator.registerColumnOverrides(0, COLUMN_ONE_LABEL);
columnLabelAccumulator.registerColumnOverrides(1, COLUMN_TWO_LABEL);
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
Style style = new Style();
style.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, HorizontalAlignmentEnum.LEFT);
style.setAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT, VerticalAlignmentEnum.TOP);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, COLUMN_ONE_LABEL);
style = new Style();
style.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, HorizontalAlignmentEnum.RIGHT);
style.setAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT, VerticalAlignmentEnum.BOTTOM);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, COLUMN_TWO_LABEL);
}
});
// adding this configuration adds the styles and the painters to use
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(ExportConfigAttributes.EXPORTER, new HSSFExcelExporter());
configRegistry.registerConfigAttribute(ExportConfigAttributes.DATE_FORMAT, "dd.MM.yyyy");
// register a custom formatter to the body of the grid
// you could also implement different formatter for different
// columns by using the label mechanism
configRegistry.registerConfigAttribute(ExportConfigAttributes.EXPORT_FORMATTER, new ExampleExportFormatter(), DisplayMode.NORMAL, GridRegion.BODY);
configRegistry.registerConfigAttribute(ExportConfigAttributes.EXPORT_FORMATTER, new IExportFormatter() {
@Override
public Object formatForExport(ILayerCell cell, IConfigRegistry configRegistry) {
// string for export
return cell.getDataValue();
}
}, DisplayMode.NORMAL, GridRegion.ROW_HEADER);
}
});
natTable.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
// property names of the NumberValues class
String[] numberPropertyNames = { "columnOneNumber", "columnTwoNumber", "columnThreeNumber", "columnFourNumber", "columnFiveNumber" };
// mapping from property to label, needed for column header labels
Map<String, String> numberPropertyToLabelMap = new HashMap<>();
numberPropertyToLabelMap.put("columnOneNumber", "Value One");
numberPropertyToLabelMap.put("columnTwoNumber", "Value Two");
numberPropertyToLabelMap.put("columnThreeNumber", "Value Three");
numberPropertyToLabelMap.put("columnFourNumber", "Value Four");
numberPropertyToLabelMap.put("columnFiveNumber", "Value Five");
List<NumberValues> valuesToShow = new ArrayList<>();
valuesToShow.add(createNumberValues());
valuesToShow.add(createNumberValues());
valuesToShow.add(createNumberValues());
valuesToShow.add(createNumberValues());
valuesToShow.add(createNumberValues());
final NatTable numberNatTable = new NatTable(gridPanel, createGrid(numberPropertyNames, numberPropertyToLabelMap, valuesToShow), false);
// adding this configuration adds the styles and the painters to use
numberNatTable.addConfiguration(new DefaultNatTableStyleConfiguration());
numberNatTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
// register a custom formatter to the body of the grid
// you could also implement different formatter for different
// columns by using the label mechanism
configRegistry.registerConfigAttribute(ExportConfigAttributes.EXPORT_FORMATTER, new IExportFormatter() {
@Override
public Object formatForExport(ILayerCell cell, IConfigRegistry configRegistry) {
// default conversion to string for export
return cell.getDataValue();
}
}, DisplayMode.NORMAL, GridRegion.BODY);
configRegistry.registerConfigAttribute(ExportConfigAttributes.EXPORT_FORMATTER, new IExportFormatter() {
@Override
public Object formatForExport(ILayerCell cell, IConfigRegistry configRegistry) {
// default conversion to string for export
return cell.getDataValue();
}
}, DisplayMode.NORMAL, GridRegion.ROW_HEADER);
}
});
numberNatTable.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(numberNatTable);
Button addColumnButton = new Button(buttonPanel, SWT.PUSH);
addColumnButton.setText("Export");
addColumnButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// get the ILayerExporter that is registered for the persons
// table, otherwise the exporter registered there would have no
// effect. For multi table export the ILayerExporter specified
// in the method call is used always
ILayerExporter exporter = natTable.getConfigRegistry().getConfigAttribute(ExportConfigAttributes.EXPORTER, DisplayMode.NORMAL);
Map<String, NatTable> export = new HashMap<>();
export.put("Persons", natTable);
export.put("Numbers", numberNatTable);
new NatExporter(Display.getCurrent().getActiveShell()).exportMultipleNatTables(exporter, export);
}
});
return panel;
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class _804_GlazedListsEditorExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "password", "description", "age", "money", "married", "gender", "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("address.street", "Street");
propertyToLabelMap.put("address.city", "City");
propertyToLabelMap.put("favouriteFood", "Food");
propertyToLabelMap.put("favouriteDrinks", "Drinks");
propertyToLabelMap.put("filename", "Filename");
ConfigRegistry configRegistry = new ConfigRegistry();
GlazedListsGridEditorGridLayer<ExtendedPersonWithAddress> gridLayer = new GlazedListsGridEditorGridLayer<>(PersonService.getExtendedPersonsWithAddress(10), configRegistry, propertyNames, propertyToLabelMap);
final DataLayer bodyDataLayer = gridLayer.getBodyDataLayer();
final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
registerColumnLabels(columnLabelAccumulator);
final NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new EditorConfiguration());
natTable.addConfiguration(new SingleClickSortConfiguration());
natTable.configure();
new NatTableContentTooltip(natTable, GridRegion.BODY);
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class NatTableBuilder method configureColumnProperties.
protected void configureColumnProperties() {
columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyLayer.getDataLayer());
bodyLayer.addLabelAccumulator(columnLabelAccumulator);
for (int colIndex = 0; colIndex < columns.length; colIndex++) {
Integer width = columns[colIndex].width;
if (isNotNull(width)) {
bodyLayer.getDataLayer().setColumnWidthByPosition(colIndex, width);
}
// Register a label on each column
String columnLabel = BODY_COLUMN_LABEL_PREFIX + colIndex;
columnLabelAccumulator.registerColumnOverrides(colIndex, columnLabel);
// Add the display converter/formatter to the column
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, columns[colIndex].displayConverter, DisplayMode.NORMAL, columnLabel);
// Add column visual style
Style style = new Style();
ColumnStyle columnStyle = columns[colIndex].style;
if (ObjectUtils.isNotNull(columnStyle)) {
style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, columnStyle.bgColor);
style.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, columnStyle.fgColor);
style.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, columnStyle.hAlign);
style.setAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT, columnStyle.vAlign);
style.setAttributeValue(CellStyleAttributes.FONT, columnStyle.font);
style.setAttributeValue(CellStyleAttributes.BORDER_STYLE, columnStyle.borderStyle);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, columnLabel);
}
}
}
Aggregations