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]);
}
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;
}
Aggregations