use of org.eclipse.nebula.widgets.nattable.selection.SelectionLayer in project nebula.widgets.nattable by eclipse.
the class _5045_ScrollableRowHeaderExample 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);
IDataProvider bodyDataProvider = new ListDataProvider<>(PersonService.getPersons(10), columnPropertyAccessor);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
DataLayer rowDataLayer = new DataLayer(new IDataProvider() {
@Override
public void setDataValue(int columnIndex, int rowIndex, Object newValue) {
}
@Override
public int getRowCount() {
return bodyDataProvider.getRowCount();
}
@Override
public Object getDataValue(int columnIndex, int rowIndex) {
return "Lorem ipsum dolor";
}
@Override
public int getColumnCount() {
return 1;
}
});
rowDataLayer.setDefaultColumnWidth(150);
ViewportLayer rowViewport = new ViewportLayer(rowDataLayer);
RowHeaderLayer scrollableRowHeaderLayer = new RowHeaderLayer(rowViewport, viewportLayer, selectionLayer);
RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(new DefaultRowHeaderDataLayer(new DefaultRowHeaderDataProvider(bodyDataProvider)), viewportLayer, selectionLayer);
CompositeLayer compositeLayer = new CompositeLayer(2, 1);
compositeLayer.setChildLayer(GridRegion.ROW_HEADER, rowHeaderLayer, 0, 0);
compositeLayer.setChildLayer(GridRegion.ROW_HEADER, scrollableRowHeaderLayer, 1, 0);
// build the column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
final DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
final AbstractLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
// build the corner layer
IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowDataLayer.getDataProvider());
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
final ILayer cornerLayer = new CornerLayer(cornerDataLayer, compositeLayer, columnHeaderLayer);
GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, compositeLayer, cornerLayer);
// MULTI-VIEWPORT-CONFIGURATION
// use a cell layer painter that is configured for left clipping
// this ensures that the rendering works correctly for split
// viewports
selectionLayer.setLayerPainter(new SelectionLayerPainter(true, false));
columnHeaderLayer.setLayerPainter(new CellLayerPainter(true, false));
// as the CompositeLayer is setting a IClientAreaProvider for the
// composition we need to set a special ClientAreaAdapter after the
// creation of the CompositeLayer to support split viewports
int leftWidth = 100;
ClientAreaAdapter leftClientAreaAdapter = new ClientAreaAdapter(rowViewport.getClientAreaProvider());
leftClientAreaAdapter.setWidth(leftWidth);
rowViewport.setClientAreaProvider(leftClientAreaAdapter);
// Wrap NatTable in composite so we can slap on the external horizontal
// sliders
Composite composite = new Composite(parent, SWT.NONE);
GridLayout gridLayout = new GridLayout(1, false);
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
gridLayout.horizontalSpacing = 0;
gridLayout.verticalSpacing = 0;
composite.setLayout(gridLayout);
NatTable natTable = new NatTable(composite, gridLayer);
GridData gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.verticalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
natTable.setLayoutData(gridData);
createSplitSliders(composite, rowViewport, rowHeaderLayer.getWidth(), viewportLayer);
// add an IOverlayPainter to render the split viewport border
natTable.addOverlayPainter(new IOverlayPainter() {
@Override
public void paintOverlay(GC gc, ILayer layer) {
Color beforeColor = gc.getForeground();
gc.setForeground(GUIHelper.COLOR_GRAY);
int viewportBorderX = compositeLayer.getWidth() - 1;
gc.drawLine(viewportBorderX, 0, viewportBorderX, layer.getHeight() - 1);
gc.setForeground(beforeColor);
}
});
// Mouse move - Show resize cursor
natTable.getUiBindingRegistry().registerFirstMouseMoveBinding(new ClientAreaResizeMatcher(compositeLayer), new VerticalResizeCursorAction());
natTable.getUiBindingRegistry().registerFirstMouseDragMode(new ClientAreaResizeMatcher(compositeLayer), new ClientAreaResizeDragMode(compositeLayer, rowDataLayer, leftClientAreaAdapter, rowViewport, viewportLayer));
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.selection.SelectionLayer in project nebula.widgets.nattable by eclipse.
the class _5051_SelectionLayerExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday", "address.street", "address.housenumber", "address.postalCode", "address.city" };
IColumnPropertyAccessor<PersonWithAddress> columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
IDataProvider bodyDataProvider = new ListDataProvider<>(PersonService.getPersonsWithAddress(50), columnPropertyAccessor);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// as the selection mouse bindings are registered for the region label
// GridRegion.BODY
// we need to set that region label to the viewport so the selection via
// mouse is working correctly
viewportLayer.setRegionName(GridRegion.BODY);
NatTable natTable = new NatTable(parent, viewportLayer);
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.selection.SelectionLayer in project nebula.widgets.nattable by eclipse.
the class _5053_SelectionEventsExample 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
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 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);
// Events are fired whenever selection occurs. These can be use to
// trigger external actions as required.
//
// This adds a custom ILayerListener that will listen and handle
// selection events on NatTable level
natTable.addLayerListener(new ILayerListener() {
// Default selection behavior selects cells by default.
@Override
public void handleLayerEvent(ILayerEvent event) {
if (event instanceof CellSelectionEvent) {
CellSelectionEvent cellEvent = (CellSelectionEvent) event;
log("Selected cell: [" + cellEvent.getRowPosition() + ", " + cellEvent.getColumnPosition() + "], " + natTable.getDataValueByPosition(cellEvent.getColumnPosition(), cellEvent.getRowPosition()));
} else if (event instanceof ColumnSelectionEvent) {
ColumnSelectionEvent columnEvent = (ColumnSelectionEvent) event;
log("Selected Column: " + columnEvent.getColumnPositionRanges());
} else if (event instanceof RowSelectionEvent) {
// directly ask the SelectionLayer about the selected rows
// and access the data via IRowDataProvider
Collection<Range> selections = selectionLayer.getSelectedRowPositions();
StringBuilder builder = new StringBuilder("Selected Persons: ").append(selectionLayer.getSelectedRowPositions()).append("[");
for (Range r : selections) {
for (int i = r.start; i < r.end; i++) {
Person p = bodyDataProvider.getRowObject(i);
if (p != null) {
if (!builder.toString().endsWith("[")) {
builder.append(", ");
}
builder.append(p.getFirstName()).append(" ").append(p.getLastName());
}
}
}
builder.append("]");
log(builder.toString());
}
}
});
// Layout widgets
parent.setLayout(new GridLayout(1, true));
natTable.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
// add a log area to the example to show the log entries
setupTextArea(parent);
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.selection.SelectionLayer in project nebula.widgets.nattable by eclipse.
the class _5055_SelectionTraversalExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
IRowDataProvider<Person> bodyDataProvider = new ListDataProvider<>(PersonService.getPersons(3), columnPropertyAccessor);
Composite panel = new Composite(parent, SWT.NONE);
panel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
// 1. AXIS traversal - NatTable default
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// as the selection mouse bindings are registered for the region label
// GridRegion.BODY we need to set that region label to the viewport so
// the selection via mouse is working correctly
viewportLayer.setRegionName(GridRegion.BODY);
NatTable natTable = new NatTable(panel, viewportLayer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
// 2. AXIS CYCLE traversal
bodyDataLayer = new DataLayer(bodyDataProvider);
selectionLayer = new SelectionLayer(bodyDataLayer);
viewportLayer = new ViewportLayer(selectionLayer);
// as the selection mouse bindings are registered for the region label
// GridRegion.BODY we need to set that region label to the viewport so
// the selection via mouse is working correctly
viewportLayer.setRegionName(GridRegion.BODY);
// register a MoveCellSelectionCommandHandler with
// AXIS_CYCLE_TRAVERSAL_STRATEGY
viewportLayer.registerCommandHandler(new MoveCellSelectionCommandHandler(selectionLayer, ITraversalStrategy.AXIS_CYCLE_TRAVERSAL_STRATEGY));
natTable = new NatTable(panel, viewportLayer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
// 3. TABLE traversal
bodyDataLayer = new DataLayer(bodyDataProvider);
selectionLayer = new SelectionLayer(bodyDataLayer);
viewportLayer = new ViewportLayer(selectionLayer);
// as the selection mouse bindings are registered for the region label
// GridRegion.BODY we need to set that region label to the viewport so
// the selection via mouse is working correctly
viewportLayer.setRegionName(GridRegion.BODY);
// register a MoveCellSelectionCommandHandler with
// TABLE_TRAVERSAL_STRATEGY
viewportLayer.registerCommandHandler(new MoveCellSelectionCommandHandler(selectionLayer, ITraversalStrategy.TABLE_TRAVERSAL_STRATEGY));
natTable = new NatTable(panel, viewportLayer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
// 4. TABLE CYCLE traversal
bodyDataLayer = new DataLayer(bodyDataProvider);
selectionLayer = new SelectionLayer(bodyDataLayer);
viewportLayer = new ViewportLayer(selectionLayer);
// as the selection mouse bindings are registered for the region label
// GridRegion.BODY we need to set that region label to the viewport so
// the selection via mouse is working correctly
viewportLayer.setRegionName(GridRegion.BODY);
// register a MoveCellSelectionCommandHandler with
// TABLE_CYCLE_TRAVERSAL_STRATEGY
viewportLayer.registerCommandHandler(new MoveCellSelectionCommandHandler(selectionLayer, ITraversalStrategy.TABLE_CYCLE_TRAVERSAL_STRATEGY));
natTable = new NatTable(panel, viewportLayer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
// 5. mixed traversal
// on left/right we will use TABLE CYCLE
// on up/down we will use AXIS CYCLE
bodyDataLayer = new DataLayer(bodyDataProvider);
selectionLayer = new SelectionLayer(bodyDataLayer);
viewportLayer = new ViewportLayer(selectionLayer);
// as the selection mouse bindings are registered for the region label
// GridRegion.BODY we need to set that region label to the viewport so
// the selection via mouse is working correctly
viewportLayer.setRegionName(GridRegion.BODY);
// register a MoveCellSelectionCommandHandler with
// TABLE_CYCLE_TRAVERSAL_STRATEGY for horizontal traversal
// and AXIS_CYCLE_TRAVERSAL_STRATEGY for vertical traversal
// NOTE:
// You could achieve the same by registering a command handler
// with TABLE_CYCLE_TRAVERSAL_STRATEGY and registering
// MoveSelectionActions with a customized ITraversalStrategy, e.g.
// AXIS_CYCLE_TRAVERSAL_STRATEGY
viewportLayer.registerCommandHandler(new MoveCellSelectionCommandHandler(selectionLayer, ITraversalStrategy.TABLE_CYCLE_TRAVERSAL_STRATEGY, ITraversalStrategy.AXIS_CYCLE_TRAVERSAL_STRATEGY));
natTable = new NatTable(panel, viewportLayer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
// 6. edit traversal traversal
// on left/right we will use TABLE CYCLE
// on up/down we will use AXIS CYCLE
bodyDataLayer = new DataLayer(bodyDataProvider);
selectionLayer = new SelectionLayer(bodyDataLayer);
viewportLayer = new ViewportLayer(selectionLayer);
// as the selection mouse bindings are registered for the region label
// GridRegion.BODY we need to set that region label to the viewport so
// the selection via mouse is working correctly
viewportLayer.setRegionName(GridRegion.BODY);
final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
registerColumnLabels(columnLabelAccumulator);
// add some edit configuration
viewportLayer.addConfiguration(new DefaultEditBindings());
viewportLayer.addConfiguration(new DefaultEditConfiguration());
viewportLayer.addConfiguration(new EditorConfiguration());
natTable = new NatTable(panel, viewportLayer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
// register a MoveCellSelectionCommandHandler with
// TABLE_CYCLE_TRAVERSAL_STRATEGY for horizontal traversal
// and AXIS_CYCLE_TRAVERSAL_STRATEGY for vertical traversal
// NOTE:
// You could achieve the same by registering a command handler
// with TABLE_CYCLE_TRAVERSAL_STRATEGY and registering
// MoveSelectionActions with a customized ITraversalStrategy, e.g.
// AXIS_CYCLE_TRAVERSAL_STRATEGY
viewportLayer.registerCommandHandler(new MoveCellSelectionCommandHandler(selectionLayer, new EditTraversalStrategy(ITraversalStrategy.TABLE_CYCLE_TRAVERSAL_STRATEGY, natTable), new EditTraversalStrategy(ITraversalStrategy.AXIS_CYCLE_TRAVERSAL_STRATEGY, natTable)));
return panel;
}
use of org.eclipse.nebula.widgets.nattable.selection.SelectionLayer in project nebula.widgets.nattable by eclipse.
the class _5062_CompositeHoverStylingExample 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");
// 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 DefaultBodyDataProvider<>(PersonService.getPersons(10), propertyNames);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
HoverLayer hoverLayer = new HoverLayer(bodyDataLayer);
SelectionLayer selectionLayer = new SelectionLayer(hoverLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// build the column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
HoverLayer columnHoverLayer = new HoverLayer(columnHeaderDataLayer, false);
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHoverLayer, viewportLayer, selectionLayer, false);
// add ColumnHeaderHoverLayerConfiguration to ensure that hover styling
// and resizing is working together
columnHeaderLayer.addConfiguration(new ColumnHeaderHoverLayerConfiguration(columnHoverLayer));
CompositeLayer compLayer = new CompositeLayer(1, 2);
compLayer.setChildLayer(GridRegion.COLUMN_HEADER, columnHeaderLayer, 0, 0);
compLayer.setChildLayer(GridRegion.BODY, viewportLayer, 0, 1);
// turn the auto configuration off as we want to add our hover styling
// configuration
NatTable natTable = new NatTable(parent, compLayer, false);
// as the autoconfiguration of the NatTable is turned off, we have to
// add the DefaultNatTableStyleConfiguration manually
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
// add the style configuration for hover
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
Style style = new Style();
style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.getColor(217, 232, 251));
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.HOVER);
Image bgImage = GUIHelper.getImageByURL("columnHeaderBg", getClass().getResource("/org/eclipse/nebula/widgets/nattable/examples/resources/column_header_bg.png"));
Image hoverBgImage = GUIHelper.getImageByURL("hoverColumnHeaderBg", getClass().getResource("/org/eclipse/nebula/widgets/nattable/examples/resources/hovered_column_header_bg.png"));
TextPainter txtPainter = new TextPainter(false, false);
ICellPainter bgImagePainter = new BackgroundImagePainter(txtPainter, bgImage, GUIHelper.getColor(192, 192, 192));
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, bgImagePainter, DisplayMode.NORMAL, GridRegion.COLUMN_HEADER);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, bgImagePainter, DisplayMode.NORMAL, GridRegion.CORNER);
ICellPainter hoveredHeaderPainter = new BackgroundImagePainter(txtPainter, hoverBgImage, GUIHelper.getColor(192, 192, 192));
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, hoveredHeaderPainter, DisplayMode.HOVER, GridRegion.COLUMN_HEADER);
}
});
natTable.configure();
return natTable;
}
Aggregations