use of org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class TickUpdateCommandHandlerTest method registerCellStyleAccumulators.
private void registerCellStyleAccumulators(DataLayer bodyDataLayer) {
AggregateConfigLabelAccumulator aggregrateConfigLabelAccumulator = new AggregateConfigLabelAccumulator();
this.columnLabelAccumulator = new ColumnOverrideLabelAccumulator(new DataLayerFixture());
aggregrateConfigLabelAccumulator.add(this.columnLabelAccumulator, new AlternatingRowConfigLabelAccumulator());
bodyDataLayer.setConfigLabelAccumulator(aggregrateConfigLabelAccumulator);
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class _423_ThemeStylingExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
container.setLayout(new GridLayout());
// 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.
final ListDataProvider<Person> bodyDataProvider = new DefaultBodyDataProvider<>(PersonService.getPersons(10), propertyNames);
final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
HoverLayer bodyHoverLayer = new HoverLayer(bodyDataLayer);
SelectionLayer selectionLayer = new SelectionLayer(bodyHoverLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// add labels to provider conditional styling
AggregateConfigLabelAccumulator labelAccumulator = new AggregateConfigLabelAccumulator();
labelAccumulator.add(new ColumnLabelAccumulator());
labelAccumulator.add(new IConfigLabelAccumulator() {
@Override
public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
Person p = bodyDataProvider.getRowObject(rowPosition);
if (p != null) {
configLabels.addLabel(p.getGender().equals(Gender.FEMALE) ? FEMALE_LABEL : MALE_LABEL);
}
}
});
bodyDataLayer.setConfigLabelAccumulator(labelAccumulator);
// build the column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
final DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
HoverLayer columnHoverLayer = new HoverLayer(columnHeaderDataLayer, false);
final 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);
final CornerLayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnHeaderLayer);
// build the grid layer
final GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
final NatTable natTable = new NatTable(container, gridLayer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
// adding a full border
natTable.addOverlayPainter(new NatTableBorderOverlayPainter(natTable.getConfigRegistry()));
Composite buttonPanel = new Composite(container, SWT.NONE);
buttonPanel.setLayout(new GridLayout(3, true));
GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);
final ThemeConfiguration defaultTheme = new DefaultNatTableThemeConfiguration();
final ThemeConfiguration modernTheme = new ModernNatTableThemeConfiguration();
final ThemeConfiguration darkTheme = new DarkNatTableThemeConfiguration();
final ThemeConfiguration conditionalDefaultTheme = new DefaultNatTableThemeConfiguration();
conditionalDefaultTheme.addThemeExtension(new ConditionalStylingThemeExtension());
final ThemeConfiguration conditionalModernTheme = new ModernNatTableThemeConfiguration();
conditionalModernTheme.addThemeExtension(new ConditionalStylingThemeExtension());
final ThemeConfiguration conditionalDarkTheme = new DarkNatTableThemeConfiguration();
conditionalDarkTheme.addThemeExtension(new ConditionalStylingThemeExtension());
final ThemeConfiguration hoverTheme = new HoverThemeConfiguration();
final ThemeConfiguration fontTheme = new FontStylingThemeConfiguration();
Button defaultThemeButton = new Button(buttonPanel, SWT.PUSH);
defaultThemeButton.setText("NatTable Default Theme");
defaultThemeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.setTheme(defaultTheme);
// reset to default state
cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
}
});
Button modernThemeButton = new Button(buttonPanel, SWT.PUSH);
modernThemeButton.setText("NatTable Modern Theme");
modernThemeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.setTheme(modernTheme);
// reset to default state
cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
}
});
Button darkThemeButton = new Button(buttonPanel, SWT.PUSH);
darkThemeButton.setText("NatTable Dark Theme");
darkThemeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.setTheme(darkTheme);
// reset to default state
cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
}
});
Button conditionalThemeButton = new Button(buttonPanel, SWT.PUSH);
conditionalThemeButton.setText("Conditional Default Theme");
conditionalThemeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.setTheme(conditionalDefaultTheme);
// reset to default state
cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
}
});
Button conditionalModernThemeButton = new Button(buttonPanel, SWT.PUSH);
conditionalModernThemeButton.setText("Conditional Modern Theme");
conditionalModernThemeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.setTheme(conditionalModernTheme);
// reset to default state
cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
}
});
Button conditionalDarkThemeButton = new Button(buttonPanel, SWT.PUSH);
conditionalDarkThemeButton.setText("Conditional Dark Theme");
conditionalDarkThemeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.setTheme(conditionalDarkTheme);
// reset to default state
cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
}
});
Button hoverThemeButton = new Button(buttonPanel, SWT.PUSH);
hoverThemeButton.setText("Hover Theme");
hoverThemeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.setTheme(hoverTheme);
// reset to default state
cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
}
});
Button fontThemeButton = new Button(buttonPanel, SWT.PUSH);
fontThemeButton.setText("Increased Font Theme");
fontThemeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.setTheme(fontTheme);
// we are simply increasing the default width and height in this
// example we could also register TextPainters that calculate
// their height by content but they are not able to shrink again
columnHeaderDataLayer.setDefaultRowHeight(30);
columnHeaderDataLayer.setDefaultColumnWidth(130);
bodyDataLayer.setDefaultRowHeight(30);
bodyDataLayer.setDefaultColumnWidth(130);
}
});
return container;
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator 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.AggregateConfigLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class GroupByDataLayerTest method addConditionalStyling.
void addConditionalStyling() {
IConfigLabelAccumulator conditional = new IConfigLabelAccumulator() {
@Override
public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
if (columnPosition == 2 && configLabels.hasLabel(GroupByDataLayer.GROUP_BY_OBJECT)) {
Double value = (Double) GroupByDataLayerTest.this.dataLayer.getDataValueByPosition(columnPosition, rowPosition, configLabels, false);
if (value > 800d) {
configLabels.addLabelOnTop(MY_LABEL);
}
}
}
};
AggregateConfigLabelAccumulator aggregate = new AggregateConfigLabelAccumulator();
aggregate.add(new ColumnLabelAccumulator());
aggregate.add(conditional);
this.dataLayer.setConfigLabelAccumulator(aggregate);
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class BodyLayerStack method setupAggregateLabelAccumulator.
private void setupAggregateLabelAccumulator() {
aggregateLabelAccumulator = new AggregateConfigLabelAccumulator();
getDataLayer().setConfigLabelAccumulator(aggregateLabelAccumulator);
}
Aggregations