Search in sources :

Example 1 with InlineCellEditEvent

use of org.eclipse.nebula.widgets.nattable.edit.event.InlineCellEditEvent 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 InlineCellEditEvent

use of org.eclipse.nebula.widgets.nattable.edit.event.InlineCellEditEvent in project nebula.widgets.nattable by eclipse.

the class EditSelectionCommandHandler method doCommand.

@Override
public boolean doCommand(EditSelectionCommand command) {
    Composite parent = command.getParent();
    IConfigRegistry configRegistry = command.getConfigRegistry();
    Character initialValue = command.getCharacter();
    if (EditUtils.allCellsEditable(this.selectionLayer, configRegistry) && EditUtils.isEditorSame(this.selectionLayer, configRegistry) && EditUtils.isConverterSame(this.selectionLayer, configRegistry) && EditUtils.activateLastSelectedCellEditor(this.selectionLayer, configRegistry, command.isByTraversal())) {
        // check how many cells are selected
        Collection<ILayerCell> selectedCells = EditUtils.getSelectedCellsForEditing(this.selectionLayer);
        if (selectedCells.size() == 1) {
            // editing is triggered by key for a single cell
            // we need to fire the InlineCellEditEvent here because we
            // don't know the correct bounds of the cell to edit inline
            // corresponding to the NatTable.
            // On firing the event, a translation process is triggered,
            // converting the information to the correct values
            // needed for inline editing
            ILayerCell cell = selectedCells.iterator().next();
            this.selectionLayer.fireLayerEvent(new InlineCellEditEvent(this.selectionLayer, new PositionCoordinate(this.selectionLayer, cell.getOriginColumnPosition(), cell.getOriginRowPosition()), parent, configRegistry, (initialValue != null ? initialValue : cell.getDataValue())));
        } else if (selectedCells.size() > 1) {
            // determine the initial value
            Object initialEditValue = initialValue;
            if (initialValue == null && EditUtils.isValueSame(this.selectionLayer)) {
                ILayerCell cell = selectedCells.iterator().next();
                initialEditValue = this.selectionLayer.getDataValueByPosition(cell.getColumnPosition(), cell.getRowPosition());
            }
            EditController.editCells(selectedCells, parent, initialEditValue, configRegistry);
        }
    }
    // successful or not
    return true;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) InlineCellEditEvent(org.eclipse.nebula.widgets.nattable.edit.event.InlineCellEditEvent) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Aggregations

InlineCellEditEvent (org.eclipse.nebula.widgets.nattable.edit.event.InlineCellEditEvent)2 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)1 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)1 DefaultEditBindings (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings)1 DefaultEditConfiguration (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration)1 DummySpanningBodyDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DummySpanningBodyDataProvider)1 CompositeLayer (org.eclipse.nebula.widgets.nattable.layer.CompositeLayer)1 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)1 SpanningDataLayer (org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer)1 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)1 ILayerEvent (org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent)1 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)1 SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)1 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)1 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)1 Composite (org.eclipse.swt.widgets.Composite)1 Test (org.junit.Test)1