Search in sources :

Example 1 with DefaultEditConfiguration

use of org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration in project nebula.widgets.nattable by eclipse.

the class EditIntegrationTest method openEditorForSpannedCellsShouldOpenInline.

@Test
public void openEditorForSpannedCellsShouldOpenInline() throws Exception {
    CompositeLayer layer = new CompositeLayer(1, 1);
    SelectionLayer selectionLayer = new SelectionLayer(new SpanningDataLayer(new DummySpanningBodyDataProvider(100, 100)));
    layer.setChildLayer(GridRegion.BODY, new ViewportLayer(selectionLayer), 0, 0);
    this.natTable = new NatTableFixture(layer, 1200, 300, false);
    layer.addConfiguration(new DefaultEditBindings());
    layer.addConfiguration(new DefaultEditConfiguration());
    this.natTable.enableEditingOnAllCells();
    final boolean[] inlineFired = new boolean[1];
    inlineFired[0] = false;
    selectionLayer.addLayerListener(new ILayerListener() {

        @Override
        public void handleLayerEvent(ILayerEvent event) {
            if (event instanceof InlineCellEditEvent) {
                inlineFired[0] = true;
            }
        }
    });
    this.natTable.configure();
    this.natTable.doCommand(new SelectCellCommand(this.natTable, 1, 1, false, false));
    this.natTable.notifyListeners(SWT.KeyDown, SWTUtils.keyEvent(SWT.F2));
    // Verify edit mode
    assertNotNull(this.natTable.getActiveCellEditor());
    assertEquals("Col: 1, Row: 1", this.natTable.getActiveCellEditor().getCanonicalValue());
    assertNotNull(ActiveCellEditorRegistry.getActiveCellEditor());
    assertEquals("Col: 1, Row: 1", ActiveCellEditorRegistry.getActiveCellEditor().getCanonicalValue());
    // verify that inline editing is used and not dialog
    assertTrue("No InlineCellEditEvent fired", inlineFired[0]);
}
Also used : NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) DummySpanningBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummySpanningBodyDataProvider) ILayerListener(org.eclipse.nebula.widgets.nattable.layer.ILayerListener) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) DefaultEditBindings(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings) ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) DefaultEditConfiguration(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) InlineCellEditEvent(org.eclipse.nebula.widgets.nattable.edit.event.InlineCellEditEvent) Test(org.junit.Test)

Example 2 with DefaultEditConfiguration

use of org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration 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)

Example 3 with DefaultEditConfiguration

use of org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration in project nebula.widgets.nattable by eclipse.

the class _801_VerticalCompositionWithFeaturesExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    ConfigRegistry configRegistry = new ConfigRegistry();
    Composite panel = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    panel.setLayout(layout);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
    Composite gridPanel = new Composite(panel, SWT.NONE);
    gridPanel.setLayout(layout);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(gridPanel);
    Composite buttonPanel = new Composite(panel, SWT.NONE);
    buttonPanel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(false, false).applyTo(buttonPanel);
    // 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 ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
    List<Person> values = PersonService.getPersons(10);
    final EventList<Person> eventList = GlazedLists.eventList(values);
    TransformedList<Person, Person> rowObjectsGlazedList = GlazedLists.threadSafeList(eventList);
    // use the SortedList constructor with 'null' for the Comparator because
    // the Comparator will be set by configuration
    SortedList<Person> sortedList = new SortedList<>(rowObjectsGlazedList, null);
    // wrap the SortedList with the FilterList
    FilterList<Person> filterList = new FilterList<>(sortedList);
    IRowDataProvider<Person> bodyDataProvider = new ListDataProvider<>(filterList, columnPropertyAccessor);
    final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    bodyDataLayer.setConfigLabelAccumulator(new ColumnLabelAccumulator());
    GlazedListsEventLayer<Person> eventLayer = new GlazedListsEventLayer<>(bodyDataLayer, filterList);
    final SelectionLayer selectionLayer = new SelectionLayer(eventLayer);
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
    // add sorting
    SortHeaderLayer<Person> sortHeaderLayer = new SortHeaderLayer<>(columnHeaderLayer, new GlazedListsSortModel<>(sortedList, columnPropertyAccessor, configRegistry, columnHeaderDataLayer), false);
    // add the filter row functionality
    final FilterRowHeaderComposite<Person> filterRowHeaderLayer = new FilterRowHeaderComposite<>(new DefaultGlazedListsFilterStrategy<>(filterList, columnPropertyAccessor, configRegistry), sortHeaderLayer, columnHeaderDataProvider, configRegistry);
    // set the region labels to make default configurations work, e.g.
    // editing, selection
    CompositeLayer compositeLayer = new CompositeLayer(1, 2);
    compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, filterRowHeaderLayer, 0, 0);
    compositeLayer.setChildLayer(GridRegion.BODY, viewportLayer, 0, 1);
    // add edit configurations
    compositeLayer.addConfiguration(new DefaultEditConfiguration());
    compositeLayer.addConfiguration(new DefaultEditBindings());
    // add print support
    compositeLayer.registerCommandHandler(new PrintCommandHandler(compositeLayer));
    compositeLayer.addConfiguration(new DefaultPrintBindings());
    // add excel export support
    compositeLayer.registerCommandHandler(new ExportCommandHandler(compositeLayer));
    compositeLayer.addConfiguration(new DefaultExportBindings());
    final NatTable natTable = new NatTable(gridPanel, compositeLayer, false);
    natTable.setConfigRegistry(configRegistry);
    // adding this configuration adds the styles and the painters to use
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    // add sorting configuration
    natTable.addConfiguration(new SingleClickSortConfiguration());
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE);
            // birthday is never editable
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new ComboBoxCellEditor(Arrays.asList(Gender.FEMALE, Gender.MALE)), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 2);
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, getGenderBooleanConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 2);
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new ComboBoxCellEditor(Arrays.asList(Boolean.TRUE, Boolean.FALSE)), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
        }
    });
    natTable.configure();
    final RowSelectionProvider<Person> selectionProvider = new RowSelectionProvider<>(selectionLayer, bodyDataProvider, false);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
    Button button = new Button(buttonPanel, SWT.PUSH);
    button.setText("Remove selected item");
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // the NatTable context
            if (natTable.getActiveCellEditor() != null) {
                natTable.commitAndCloseActiveCellEditor();
            }
            Person item = (Person) ((IStructuredSelection) selectionProvider.getSelection()).getFirstElement();
            eventList.remove(item);
        }
    });
    return panel;
}
Also used : HashMap(java.util.HashMap) DefaultPrintBindings(org.eclipse.nebula.widgets.nattable.print.config.DefaultPrintBindings) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) SortedList(ca.odell.glazedlists.SortedList) DefaultExportBindings(org.eclipse.nebula.widgets.nattable.export.config.DefaultExportBindings) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) GlazedListsEventLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) ExportCommandHandler(org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DefaultBooleanDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter) SortHeaderLayer(org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer) ComboBoxCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) DefaultEditBindings(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings) GridLayout(org.eclipse.swt.layout.GridLayout) DefaultEditConfiguration(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration) ExtendedReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) FilterRowHeaderComposite(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowHeaderComposite) PrintCommandHandler(org.eclipse.nebula.widgets.nattable.print.command.PrintCommandHandler) Composite(org.eclipse.swt.widgets.Composite) FilterRowHeaderComposite(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowHeaderComposite) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FilterList(ca.odell.glazedlists.FilterList) RowSelectionProvider(org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider) SingleClickSortConfiguration(org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)

Example 4 with DefaultEditConfiguration

use of org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration in project nebula.widgets.nattable by eclipse.

the class EditTraversalStrategyLeftRightTest method setUp.

@Before
public void setUp() {
    this.dataLayer = new DataLayerFixture(10, 10, 100, 20);
    this.selectionLayer = new SelectionLayer(this.dataLayer);
    this.viewportLayer = new ViewportLayer(this.selectionLayer);
    this.viewportLayer.setRegionName(GridRegion.BODY);
    this.viewportLayer.addConfiguration(new DefaultEditBindings());
    this.viewportLayer.addConfiguration(new DefaultEditConfiguration());
    this.natTable = new NatTableFixture(this.viewportLayer);
    this.natTable.enableEditingOnAllCells();
    this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE, DisplayMode.EDIT, NOT_EDITABLE);
    this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.OPEN_ADJACENT_EDITOR, Boolean.TRUE);
    this.natTable.registerLabelOnColumn(this.dataLayer, 2, NOT_EDITABLE);
    this.natTable.registerLabelOnColumn(this.dataLayer, 5, NOT_EDITABLE);
    this.natTable.registerLabelOnColumn(this.dataLayer, 6, NOT_EDITABLE);
    this.natTable.registerLabelOnColumn(this.dataLayer, 7, NOT_EDITABLE);
    this.natTable.registerLabelOnColumn(this.dataLayer, 8, NOT_EDITABLE);
    this.natTable.registerLabelOnColumn(this.dataLayer, 9, NOT_EDITABLE);
}
Also used : DefaultEditConfiguration(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) DataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) DefaultEditBindings(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings) Before(org.junit.Before)

Example 5 with DefaultEditConfiguration

use of org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration in project nebula.widgets.nattable by eclipse.

the class EditTraversalStrategyUpDownTest method setUp.

@Before
public void setUp() {
    // only use 10 columns to make the test cases easier
    String[] propertyNames = Arrays.copyOfRange(RowDataListFixture.getPropertyNames(), 0, 10);
    IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<>(RowDataListFixture.getList(10), new ReflectiveColumnPropertyAccessor<RowDataFixture>(propertyNames));
    this.dataLayer = new DataLayer(bodyDataProvider, 20, 20);
    this.selectionLayer = new SelectionLayer(this.dataLayer);
    this.viewportLayer = new ViewportLayer(this.selectionLayer);
    this.viewportLayer.setRegionName(GridRegion.BODY);
    this.viewportLayer.addConfiguration(new DefaultEditBindings());
    this.viewportLayer.addConfiguration(new DefaultEditConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new TextCellEditor(true, true));
            configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, new DefaultDataValidator());
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 9);
        }
    });
    this.natTable = new NatTableFixture(this.viewportLayer);
    this.natTable.enableEditingOnAllCells();
    this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE, DisplayMode.EDIT, NOT_EDITABLE);
    this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.OPEN_ADJACENT_EDITOR, Boolean.TRUE);
    // register non editable rows
    this.overrider = new RowOverrideLabelAccumulator<>(bodyDataProvider, new IRowIdAccessor<RowDataFixture>() {

        @Override
        public Serializable getRowId(RowDataFixture rowObject) {
            return rowObject.getSecurity_id();
        }
    });
    this.overrider.registerRowOverrides(2, NOT_EDITABLE);
    this.overrider.registerRowOverrides(5, NOT_EDITABLE);
    this.overrider.registerRowOverrides(6, NOT_EDITABLE);
    this.overrider.registerRowOverrides(7, NOT_EDITABLE);
    this.overrider.registerRowOverrides(8, NOT_EDITABLE);
    this.overrider.registerRowOverrides(9, NOT_EDITABLE);
    AggregateConfigLabelAccumulator accumulator = new AggregateConfigLabelAccumulator();
    accumulator.add(this.overrider);
    accumulator.add(new ColumnLabelAccumulator());
    this.dataLayer.setConfigLabelAccumulator(accumulator);
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) DefaultBooleanDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) DefaultDataValidator(org.eclipse.nebula.widgets.nattable.data.validate.DefaultDataValidator) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) DefaultEditBindings(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings) AggregateConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator) IRowIdAccessor(org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultEditConfiguration(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) TextCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) Before(org.junit.Before)

Aggregations

DefaultEditBindings (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings)8 DefaultEditConfiguration (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration)8 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)7 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)5 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)4 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)4 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)4 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)4 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)3 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)3 CompositeLayer (org.eclipse.nebula.widgets.nattable.layer.CompositeLayer)3 SpanningDataLayer (org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer)3 ColumnLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator)3 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)3 HashMap (java.util.HashMap)2 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)2 DefaultBooleanDisplayConverter (org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter)2 Person (org.eclipse.nebula.widgets.nattable.dataset.person.Person)2 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)2 DummySpanningBodyDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DummySpanningBodyDataProvider)2