use of org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class ColumnHeaderLayerStack method setupAggregateLabelAccumulator.
private void setupAggregateLabelAccumulator() {
aggregateLabelAccumulator = new AggregateConfigLabelAccumulator();
getDataLayer().setConfigLabelAccumulator(aggregateLabelAccumulator);
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class ColumnReorderLayerTest method registerCellStyleAccumulators.
private void registerCellStyleAccumulators(DataLayer bodyDataLayer, ColumnOverrideLabelAccumulator columnLabelAccumulator) {
AggregateConfigLabelAccumulator aggregrateConfigLabelAccumulator = new AggregateConfigLabelAccumulator();
aggregrateConfigLabelAccumulator.add(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 EditTraversalStrategyUpDownTest method setUp.
@Before
public void setUp() {
// only use 10 columns to make the test cases easier
String[] propertyNames = Arrays.copyOfRange(RowDataListFixture.getPropertyNames(), 0, 10);
IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<>(RowDataListFixture.getList(10), new ReflectiveColumnPropertyAccessor<RowDataFixture>(propertyNames));
this.dataLayer = new DataLayer(bodyDataProvider, 20, 20);
this.selectionLayer = new SelectionLayer(this.dataLayer);
this.viewportLayer = new ViewportLayer(this.selectionLayer);
this.viewportLayer.setRegionName(GridRegion.BODY);
this.viewportLayer.addConfiguration(new DefaultEditBindings());
this.viewportLayer.addConfiguration(new DefaultEditConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new TextCellEditor(true, true));
configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, new DefaultDataValidator());
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 9);
}
});
this.natTable = new NatTableFixture(this.viewportLayer);
this.natTable.enableEditingOnAllCells();
this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE, DisplayMode.EDIT, NOT_EDITABLE);
this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.OPEN_ADJACENT_EDITOR, Boolean.TRUE);
// register non editable rows
this.overrider = new RowOverrideLabelAccumulator<>(bodyDataProvider, new IRowIdAccessor<RowDataFixture>() {
@Override
public Serializable getRowId(RowDataFixture rowObject) {
return rowObject.getSecurity_id();
}
});
this.overrider.registerRowOverrides(2, NOT_EDITABLE);
this.overrider.registerRowOverrides(5, NOT_EDITABLE);
this.overrider.registerRowOverrides(6, NOT_EDITABLE);
this.overrider.registerRowOverrides(7, NOT_EDITABLE);
this.overrider.registerRowOverrides(8, NOT_EDITABLE);
this.overrider.registerRowOverrides(9, NOT_EDITABLE);
AggregateConfigLabelAccumulator accumulator = new AggregateConfigLabelAccumulator();
accumulator.add(this.overrider);
accumulator.add(new ColumnLabelAccumulator());
this.dataLayer.setConfigLabelAccumulator(accumulator);
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class CompositeLayer method addConfigLabelAccumulatorForRegion.
/**
* Adds the configLabelAccumulator to the existing label accumulators.
*/
public void addConfigLabelAccumulatorForRegion(String regionName, IConfigLabelAccumulator configLabelAccumulator) {
IConfigLabelAccumulator existingConfigLabelAccumulator = this.regionNameToConfigLabelAccumulatorMap.get(regionName);
AggregateConfigLabelAccumulator aggregateAccumulator;
if (existingConfigLabelAccumulator instanceof AggregateConfigLabelAccumulator) {
aggregateAccumulator = (AggregateConfigLabelAccumulator) existingConfigLabelAccumulator;
} else {
aggregateAccumulator = new AggregateConfigLabelAccumulator();
if (existingConfigLabelAccumulator != null) {
aggregateAccumulator.add(existingConfigLabelAccumulator);
}
this.regionNameToConfigLabelAccumulatorMap.put(regionName, aggregateAccumulator);
}
aggregateAccumulator.add(configLabelAccumulator);
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class CSSExample method postConstruct.
@PostConstruct
public void postConstruct(Composite parent, Shell shell) {
parent.setLayout(new GridLayout());
// property names of the Person class
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "password", "description", "age", "money", "married", "gender", "address.street", "address.city", "favouriteFood", "favouriteDrinks" };
// 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");
IDataProvider bodyDataProvider = new ListDataProvider<>(PersonService.getExtendedPersonsWithAddress(10), new ExtendedReflectiveColumnPropertyAccessor<ExtendedPersonWithAddress>(propertyNames));
DefaultGridLayer gridLayer = new DefaultGridLayer(bodyDataProvider, new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap));
// unregister the default registered commandhandler to make the fill
// handle work here for the age column
gridLayer.unregisterCommandHandler(CopyDataToClipboardCommand.class);
gridLayer.getBodyLayer().unregisterCommandHandler(CopyDataToClipboardCommand.class);
final DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
AggregateConfigLabelAccumulator accumulator = new AggregateConfigLabelAccumulator();
// create the ColumnLabelAccumulator with IDataProvider to be able to
// tell the CSS engine about the added labels
accumulator.add(new ColumnLabelAccumulator(bodyDataProvider));
ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
columnLabelAccumulator.registerColumnOverrides(5, CustomLineBorderDecorator.RIGHT_LINE_BORDER_LABEL);
accumulator.add(columnLabelAccumulator);
bodyDataLayer.setConfigLabelAccumulator(accumulator);
NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new FillHandleConfiguration(gridLayer.getBodyLayer().getSelectionLayer()));
gridLayer.addConfiguration(new DefaultEditConfiguration());
gridLayer.addConfiguration(new DefaultEditBindings());
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, EditableRule.ALWAYS_EDITABLE, DisplayMode.NORMAL, "COLUMN_4");
configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, new DataValidator() {
@Override
public boolean validate(int columnIndex, int rowIndex, Object newValue) {
if (newValue instanceof Integer && ((Integer) newValue).intValue() > 100) {
return false;
}
return true;
}
}, DisplayMode.NORMAL, "COLUMN_4");
}
});
natTable.setData(CSSSWTConstants.CSS_CLASS_NAME_KEY, "basic");
// application model menu configuration
menuService.registerContextMenu(natTable, "org.eclipse.nebula.widgets.nattable.examples.e4.popupmenu.0");
// get the menu registered by EMenuService
final Menu e4Menu = natTable.getMenu();
// remove the menu reference from NatTable instance
natTable.setMenu(null);
natTable.addConfiguration(new AbstractUiBindingConfiguration() {
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
// add NatTable menu items
// and register the DisposeListener
new PopupMenuBuilder(natTable, e4Menu).withInspectLabelsMenuItem().build();
// register the UI binding
uiBindingRegistry.registerMouseDownBinding(new MouseEventMatcher(SWT.NONE, GridRegion.BODY, MouseEventMatcher.RIGHT_BUTTON), new PopupMenuAction(e4Menu));
}
});
natTable.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
// add a custom painter for key errortext
int[] yErrorOffsets = { 0, 1, 2, 1 };
CellPainterFactory.getInstance().registerContentPainter("errortext", (properties, underlying) -> {
return new TextPainter(true, true, false) {
@Override
protected void paintDecoration(IStyle cellStyle, GC gc, int x, int y, int length, int fontHeight) {
int underlineY = y + fontHeight - (gc.getFontMetrics().getDescent() / 2);
Color previousColor = gc.getForeground();
gc.setForeground(GUIHelper.COLOR_RED);
int startX = x;
underlineY--;
int index = 0;
while (startX <= (x + length)) {
gc.drawPoint(startX, underlineY + yErrorOffsets[(index % 4)]);
index++;
startX++;
}
gc.setForeground(previousColor);
}
};
});
showSourceLinks(parent, getClass().getName());
}
Aggregations