use of org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer 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.grid.layer.DefaultGridLayer in project nebula.widgets.nattable by eclipse.
the class CrossValidationDialogErrorHandling method createExampleControl.
@Override
@SuppressWarnings("unchecked")
public Control createExampleControl(Composite parent) {
Composite panel = new Composite(parent, SWT.NONE);
panel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
Composite gridPanel = new Composite(panel, SWT.NONE);
gridPanel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(gridPanel);
Composite buttonPanel = new Composite(panel, SWT.NONE);
buttonPanel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(buttonPanel);
// property names of the EventData class
String[] propertyNames = { "title", "description", "where", "fromDate", "toDate" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("title", "Title");
propertyToLabelMap.put("description", "Description");
propertyToLabelMap.put("where", "Where");
propertyToLabelMap.put("fromDate", "From");
propertyToLabelMap.put("toDate", "To");
this.valuesToShow.addAll(createEventData());
ConfigRegistry configRegistry = new ConfigRegistry();
DefaultGridLayer gridLayer = new DefaultGridLayer(this.valuesToShow, propertyNames, propertyToLabelMap);
DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
IRowDataProvider<EventData> bodyDataProvider = (IRowDataProvider<EventData>) bodyDataLayer.getDataProvider();
bodyDataLayer.setConfigLabelAccumulator(new CrossValidationLabelAccumulator(bodyDataProvider));
final NatTable natTable = new NatTable(gridPanel, gridLayer, false);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new CrossValidationEditConfiguration(bodyDataProvider));
natTable.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
return panel;
}
use of org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer 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;
}
use of org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer in project nebula.widgets.nattable by eclipse.
the class EditableGridExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
DefaultGridLayer gridLayer = new DefaultGridLayer(RowDataListFixture.getList(), RowDataListFixture.getPropertyNames(), RowDataListFixture.getPropertyToLabelMap());
DataLayer columnHeaderDataLayer = (DataLayer) gridLayer.getColumnHeaderDataLayer();
columnHeaderDataLayer.setConfigLabelAccumulator(new ColumnLabelAccumulator());
final DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
IDataProvider dataProvider = bodyDataLayer.getDataProvider();
// NOTE: Register the accumulator on the body data layer.
// This ensures that the labels are bound to the column index and are
// unaffected by column order.
final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
natTable.addConfiguration(editableGridConfiguration(columnLabelAccumulator, dataProvider));
final ColumnHeaderCheckBoxPainter columnHeaderCheckBoxPainter = new ColumnHeaderCheckBoxPainter(bodyDataLayer);
final ICellPainter column9HeaderPainter = new BeveledBorderDecorator(new CellPainterDecorator(new TextPainter(), CellEdgeEnum.RIGHT, columnHeaderCheckBoxPainter));
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, column9HeaderPainter, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 9);
}
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerFirstSingleClickBinding(new CellPainterMouseEventMatcher(GridRegion.COLUMN_HEADER, MouseEventMatcher.LEFT_BUTTON, columnHeaderCheckBoxPainter), new ToggleCheckBoxColumnAction(columnHeaderCheckBoxPainter, bodyDataLayer));
}
});
natTable.configure();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer in project nebula.widgets.nattable by eclipse.
the class EditorConfiguration method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "password", "description", "age", "money", "married", "gender", "address.street", "address.city", "favouriteFood", "favouriteDrinks", "filename" };
// 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");
propertyToLabelMap.put("filename", "Filename");
IDataProvider bodyDataProvider = new ListDataProvider<>(PersonService.getExtendedPersonsWithAddress(10), new ExtendedReflectiveColumnPropertyAccessor<ExtendedPersonWithAddress>(propertyNames));
DefaultGridLayer gridLayer = new DefaultGridLayer(bodyDataProvider, new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap));
final DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
registerColumnLabels(columnLabelAccumulator);
final NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new EditorConfiguration());
natTable.configure();
new NatTableContentTooltip(natTable, GridRegion.BODY);
return natTable;
}
Aggregations