use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class NatTableFixture method getColumnLabelAccumulator.
private ColumnOverrideLabelAccumulator getColumnLabelAccumulator(DataLayer dataLayer) {
if (this.columnLabelAccumulator == null) {
this.columnLabelAccumulator = new ColumnOverrideLabelAccumulator(dataLayer);
dataLayer.setConfigLabelAccumulator(this.columnLabelAccumulator);
}
return this.columnLabelAccumulator;
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class GridSearchStrategyTest method searchShouldNotFindWithSkipSearchLabel.
@Test
public void searchShouldNotFindWithSkipSearchLabel() {
GridSearchStrategy gridStrategy = new GridSearchStrategy(this.configRegistry, false, true);
// If we don't specify to wrap the search, it will not find it.
gridStrategy.setContextLayer(this.selectionLayer);
gridStrategy.setCaseSensitive(true);
gridStrategy.setComparator(new CellValueAsStringComparator<>());
PositionCoordinate searchResult = gridStrategy.executeSearch("body");
assertNotNull(searchResult);
assertEquals(2, searchResult.columnPosition);
assertEquals(2, searchResult.rowPosition);
// clear the selection
this.selectionLayer.clear();
// configure skip search label
ColumnOverrideLabelAccumulator accumulator = new ColumnOverrideLabelAccumulator(this.selectionLayer);
accumulator.registerColumnOverrides(2, ISearchStrategy.SKIP_SEARCH_RESULT_LABEL);
this.selectionLayer.setConfigLabelAccumulator(accumulator);
searchResult = gridStrategy.executeSearch("body");
assertNull(searchResult);
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class DisplayColumnStyleEditorCommandHandlerTest method setup.
@Before
public void setup() {
this.labelAccumulatorFixture = new ColumnOverrideLabelAccumulator(new DataLayerFixture());
this.natTableFixture = new NatTableFixture();
this.configRegistryFixture = this.natTableFixture.getConfigRegistry();
this.commandFixture = new DisplayColumnStyleEditorCommand(this.natTableFixture, this.natTableFixture.getConfigRegistry(), 1, 1);
final SelectionLayer selectionLayer = ((DummyGridLayerStack) this.natTableFixture.getLayer()).getBodyLayer().getSelectionLayer();
this.handlerUnderTest = new DisplayColumnStyleEditorCommandHandler(selectionLayer, this.labelAccumulatorFixture, this.configRegistryFixture);
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator 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());
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class TableEditConfiguration method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// property names of the NumberValues class
String[] propertyNames = { "columnOneNumber", "columnTwoNumber", "columnThreeNumber", "columnFourNumber", "columnFiveNumber" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("columnOneNumber", "Column 1");
propertyToLabelMap.put("columnTwoNumber", "Column 2");
propertyToLabelMap.put("columnThreeNumber", "Column 3");
propertyToLabelMap.put("columnFourNumber", "Column 4");
propertyToLabelMap.put("columnFiveNumber", "Column 5");
DefaultGridLayer gridLayer = new DefaultGridLayer(createNumberValuesList(), propertyNames, propertyToLabelMap);
DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
registerColumnLabels(columnLabelAccumulator);
NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new TableEditConfiguration());
natTable.configure();
return natTable;
}
Aggregations