use of org.eclipse.nebula.widgets.nattable.selection.EditTraversalStrategy 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;
}
Aggregations