use of org.eclipse.nebula.widgets.nattable.edit.gui.ICellEditDialog in project nebula.widgets.nattable by eclipse.
the class EditController method editCells.
/**
* This method is used to edit cells in a sub dialog. In every case this
* method will open a dialog for editing, regardless if the list of cells to
* edit contain several or only one value. Only if the given list of cells
* to edit is <code>null</code> or empty, there is no action performed.
*
* @param cells
* The list of cells to edit.
* @param parent
* The parent composite to access the parent shell, or
* <code>null</code> to create a top-level shell dialog. In the
* last case, the dialog will be opened as non modal.
* @param initialCanonicalValue
* The value that should be propagated to the editor control.
* Needed because for multi cell editing or editor activation by
* letter/digit key will result in a different value to populate
* for some editors than populating the value out of the
* cell/data model directly.
* @param configRegistry
* The {@link IConfigRegistry} containing the configuration of
* the current NatTable instance the command should be executed
* for. This is necessary because the edit controllers in the
* current architecture are not aware of the instance they are
* running in and therefore it is needed for activation of
* editors.
*/
public static void editCells(final Collection<ILayerCell> cells, final Composite parent, Object initialCanonicalValue, final IConfigRegistry configRegistry) {
if (cells != null && !cells.isEmpty()) {
// get the editor to use, because the editor contains information if
// it allows editing on a multi edit dialog
// Note: this works because previous to calling this method it is
// checked if all cells have the same editor configured. Otherwise
// this method will have serious issues further on.
ICellEditor cellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, cells.iterator().next().getConfigLabels().getLabels());
if (cells.size() == 1 || (cells.size() > 1 && supportMultiEdit(cells, cellEditor, configRegistry))) {
if (cellEditor.openMultiEditDialog()) {
// as the EditSelectionCommandHandler already ensured that
// all cells have the same configuration, we can simply use
// any cell for multi cell edit handling
ICellEditDialog dialog = CellEditDialogFactory.createCellEditDialog(parent != null ? parent.getShell() : null, initialCanonicalValue, cells.iterator().next(), cellEditor, configRegistry);
int returnValue = dialog.open();
if (returnValue == Window.OK) {
for (ILayerCell selectedCell : cells) {
Object editorValue = dialog.getCommittedValue();
if (!(dialog.getEditType() == EditTypeEnum.SET)) {
editorValue = dialog.calculateValue(selectedCell.getDataValue(), editorValue);
}
ILayer layer = selectedCell.getLayer();
layer.doCommand(new UpdateDataCommand(layer, selectedCell.getColumnPosition(), selectedCell.getRowPosition(), editorValue));
}
}
} else {
// directly changes the value and closes right away.
for (ILayerCell cell : cells) {
ICellEditHandler editHandler = new InlineEditHandler(cell.getLayer(), cell.getColumnPosition(), cell.getRowPosition());
cellEditor.activateCell(parent, initialCanonicalValue, EditModeEnum.INLINE, editHandler, cell, configRegistry);
}
}
}
}
}
Aggregations