use of org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class DimensionallyDependentLayer method getConfigLabelsByPosition.
@Override
public LabelStack getConfigLabelsByPosition(int columnPosition, int rowPosition) {
int baseColumnPosition = LayerUtil.convertColumnPosition(this, columnPosition, this.baseLayer);
int baseRowPosition = LayerUtil.convertRowPosition(this, rowPosition, this.baseLayer);
LabelStack labelStack = this.baseLayer.getConfigLabelsByPosition(baseColumnPosition, baseRowPosition);
IConfigLabelAccumulator configLabelAccumulator = getConfigLabelAccumulator();
if (configLabelAccumulator != null) {
configLabelAccumulator.accumulateConfigLabels(labelStack, columnPosition, rowPosition);
}
return labelStack;
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class AbstractIndexLayerTransform method getConfigLabelsByPosition.
@Override
public LabelStack getConfigLabelsByPosition(int columnPosition, int rowPosition) {
LabelStack configLabels = this.underlyingLayer.getConfigLabelsByPosition(localToUnderlyingColumnPosition(columnPosition), localToUnderlyingRowPosition(rowPosition));
IConfigLabelAccumulator configLabelAccumulator = getConfigLabelAccumulator();
if (configLabelAccumulator != null) {
configLabelAccumulator.accumulateConfigLabels(configLabels, columnPosition, rowPosition);
}
String regionName = getRegionName();
if (regionName != null) {
configLabels.addLabel(regionName);
}
return configLabels;
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator 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.IConfigLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class _5054_SelectionProviderExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
Composite panel = new Composite(parent, SWT.NONE);
panel.setLayout(new GridLayout(2, true));
// property names of the Person class
String[] propertyNames = { "lastName", "firstName" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("lastName", "Lastname");
propertyToLabelMap.put("firstName", "Firstname");
IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
IRowIdAccessor<Person> rowIdAccessor = new IRowIdAccessor<Person>() {
@Override
public Serializable getRowId(Person rowObject) {
return rowObject.getId();
}
};
// create the first table
// create the body layer stack
final IRowDataProvider<Person> firstBodyDataProvider = new ListDataProvider<>(getSimpsonsList(), columnPropertyAccessor);
final DataLayer firstBodyDataLayer = new DataLayer(firstBodyDataProvider);
final SelectionLayer firstSelectionLayer = new SelectionLayer(firstBodyDataLayer);
ViewportLayer firstViewportLayer = new ViewportLayer(firstSelectionLayer);
// use a RowSelectionModel that will perform row selections and is able
// to identify a row via unique ID
firstSelectionLayer.setSelectionModel(new RowSelectionModel<>(firstSelectionLayer, firstBodyDataProvider, rowIdAccessor));
// create the column header layer stack
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer firstColumnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
ColumnHeaderLayer firstColumnHeaderLayer = new ColumnHeaderLayer(firstColumnHeaderDataLayer, firstViewportLayer, firstSelectionLayer);
// register custom label styling to indicate if the table is active
firstColumnHeaderDataLayer.setConfigLabelAccumulator(new IConfigLabelAccumulator() {
@Override
public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
if (_5054_SelectionProviderExample.this.isFirstSelectionProvider) {
configLabels.addLabelOnTop(ACTIVE_LABEL);
}
}
});
// set the region labels to make default configurations work, e.g.
// selection
CompositeLayer firstCompositeLayer = new CompositeLayer(1, 2);
firstCompositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, firstColumnHeaderLayer, 0, 0);
firstCompositeLayer.setChildLayer(GridRegion.BODY, firstViewportLayer, 0, 1);
final NatTable firstNatTable = new NatTable(panel, firstCompositeLayer, false);
firstNatTable.addConfiguration(new DefaultNatTableStyleConfiguration());
firstNatTable.addConfiguration(new ActiveTableStyleConfiguration());
firstNatTable.configure();
// set the modern theme
firstNatTable.setTheme(new ModernNatTableThemeConfiguration());
// add overlay painter for full borders
firstNatTable.addOverlayPainter(new NatTableBorderOverlayPainter());
// create the second table
// create the body layer stack
final IRowDataProvider<Person> secondBodyDataProvider = new ListDataProvider<>(getFlandersList(), columnPropertyAccessor);
final DataLayer secondBodyDataLayer = new DataLayer(secondBodyDataProvider);
final SelectionLayer secondSelectionLayer = new SelectionLayer(secondBodyDataLayer);
ViewportLayer secondViewportLayer = new ViewportLayer(secondSelectionLayer);
// use a RowSelectionModel that will perform row selections and is able
// to identify a row via unique ID
secondSelectionLayer.setSelectionModel(new RowSelectionModel<>(secondSelectionLayer, secondBodyDataProvider, rowIdAccessor));
// create the column header layer stack
DataLayer secondColumnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
ILayer secondColumnHeaderLayer = new ColumnHeaderLayer(secondColumnHeaderDataLayer, secondViewportLayer, secondSelectionLayer);
// register custom label styling to indicate if the table is active
secondColumnHeaderDataLayer.setConfigLabelAccumulator(new IConfigLabelAccumulator() {
@Override
public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
if (!_5054_SelectionProviderExample.this.isFirstSelectionProvider) {
configLabels.addLabelOnTop(ACTIVE_LABEL);
}
}
});
// set the region labels to make default configurations work, e.g.
// selection
CompositeLayer secondCompositeLayer = new CompositeLayer(1, 2);
secondCompositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, secondColumnHeaderLayer, 0, 0);
secondCompositeLayer.setChildLayer(GridRegion.BODY, secondViewportLayer, 0, 1);
final NatTable secondNatTable = new NatTable(panel, secondCompositeLayer, false);
secondNatTable.addConfiguration(new DefaultNatTableStyleConfiguration());
secondNatTable.addConfiguration(new ActiveTableStyleConfiguration());
secondNatTable.configure();
// set the modern theme
secondNatTable.setTheme(new ModernNatTableThemeConfiguration());
// add overlay painter for full borders
secondNatTable.addOverlayPainter(new NatTableBorderOverlayPainter());
// set ISelectionProvider
final RowSelectionProvider<Person> selectionProvider = new RowSelectionProvider<>(firstSelectionLayer, firstBodyDataProvider);
// add a listener to the selection provider, in an Eclipse application
// you would do this e.g. getSite().getPage().addSelectionListener()
selectionProvider.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
log("Selection changed:");
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
@SuppressWarnings("rawtypes") Iterator it = selection.iterator();
while (it.hasNext()) {
Person selected = (Person) it.next();
log(" " + selected.getFirstName() + " " + selected.getLastName());
}
}
});
// layout widgets
GridDataFactory.fillDefaults().grab(true, true).applyTo(firstNatTable);
GridDataFactory.fillDefaults().grab(true, true).applyTo(secondNatTable);
// add a region for buttons
Composite buttonArea = new Composite(panel, SWT.NONE);
buttonArea.setLayout(new RowLayout());
GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(buttonArea);
// create a button to enable selection provider change
Button button = new Button(buttonArea, SWT.PUSH);
button.setText("Change selection provider");
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
_5054_SelectionProviderExample.this.isFirstSelectionProvider = !_5054_SelectionProviderExample.this.isFirstSelectionProvider;
if (_5054_SelectionProviderExample.this.isFirstSelectionProvider) {
selectionProvider.updateSelectionProvider(firstSelectionLayer, firstBodyDataProvider);
} else {
selectionProvider.updateSelectionProvider(secondSelectionLayer, secondBodyDataProvider);
}
// refresh both tables to update the active rendering in the
// column header/ this is not necessary for updating the
// selection provider
firstNatTable.doCommand(new VisualRefreshCommand());
secondNatTable.doCommand(new VisualRefreshCommand());
}
});
// add a log area to the example to show the log entries
Text output = setupTextArea(panel);
GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(output);
return panel;
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class _308_DataModificationExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// set the GridLayout because the FillLayout seems to introduce a
// scrollbar rendering issue on changing the content
parent.setLayout(new GridLayout());
// property names of the Person class
String[] personPropertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
// mapping from property to label, needed for column header labels
Map<String, String> personPropertyToLabelMap = new HashMap<>();
personPropertyToLabelMap.put("firstName", "Firstname");
personPropertyToLabelMap.put("lastName", "Lastname");
personPropertyToLabelMap.put("gender", "Gender");
personPropertyToLabelMap.put("married", "Married");
personPropertyToLabelMap.put("birthday", "Birthday");
ListDataProvider<Person> bodyDataProvider = new ListDataProvider<>(PersonService.getPersons(10), new ReflectiveColumnPropertyAccessor<Person>(personPropertyNames));
IDataProvider personColumnHeaderDataProvider = new DefaultColumnHeaderDataProvider(personPropertyNames, personPropertyToLabelMap);
IDataProvider personRowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
// mapping from property to label, needed for column header labels
Map<String, String> addressPropertyToLabelMap = new HashMap<>();
addressPropertyToLabelMap.put("street", "Street");
addressPropertyToLabelMap.put("housenumber", "Housenumber");
addressPropertyToLabelMap.put("postalCode", "Postal Code");
addressPropertyToLabelMap.put("city", "City");
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);
ConfigRegistry configRegistry = new ConfigRegistry();
// create the body layer stack
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
bodyDataLayer.setConfigLabelAccumulator(new IConfigLabelAccumulator() {
@Override
public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
switch(columnPosition) {
case 3:
configLabels.addLabel("MARRIED");
break;
case 4:
configLabels.addLabel("DATE");
break;
}
}
});
DefaultBodyLayerStack bodyLayerStack = new DefaultBodyLayerStack(bodyDataLayer);
bodyDataLayer.registerCommandHandler(new DeleteRowCommandHandler<>(bodyDataProvider.getList()));
bodyDataLayer.registerCommandHandler(new InsertRowCommandHandler<>(bodyDataProvider.getList()));
// create the column header layer stack
DataLayer columnHeaderDataLayer = new DataLayer(personColumnHeaderDataProvider);
ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack.getViewportLayer(), bodyLayerStack.getSelectionLayer());
// create the row header layer stack
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(personRowHeaderDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayerStack.getViewportLayer(), bodyLayerStack.getSelectionLayer());
// create the corner layer stack
ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(personColumnHeaderDataProvider, personRowHeaderDataProvider)), rowHeaderLayer, columnHeaderLayer);
// create the grid layer composed with the prior created layer stacks
GridLayer gridLayer = new GridLayer(bodyLayerStack, columnHeaderLayer, rowHeaderLayer, cornerLayer);
final NatTable natTable = new NatTable(gridPanel, gridLayer, false);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
natTable.addConfiguration(new SingleClickSortConfiguration());
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CheckBoxPainter(), DisplayMode.NORMAL, "MARRIED");
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDateDisplayConverter("yyyy-MM-dd"), DisplayMode.NORMAL, "DATE");
}
});
natTable.addConfiguration(new AbstractUiBindingConfiguration() {
private final Menu bodyMenu = new PopupMenuBuilder(natTable).withMenuItemProvider(new IMenuItemProvider() {
@Override
public void addMenuItem(NatTable natTable, Menu popupMenu) {
MenuItem deleteRow = new MenuItem(popupMenu, SWT.PUSH);
deleteRow.setText("Insert below");
deleteRow.setEnabled(true);
deleteRow.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
int rowPosition = MenuItemProviders.getNatEventData(event).getRowPosition();
natTable.doCommand(new InsertRowCommand<>(bodyDataLayer, rowPosition, PersonService.getPersons(1).get(0)));
}
});
}
}).withMenuItemProvider(new IMenuItemProvider() {
@Override
public void addMenuItem(NatTable natTable, Menu popupMenu) {
MenuItem deleteRow = new MenuItem(popupMenu, SWT.PUSH);
deleteRow.setText("Delete");
deleteRow.setEnabled(true);
deleteRow.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
int rowPosition = MenuItemProviders.getNatEventData(event).getRowPosition();
natTable.doCommand(new DeleteRowCommand(natTable, rowPosition));
}
});
}
}).build();
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerMouseDownBinding(new MouseEventMatcher(SWT.NONE, GridRegion.BODY, MouseEventMatcher.RIGHT_BUTTON), new PopupMenuAction(this.bodyMenu) {
@Override
public void run(NatTable natTable, MouseEvent event) {
int columnPosition = natTable.getColumnPositionByX(event.x);
int rowPosition = natTable.getRowPositionByY(event.y);
if (!bodyLayerStack.getSelectionLayer().isRowPositionFullySelected(rowPosition)) {
natTable.doCommand(new SelectRowsCommand(natTable, columnPosition, rowPosition, false, false));
}
super.run(natTable, event);
}
});
}
});
natTable.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
return panel;
}
Aggregations