Search in sources :

Example 1 with MoveCellSelectionCommandHandler

use of org.eclipse.nebula.widgets.nattable.selection.MoveCellSelectionCommandHandler 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;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) EditTraversalStrategy(org.eclipse.nebula.widgets.nattable.selection.EditTraversalStrategy) Composite(org.eclipse.swt.widgets.Composite) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) DefaultEditBindings(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) MoveCellSelectionCommandHandler(org.eclipse.nebula.widgets.nattable.selection.MoveCellSelectionCommandHandler) GridLayout(org.eclipse.swt.layout.GridLayout) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultEditConfiguration(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person)

Aggregations

NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)1 ReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor)1 Person (org.eclipse.nebula.widgets.nattable.dataset.person.Person)1 DefaultEditBindings (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings)1 DefaultEditConfiguration (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration)1 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)1 ColumnOverrideLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator)1 EditTraversalStrategy (org.eclipse.nebula.widgets.nattable.selection.EditTraversalStrategy)1 MoveCellSelectionCommandHandler (org.eclipse.nebula.widgets.nattable.selection.MoveCellSelectionCommandHandler)1 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)1 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1