use of org.eclipse.nebula.widgets.nattable.data.IDataProvider in project nebula.widgets.nattable by eclipse.
the class _4222_CellPainterExample 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" };
// 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));
final DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
registerColumnLabels(columnLabelAccumulator);
this.natTable = new NatTable(parent, gridLayer, false);
this.natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
this.natTable.addConfiguration(new PainterConfiguration());
this.natTable.configure();
new NatTableContentTooltip(this.natTable, GridRegion.BODY);
return this.natTable;
}
use of org.eclipse.nebula.widgets.nattable.data.IDataProvider in project nebula.widgets.nattable by eclipse.
the class _5111_ColumnGroupingExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "gender", "married", "address.street", "address.housenumber", "address.postalCode", "address.city", "age", "birthday", "money", "description", "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("gender", "Gender");
propertyToLabelMap.put("married", "Married");
propertyToLabelMap.put("address.street", "Street");
propertyToLabelMap.put("address.housenumber", "Housenumber");
propertyToLabelMap.put("address.postalCode", "Postalcode");
propertyToLabelMap.put("address.city", "City");
propertyToLabelMap.put("age", "Age");
propertyToLabelMap.put("birthday", "Birthday");
propertyToLabelMap.put("money", "Money");
propertyToLabelMap.put("description", "Description");
propertyToLabelMap.put("favouriteFood", "Food");
propertyToLabelMap.put("favouriteDrinks", "Drinks");
IColumnPropertyAccessor<ExtendedPersonWithAddress> columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
ColumnGroupModel columnGroupModel = new ColumnGroupModel();
// build the body layer stack
// Usually you would create a new layer stack by extending
// AbstractIndexLayerTransform and setting the ViewportLayer as
// underlying layer. But in this case using the ViewportLayer
// directly as body layer is also working.
IDataProvider bodyDataProvider = new ListDataProvider<>(PersonService.getExtendedPersonsWithAddress(10), columnPropertyAccessor);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(bodyDataLayer);
ColumnGroupReorderLayer columnGroupReorderLayer = new ColumnGroupReorderLayer(columnReorderLayer, columnGroupModel);
ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnGroupReorderLayer);
ColumnGroupExpandCollapseLayer columnGroupExpandCollapseLayer = new ColumnGroupExpandCollapseLayer(columnHideShowLayer, columnGroupModel);
final SelectionLayer selectionLayer = new SelectionLayer(columnGroupExpandCollapseLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// build the column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
ColumnGroupHeaderLayer columnGroupHeaderLayer = new ColumnGroupHeaderLayer(columnHeaderLayer, selectionLayer, columnGroupModel);
// configure the column groups
columnGroupHeaderLayer.addColumnsIndexesToGroup("Person", 0, 1, 2, 3);
columnGroupHeaderLayer.addColumnsIndexesToGroup("Address", 4, 5, 6, 7);
columnGroupHeaderLayer.addColumnsIndexesToGroup("Facts", 8, 9, 10);
columnGroupHeaderLayer.addColumnsIndexesToGroup("Personal", 11, 12, 13);
columnGroupHeaderLayer.setStaticColumnIndexesByGroup("Person", 0, 1);
columnGroupHeaderLayer.setStaticColumnIndexesByGroup("Address", 4, 5, 6);
columnGroupHeaderLayer.setGroupUnbreakable(1);
// build the row header layer
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer);
// build the corner layer
IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnGroupHeaderLayer);
// build the grid layer
GridLayer gridLayer = new GridLayer(viewportLayer, columnGroupHeaderLayer, rowHeaderLayer, cornerLayer);
// turn the auto configuration off as we want to add our header menu
// configuration
NatTable natTable = new NatTable(parent, gridLayer, false);
// as the autoconfiguration of the NatTable is turned off, we have to
// add the DefaultNatTableStyleConfiguration manually
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {
@Override
protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
PopupMenuBuilder builder = super.createColumnHeaderMenu(natTable).withColumnChooserMenuItem();
builder.withEnabledState(PopupMenuBuilder.HIDE_COLUMN_MENU_ITEM_ID, new VisibleColumnsRemaining(selectionLayer));
return builder;
}
});
// Column group header menu
final Menu columnGroupHeaderMenu = new PopupMenuBuilder(natTable).withRenameColumnGroupMenuItem().withRemoveColumnGroupMenuItem().build();
natTable.addConfiguration(new AbstractUiBindingConfiguration() {
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerFirstMouseDownBinding(new MouseEventMatcher(SWT.NONE, GridRegion.COLUMN_GROUP_HEADER, MouseEventMatcher.RIGHT_BUTTON), new PopupMenuAction(columnGroupHeaderMenu));
}
});
// enable this configuration to verify the automatic height calculation
// when using vertical text painter
// natTable.addConfiguration(new AbstractRegistryConfiguration() {
//
// @Override
// public void configureRegistry(IConfigRegistry configRegistry) {
// ICellPainter cellPainter = new BeveledBorderDecorator(new
// VerticalTextPainter(false, true, 5, true, true));
// configRegistry.registerConfigAttribute(
// CellConfigAttributes.CELL_PAINTER, cellPainter, DisplayMode.NORMAL,
// GridRegion.COLUMN_HEADER);
// }
// });
// Register column chooser
DisplayColumnChooserCommandHandler columnChooserCommandHandler = new DisplayColumnChooserCommandHandler(selectionLayer, columnHideShowLayer, columnHeaderLayer, columnHeaderDataLayer, columnGroupHeaderLayer, columnGroupModel, false, true);
viewportLayer.registerCommandHandler(columnChooserCommandHandler);
natTable.configure();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.data.IDataProvider in project nebula.widgets.nattable by eclipse.
the class ExampleSummaryRowGridConfiguration method init.
private void init(IDataProvider dataProvider, ConfigRegistry configRegistry, final String[] propertyNames, Map<String, String> propertyToLabelMap) {
// Body
SummaryRowBodyLayerStack bodyLayer = new SummaryRowBodyLayerStack(dataProvider, configRegistry);
SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
// Column header
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
ILayer columnHeaderLayer = new ColumnHeaderLayer(new DefaultColumnHeaderDataLayer(columnHeaderDataProvider), bodyLayer, selectionLayer);
// Row header
// Adding the specialized DefaultSummaryRowHeaderDataProvider to
// indicate the summary row in the row header
IDataProvider rowHeaderDataProvider = new DefaultSummaryRowHeaderDataProvider(bodyLayer.getDataLayer().getDataProvider(), "\u2211");
final DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
// add a label to the row header summary row cell aswell, so it can be
// styled differently too
// in this case it will simply use the same styling as the summary row
// in the body
rowHeaderDataLayer.setConfigLabelAccumulator(new AbstractOverrider() {
@Override
public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
if ((rowPosition + 1) == rowHeaderDataLayer.getRowCount()) {
configLabels.addLabel(SummaryRowLayer.DEFAULT_SUMMARY_ROW_CONFIG_LABEL);
}
}
});
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayer, selectionLayer);
// Corner
ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)), rowHeaderLayer, columnHeaderLayer);
setBodyLayer(bodyLayer);
setColumnHeaderLayer(columnHeaderLayer);
setRowHeaderLayer(rowHeaderLayer);
setCornerLayer(cornerLayer);
}
use of org.eclipse.nebula.widgets.nattable.data.IDataProvider in project nebula.widgets.nattable by eclipse.
the class _5123_SummaryRowPositionExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
Composite panel = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.verticalSpacing = 20;
panel.setLayout(layout);
// property names of the NumberValues class
String[] propertyNames = { "columnOneNumber", "columnTwoNumber", "columnThreeNumber", "columnFourNumber", "columnFiveNumber" };
IColumnPropertyAccessor<NumberValues> cpa = new ReflectiveColumnPropertyAccessor<>(propertyNames);
IDataProvider dataProvider = new ListDataProvider<>(createNumberValueList(), cpa);
ConfigRegistry configRegistry = new ConfigRegistry();
// Summary row fixed on top
DataLayer dataLayer = new DataLayer(dataProvider);
ViewportLayer viewportLayer = new ViewportLayer(dataLayer);
// Plug in the SummaryRowLayer
FixedSummaryRowLayer summaryRowLayer = new FixedSummaryRowLayer(dataLayer, viewportLayer, configRegistry, false);
summaryRowLayer.setHorizontalCompositeDependency(false);
CompositeLayer composite = new CompositeLayer(1, 2);
composite.setChildLayer("SUMMARY", summaryRowLayer, 0, 0);
composite.setChildLayer(GridRegion.BODY, viewportLayer, 0, 1);
NatTable natTable = new NatTable(panel, composite, false);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
// Configure custom summary formula for a column
natTable.addConfiguration(new ExampleSummaryRowConfiguration(dataProvider));
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.setConfigRegistry(configRegistry);
natTable.configure();
// Summary row fixed at the bottom
dataLayer = new DataLayer(dataProvider);
// IMPORTANT:
// since the summary row layer is to the bottom of the viewport layer
// we need to configure a GridLineCellLayerPainter that clips the top
// cell. This means the body data layer is clipped at the bottom since
// the painter is used globally
dataLayer.setLayerPainter(new GridLineCellLayerPainter(false, true));
viewportLayer = new ViewportLayer(dataLayer);
// Plug in the SummaryRowLayer
summaryRowLayer = new FixedSummaryRowLayer(dataLayer, viewportLayer, configRegistry, false);
summaryRowLayer.setHorizontalCompositeDependency(false);
composite = new CompositeLayer(1, 2);
composite.setChildLayer(GridRegion.BODY, viewportLayer, 0, 0);
composite.setChildLayer("SUMMARY", summaryRowLayer, 0, 1);
natTable = new NatTable(panel, composite, false);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
// Configure custom summary formula for a column
natTable.addConfiguration(new ExampleSummaryRowConfiguration(dataProvider));
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.setConfigRegistry(configRegistry);
natTable.configure();
return panel;
}
use of org.eclipse.nebula.widgets.nattable.data.IDataProvider in project nebula.widgets.nattable by eclipse.
the class _5015_AutomaticDataSpanningExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// property names of the NumberValues class
String[] propertyNames = { "columnOneNumber", "columnTwoNumber", "columnThreeNumber", "columnFourNumber", "columnFiveNumber" };
IColumnPropertyAccessor<NumberValues> cpa = new ReflectiveColumnPropertyAccessor<>(propertyNames);
IDataProvider dataProvider = new ListDataProvider<>(createNumberValueList(), cpa);
AutomaticSpanningDataProvider spanningDataProvider = new AutomaticSpanningDataProvider(dataProvider, true, false);
// spanningDataProvider.addAutoSpanningColumnPositions(0, 1, 2);
// spanningDataProvider.addAutoSpanningColumnPositions(2, 3, 4);
// spanningDataProvider.addAutoSpanningColumnPositions(0, 1, 3, 4);
// spanningDataProvider.addAutoSpanningRowPositions(0, 1, 2);
// spanningDataProvider.addAutoSpanningRowPositions(2, 3, 4);
// spanningDataProvider.addAutoSpanningRowPositions(0, 1, 3, 4);
NatTable natTable = new NatTable(parent, new ViewportLayer(new SelectionLayer(new SpanningDataLayer(spanningDataProvider))), false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new BodyMenuConfiguration(natTable, spanningDataProvider));
natTable.configure();
natTable.registerCommandHandler(new DisplayPersistenceDialogCommandHandler());
return natTable;
}
Aggregations