use of org.eclipse.nebula.widgets.nattable.layer.LabelStack in project nebula.widgets.nattable by eclipse.
the class _001_Custom_styling_of_specific_cells method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
List<SimplePerson> myList = new ArrayList<>();
for (int i = 1; i <= 100; i++) {
myList.add(new SimplePerson(i, "Joe" + i, new Date()));
}
String[] propertyNames = { "id", "name", "birthDate" };
IColumnPropertyAccessor<SimplePerson> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
ListDataProvider<SimplePerson> listDataProvider = new ListDataProvider<>(myList, columnPropertyAccessor);
DefaultGridLayer gridLayer = new DefaultGridLayer(listDataProvider, new DummyColumnHeaderDataProvider(listDataProvider));
final DefaultBodyLayerStack bodyLayer = gridLayer.getBodyLayer();
// Custom label "FOO" for cell at column, row index (1, 5)
IConfigLabelAccumulator cellLabelAccumulator = new IConfigLabelAccumulator() {
@Override
public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
int columnIndex = bodyLayer.getColumnIndexByPosition(columnPosition);
int rowIndex = bodyLayer.getRowIndexByPosition(rowPosition);
if (columnIndex == 1 && rowIndex == 5) {
configLabels.addLabel(FOO_LABEL);
}
if (columnIndex == 1 && rowIndex == 10) {
configLabels.addLabel(BAR_LABEL);
}
// add labels for surrounding borders
if (rowIndex == 13) {
configLabels.addLabel(CustomLineBorderDecorator.TOP_LINE_BORDER_LABEL);
configLabels.addLabel(CustomLineBorderDecorator.BOTTOM_LINE_BORDER_LABEL);
if (columnIndex == 0) {
configLabels.addLabel(CustomLineBorderDecorator.LEFT_LINE_BORDER_LABEL);
}
if (columnIndex == 2) {
configLabels.addLabel(CustomLineBorderDecorator.RIGHT_LINE_BORDER_LABEL);
}
}
}
};
bodyLayer.setConfigLabelAccumulator(cellLabelAccumulator);
NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {
{
// override the LineBorderDecorator here to show how to paint
// borders on single sides of a cell
this.cellPainter = new CustomLineBorderDecorator(new TextPainter());
// set a border style
this.borderStyle = new BorderStyle(2, GUIHelper.COLOR_BLUE, LineStyleEnum.DASHDOT);
}
});
// Custom style for label "FOO"
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
Style cellStyle = new Style();
cellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.COLOR_GREEN);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, FOO_LABEL);
cellStyle = new Style();
cellStyle.setAttributeValue(CellStyleAttributes.TEXT_DECORATION, TextDecorationEnum.UNDERLINE_STRIKETHROUGH);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, BAR_LABEL);
}
});
natTable.configure();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.layer.LabelStack in project nebula.widgets.nattable by eclipse.
the class _6045_HierarchicalTreeLayerExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
container.setLayout(new GridLayout());
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("manufacturer", "Manufacturer");
propertyToLabelMap.put("model", "Model");
propertyToLabelMap.put("motors.identifier", "Identifier");
propertyToLabelMap.put("motors.capacity", "Capacity");
propertyToLabelMap.put("motors.capacityUnit", "Capacity Unit");
propertyToLabelMap.put("motors.maximumSpeed", "Maximum Speed");
propertyToLabelMap.put("motors.feedbacks.creationTime", "Creation Time");
propertyToLabelMap.put("motors.feedbacks.classification", "Classification");
propertyToLabelMap.put("motors.feedbacks.comment", "Comment");
ConfigRegistry configRegistry = new ConfigRegistry();
BodyLayerStack bodyLayerStack = new BodyLayerStack(CarService.getInput(), CarService.PROPERTY_NAMES);
// create the column header layer stack
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(CarService.PROPERTY_NAMES, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
// add the SortHeaderLayer to the column header layer stack
final SortHeaderLayer<HierarchicalWrapper> sortHeaderLayer = new SortHeaderLayer<>(columnHeaderLayer, new HierarchicalWrapperSortModel(bodyLayerStack.getSortedList(), bodyLayerStack.getColumnPropertyAccessor(), bodyLayerStack.getTreeLayer().getLevelIndexMapping(), columnHeaderDataLayer, configRegistry), false);
// add the filter row functionality
final FilterRowHeaderComposite<HierarchicalWrapper> filterRowHeaderLayer = new FilterRowHeaderComposite<>(new DefaultGlazedListsFilterStrategy<>(bodyLayerStack.getFilterList(), bodyLayerStack.getColumnPropertyAccessor(), configRegistry), sortHeaderLayer, columnHeaderDataLayer.getDataProvider(), configRegistry);
filterRowHeaderLayer.addConfigLabelAccumulatorForRegion(GridRegion.FILTER_ROW, new IConfigLabelAccumulator() {
@Override
public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
int columnIndex = filterRowHeaderLayer.getColumnIndexByPosition(columnPosition);
// header column
if (columnIndex < 0) {
configLabels.addLabelOnTop(HierarchicalTreeLayer.LEVEL_HEADER_CELL);
}
}
});
// create the composite layer composed with the prior created layer
// stacks
CompositeLayer compositeLayer = new CompositeLayer(1, 2);
compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, filterRowHeaderLayer, 0, 0);
compositeLayer.setChildLayer(GridRegion.BODY, bodyLayerStack, 0, 1);
compositeLayer.addConfiguration(new DefaultGridLayerConfiguration(compositeLayer) {
@Override
protected void addAlternateRowColoringConfig(CompositeLayer gridLayer) {
// do nothing to avoid the default grid alternate row coloring
// needed because the alternate row coloring in the hierarchical
// tree
// is based on the spanned cells and not per individual row
// position
}
});
NatTable natTable = new NatTable(container, compositeLayer, false);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {
{
this.vAlign = VerticalAlignmentEnum.TOP;
this.hAlign = HorizontalAlignmentEnum.LEFT;
this.cellPainter = new PaddingDecorator(new TextPainter(), 2);
}
});
// add editing configuration
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
// make identifier editable
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, EditableRule.ALWAYS_EDITABLE, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 2);
// make capacity unit editable
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, EditableRule.ALWAYS_EDITABLE, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new ComboBoxCellEditor("KW", "PS"), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new PaddingDecorator(new ComboBoxPainter(), 2), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
// make comment editable
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, EditableRule.ALWAYS_EDITABLE, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 8);
}
});
// adds the key bindings that allows pressing space bar to
// expand/collapse tree nodes
natTable.addConfiguration(new TreeLayerExpandCollapseKeyBindings(bodyLayerStack.getTreeLayer(), bodyLayerStack.getSelectionLayer()));
// add sorting configuration
natTable.addConfiguration(new SingleClickSortConfiguration());
// add some additional filter configuration
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
Style style = new Style();
style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.getColor(173, 216, 230));
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, GridRegion.FILTER_ROW);
}
});
natTable.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
Composite buttonPanel = new Composite(container, SWT.NONE);
buttonPanel.setLayout(new RowLayout());
GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);
Button collapseAllButton = new Button(buttonPanel, SWT.PUSH);
collapseAllButton.setText("Collapse All");
collapseAllButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new TreeCollapseAllCommand());
}
});
Button expandAllButton = new Button(buttonPanel, SWT.PUSH);
expandAllButton.setText("Expand All");
expandAllButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new TreeExpandAllCommand());
}
});
Button expandAllFirstLevelButton = new Button(buttonPanel, SWT.PUSH);
expandAllFirstLevelButton.setText("Expand All First Level");
expandAllFirstLevelButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new TreeExpandToLevelCommand(0));
}
});
Button toggleExpandButton = new Button(buttonPanel, SWT.PUSH);
toggleExpandButton.setText("Enable Advanced Expand");
toggleExpandButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
_6045_HierarchicalTreeLayerExample.this.advancedExpandEnabled = !_6045_HierarchicalTreeLayerExample.this.advancedExpandEnabled;
if (_6045_HierarchicalTreeLayerExample.this.advancedExpandEnabled) {
toggleExpandButton.setText("Disable Advanced Expand");
// configure advanced action
natTable.getUiBindingRegistry().registerFirstSingleClickBinding(_6045_HierarchicalTreeLayerExample.this.treeImagePainterMouseEventMatcher, _6045_HierarchicalTreeLayerExample.this.advancedTreeExpandCollapseAction);
} else {
toggleExpandButton.setText("Enable Advanced Expand");
// configure simple action
natTable.getUiBindingRegistry().registerFirstSingleClickBinding(_6045_HierarchicalTreeLayerExample.this.treeImagePainterMouseEventMatcher, _6045_HierarchicalTreeLayerExample.this.simpleTreeExpandCollapseAction);
}
}
});
Button multiReorderButton = new Button(buttonPanel, SWT.PUSH);
multiReorderButton.setText("Reorder Second Level");
multiReorderButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
List<Integer> fromColumnPositions = Arrays.asList(4, 5);
natTable.doCommand(new MultiColumnReorderCommand(natTable, fromColumnPositions, 8));
}
});
Button deleteButton = new Button(buttonPanel, SWT.PUSH);
deleteButton.setText("Delete Row 4");
deleteButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// remove the element
HierarchicalWrapper rowObject = bodyLayerStack.getFilterList().remove(3);
// fire the event to refresh
bodyLayerStack.getBodyDataLayer().fireLayerEvent(new RowDeleteEvent(bodyLayerStack.getBodyDataLayer(), 3));
bodyLayerStack.getTreeLayer().cleanupRetainedCollapsedNodes(rowObject);
}
});
return container;
}
use of org.eclipse.nebula.widgets.nattable.layer.LabelStack in project nebula.widgets.nattable by eclipse.
the class GroupByDataLayerTest method testOneLevelGroupSortSummary.
@Test
public void testOneLevelGroupSortSummary() {
addSortingCapability();
addSummaryConfiguration();
// increase the money amount for all flanders to show that the sort
// order is related to the summary value and not the groupBy value
double value = 600.0d;
for (int i = 10; i < this.sortedList.size(); i++) {
if ((i - 10) % 2 == 0) {
value -= 100.0d;
}
this.sortedList.get(i).setMoney(value);
}
// groupBy lastname
this.groupByModel.addGroupByColumnIndex(1);
// 18 data rows + 2 GroupBy rows
assertEquals(20, this.dataLayer.getRowCount());
Object o = this.dataLayer.getTreeList().get(0);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Flanders", ((GroupByObject) o).getValue());
LabelStack labelStack = this.dataLayer.getConfigLabelsByPosition(2, 0);
assertEquals(2800.0d, this.dataLayer.getDataValueByPosition(2, 0, labelStack, false));
o = this.dataLayer.getTreeList().get(1);
assertTrue("Object is not a Person", o instanceof Person);
assertEquals("Ned", ((Person) o).getFirstName());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, 1);
assertEquals(500.0d, this.dataLayer.getDataValueByPosition(2, 1, labelStack, false));
o = this.dataLayer.getTreeList().get(9);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Simpson", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, 9);
assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, 9, labelStack, false));
// sort ascending by money
this.sortModel.sort(2, SortDirectionEnum.ASC, false);
o = this.dataLayer.getTreeList().get(0);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Simpson", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, 0);
assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, 0, labelStack, false));
o = this.dataLayer.getTreeList().get(11);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Flanders", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, 11);
assertEquals(2800.0d, this.dataLayer.getDataValueByPosition(2, 11, labelStack, false));
o = this.dataLayer.getTreeList().get(12);
assertTrue("Object is not a Person", o instanceof Person);
assertEquals("Todd", ((Person) o).getFirstName());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, 1);
assertEquals(100.0d, this.dataLayer.getDataValueByPosition(2, 1, labelStack, false));
// sort descending by money
this.sortModel.sort(2, SortDirectionEnum.DESC, false);
o = this.dataLayer.getTreeList().get(0);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Flanders", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, 0);
assertEquals(2800.0d, this.dataLayer.getDataValueByPosition(2, 0, labelStack, false));
o = this.dataLayer.getTreeList().get(9);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Simpson", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, 9);
assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, 9, labelStack, false));
o = this.dataLayer.getTreeList().get(1);
assertTrue("Object is not a Person", o instanceof Person);
assertEquals("Ned", ((Person) o).getFirstName());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, 1);
assertEquals(500.0d, this.dataLayer.getDataValueByPosition(2, 1, labelStack, false));
}
use of org.eclipse.nebula.widgets.nattable.layer.LabelStack in project nebula.widgets.nattable by eclipse.
the class GroupByDataLayerTest method testConfigLabelsWithoutGrouping.
@Test
public void testConfigLabelsWithoutGrouping() {
// there should be never a groupBy label or groupBySummary label
for (int row = 0; row < this.dataLayer.getRowCount(); row++) {
for (int column = 0; column < this.dataLayer.getColumnCount(); column++) {
LabelStack stack = this.dataLayer.getConfigLabelsByPosition(column, row);
assertTrue("column label not found", stack.hasLabel(ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + column));
assertFalse("groupBy object label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_OBJECT));
assertFalse("groupBy column label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + column));
assertFalse("groupBy summary label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_SUMMARY));
assertFalse("groupBy summary column label found", stack.hasLabel(GroupByDataLayer.GROUP_BY_SUMMARY_COLUMN_PREFIX + column));
}
}
}
use of org.eclipse.nebula.widgets.nattable.layer.LabelStack 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);
}
Aggregations