use of org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration in project nebula.widgets.nattable by eclipse.
the class _773_GridExcelExportFormatterExample 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(layout);
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");
// 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);
bodyDataLayer.setConfigLabelAccumulator(new ColumnLabelAccumulator());
// 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);
final NatTable natTable = new NatTable(gridPanel, gridLayer, false);
// 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) {
PoiExcelExporter exporter = new HSSFExcelExporter();
exporter.setApplyVerticalTextConfiguration(true);
exporter.setApplyBackgroundColor(false);
configRegistry.registerConfigAttribute(ExportConfigAttributes.EXPORTER, exporter);
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) {
// the default conversion to string for export
return cell.getDataValue();
}
}, DisplayMode.NORMAL, GridRegion.ROW_HEADER);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new BeveledBorderDecorator(new VerticalTextPainter(false, true, true)), DisplayMode.NORMAL, GridRegion.COLUMN_HEADER);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CheckBoxPainter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
}
});
gridLayer.addConfiguration(new DefaultImageExportBindings());
natTable.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
Button addColumnButton = new Button(buttonPanel, SWT.PUSH);
addColumnButton.setText("Export");
addColumnButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new ExportCommand(natTable.getConfigRegistry(), natTable.getShell()));
}
});
return panel;
}
use of org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration 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.config.DefaultNatTableStyleConfiguration in project nebula.widgets.nattable by eclipse.
the class TextPainter_Examples method createNatTable3.
@SuppressWarnings("unused")
private void createNatTable3(Composite parent, final ICellPainter painter) {
IDataProvider bodyDataProvider = new ExampleHeaderDataProvider();
DataLayer dataLayer = new DataLayer(bodyDataProvider);
SelectionLayer selectionLayer = new SelectionLayer(dataLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(new DummyColumnHeaderDataProvider(bodyDataProvider)), viewportLayer, selectionLayer);
CompositeLayer compositeLayer = new CompositeLayer(1, 2);
compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, columnHeaderLayer, 0, 0);
compositeLayer.setChildLayer(GridRegion.BODY, viewportLayer, 0, 1);
NatTable natTable = new NatTable(parent, compositeLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {
{
this.vAlign = VerticalAlignmentEnum.TOP;
this.hAlign = HorizontalAlignmentEnum.LEFT;
this.cellPainter = new LineBorderDecorator(painter);
this.font = GUIHelper.getFont(new FontData("Arial", 20, SWT.NORMAL));
}
});
natTable.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
}
use of org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration in project nebula.widgets.nattable by eclipse.
the class TextPainter_Examples method createNatTable.
private void createNatTable(Composite parent, final ICellPainter painter) {
IDataProvider bodyDataProvider = new ExampleTextBodyDataProvider();
DataLayer dataLayer = new DataLayer(bodyDataProvider);
dataLayer.setRowHeightByPosition(0, 32);
SelectionLayer selectionLayer = new SelectionLayer(dataLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(new DummyColumnHeaderDataProvider(bodyDataProvider)), viewportLayer, selectionLayer);
CompositeLayer compositeLayer = new CompositeLayer(1, 2);
compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, columnHeaderLayer, 0, 0);
compositeLayer.setChildLayer(GridRegion.BODY, viewportLayer, 0, 1);
NatTable natTable = new NatTable(parent, compositeLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {
{
this.vAlign = VerticalAlignmentEnum.TOP;
this.hAlign = HorizontalAlignmentEnum.LEFT;
this.cellPainter = new LineBorderDecorator(painter);
}
});
natTable.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
}
use of org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration in project nebula.widgets.nattable by eclipse.
the class TextPainter_Examples method createVerticalNatTable.
@SuppressWarnings("unused")
private void createVerticalNatTable(Composite parent, final ICellPainter painter) {
IDataProvider bodyDataProvider = new ExampleHeaderDataProvider();
SelectionLayer selectionLayer = new SelectionLayer(new DataLayer(bodyDataProvider, 20, 100));
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(new DummyColumnHeaderDataProvider(bodyDataProvider), 20, 100), viewportLayer, selectionLayer);
columnHeaderLayer.addConfiguration(new DefaultColumnHeaderLayerConfiguration() {
@Override
protected void addColumnHeaderStyleConfig() {
addConfiguration(new DefaultColumnHeaderStyleConfiguration() {
{
this.cellPainter = new BeveledBorderDecorator(new VerticalTextPainter());
}
});
}
});
CompositeLayer compositeLayer = new CompositeLayer(1, 2);
compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, columnHeaderLayer, 0, 0);
compositeLayer.setChildLayer(GridRegion.BODY, viewportLayer, 0, 1);
NatTable natTable = new NatTable(parent, compositeLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {
{
this.vAlign = VerticalAlignmentEnum.MIDDLE;
this.hAlign = HorizontalAlignmentEnum.LEFT;
this.cellPainter = new LineBorderDecorator(painter);
this.font = GUIHelper.getFont(new FontData("Arial", 20, SWT.NORMAL));
}
});
natTable.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
}
Aggregations