use of org.eclipse.nebula.widgets.nattable.data.ListDataProvider 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.data.ListDataProvider in project nebula.widgets.nattable by eclipse.
the class SelectionListenerExample method postConstruct.
@PostConstruct
public void postConstruct(Composite parent) {
// 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");
IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
final List<Person> data = PersonService.getPersons(10);
// create the body layer stack
final IRowDataProvider<Person> bodyDataProvider = new ListDataProvider<>(data, columnPropertyAccessor);
final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
final SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// create a E4SelectionListener and configure it for providing selection
// on cell selection
E4SelectionListener<Person> esl = new E4SelectionListener<>(service, selectionLayer, bodyDataProvider);
esl.setFullySelectedRowsOnly(false);
esl.setHandleSameRowSelection(false);
selectionLayer.addLayerListener(esl);
// create the column header layer stack
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(columnHeaderDataProvider), viewportLayer, selectionLayer);
// create the row header layer stack
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(new DefaultRowHeaderDataLayer(new DefaultRowHeaderDataProvider(bodyDataProvider)), viewportLayer, selectionLayer);
// create the corner layer stack
ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)), rowHeaderLayer, columnHeaderLayer);
// create the grid layer composed with the prior created layer stacks
GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
final NatTable natTable = new NatTable(parent, gridLayer);
natTable.setData("org.eclipse.e4.ui.css.CssClassName", "modern");
parent.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
outputArea = new Text(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
outputArea.setEditable(false);
GridDataFactory.fillDefaults().grab(true, false).hint(0, 100).align(SWT.FILL, SWT.BEGINNING).applyTo(outputArea);
showSourceLinks(parent, getClass().getName());
}
use of org.eclipse.nebula.widgets.nattable.data.ListDataProvider in project nebula.widgets.nattable by eclipse.
the class _424_NebulaRichTextIntegrationExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// set the directory to which the richtext resources should be unpacked
System.setProperty(RichTextEditor.JAR_UNPACK_LOCATION_PROPERTY, System.getProperty("user.dir") + File.separator + RichTextEditor.class.getPackage().getName());
String[] propertyNames = new String[] { "firstName", "lastName", "gender", "married", "description" };
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("firstName", "Firstname");
propertyToLabelMap.put("lastName", "Lastname");
propertyToLabelMap.put("gender", "Gender");
propertyToLabelMap.put("married", "Married");
propertyToLabelMap.put("description", "Description");
IColumnAccessor<Person> columnAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
List<Person> persons = PersonService.getPersons(10);
IDataProvider bodyDataProvider = new ListDataProvider<>(persons, columnAccessor);
DefaultColumnHeaderDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DefaultGridLayer gridLayer = new DefaultGridLayer(bodyDataProvider, columnHeaderDataProvider);
((AbstractLayer) gridLayer.getBodyDataLayer()).setConfigLabelAccumulator(new ColumnLabelAccumulator());
NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
// add custom painter and editor configuration
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
// configure converter
MarkupDisplayConverter markupConverter = new MarkupDisplayConverter();
markupConverter.registerMarkup("Simpson", "<em>", "</em>");
markupConverter.registerMarkup("Smithers", "<span style=\"background-color:rgb(255, 0, 0)\"><strong><s><u>", "</u></s></strong></span>");
// register markup display converter for normal displaymode
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, markupConverter, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 1);
// register default display converter for editing, so there is
// no markup in the editor
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDisplayConverter(), DisplayMode.EDIT, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 1);
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
// configure cell painter
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new BackgroundPainter(new PaddingDecorator(new RichTextCellPainter(), 2, 5, 2, 5)), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 1);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CheckBoxPainter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new BackgroundPainter(new PaddingDecorator(new RichTextCellPainter(), 2, 5, 2, 5)), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
// configure editing
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, EditableRule.ALWAYS_EDITABLE);
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new CheckBoxCellEditor(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new RichTextCellEditor(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
}
});
natTable.configure();
natTable.setTheme(new ModernNatTableThemeConfiguration());
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.data.ListDataProvider in project nebula.widgets.nattable by eclipse.
the class _5011_DataLayerExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
parent.setLayout(new GridLayout());
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
IDataProvider bodyDataProvider = new ListDataProvider<>(PersonService.getPersons(10), columnPropertyAccessor);
final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
// use different style bits to avoid rendering of inactive scrollbars
// for small table
// Note: The enabling/disabling and showing of the scrollbars is handled
// by the ViewportLayer.
// Without the ViewportLayer the scrollbars will always be visible with
// the default
// style bits of NatTable.
final NatTable natTable = new NatTable(parent, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED, bodyDataLayer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
Button b1 = new Button(parent, SWT.PUSH);
b1.setText("Toggle column width");
b1.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
_5011_DataLayerExample.this.showDefaultColumnWidth = !_5011_DataLayerExample.this.showDefaultColumnWidth;
if (_5011_DataLayerExample.this.showDefaultColumnWidth) {
// reset to default
bodyDataLayer.setColumnWidthByPosition(0, DataLayer.DEFAULT_COLUMN_WIDTH, false);
bodyDataLayer.setColumnWidthByPosition(1, DataLayer.DEFAULT_COLUMN_WIDTH, false);
bodyDataLayer.setColumnWidthByPosition(2, DataLayer.DEFAULT_COLUMN_WIDTH, false);
bodyDataLayer.setColumnWidthByPosition(3, DataLayer.DEFAULT_COLUMN_WIDTH, false);
// this one will trigger the refresh
bodyDataLayer.setColumnWidthByPosition(4, DataLayer.DEFAULT_COLUMN_WIDTH, true);
} else {
bodyDataLayer.setColumnWidthByPosition(0, 70, false);
bodyDataLayer.setColumnWidthByPosition(1, 70, false);
bodyDataLayer.setColumnWidthByPosition(2, 50, false);
bodyDataLayer.setColumnWidthByPosition(3, 30, false);
// this one will trigger the refresh
bodyDataLayer.setColumnWidthByPosition(4, 200, true);
}
}
});
Button b2 = new Button(parent, SWT.PUSH);
b2.setText("Toggle row height");
b2.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
_5011_DataLayerExample.this.showDefaultRowHeight = !_5011_DataLayerExample.this.showDefaultRowHeight;
if (_5011_DataLayerExample.this.showDefaultRowHeight) {
// reset to default
bodyDataLayer.setDefaultRowHeight(DataLayer.DEFAULT_ROW_HEIGHT);
} else {
bodyDataLayer.setDefaultRowHeight(50);
}
// repaint the table, as setting the default height is not
// triggering a refresh automatically
// this is because setting the default usually should be done
// prior rendering
natTable.refresh(false);
}
});
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.data.ListDataProvider in project nebula.widgets.nattable by eclipse.
the class _5052_RowSelectionExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// 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");
IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
final List<Person> data = PersonService.getPersons(10);
// create the body layer stack
IRowDataProvider<Person> bodyDataProvider = new ListDataProvider<>(data, columnPropertyAccessor);
final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
// create a SelectionLayer without using the default configuration
// this enables us to add the row selection configuration cleanly
// afterwards
final SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer, false);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// use a RowSelectionModel that will perform row selections and is able
// to identify a row via unique ID
selectionLayer.setSelectionModel(new RowSelectionModel<>(selectionLayer, bodyDataProvider, new IRowIdAccessor<Person>() {
@Override
public Serializable getRowId(Person rowObject) {
return rowObject.getId();
}
}));
// register the DefaultRowSelectionLayerConfiguration that contains the
// default styling and functionality bindings (search, tick update)
// and different configurations for a move command handler that always
// moves by a row and row only selection bindings
selectionLayer.addConfiguration(new DefaultRowSelectionLayerConfiguration());
// create the column header layer stack
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(columnHeaderDataProvider), viewportLayer, selectionLayer);
// create the row header layer stack
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(new DefaultRowHeaderDataLayer(new DefaultRowHeaderDataProvider(bodyDataProvider)), viewportLayer, selectionLayer);
// create the corner layer stack
ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)), rowHeaderLayer, columnHeaderLayer);
// create the grid layer composed with the prior created layer stacks
GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
return new NatTable(parent, gridLayer);
}
Aggregations