use of org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor in project nebula.widgets.nattable by eclipse.
the class RowSelectionEditUtilsTest method testGetLastSelectedCellEditorWithSingleSelection.
@Test
public void testGetLastSelectedCellEditorWithSingleSelection() {
this.selectionLayer.selectCell(1, 1, false, false);
ICellEditor editor = EditUtils.getLastSelectedCellEditor(this.selectionLayer, this.natTable.getConfigRegistry());
assertNotNull(editor);
assertTrue(editor instanceof TextCellEditor);
}
use of org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor in project nebula.widgets.nattable by eclipse.
the class RowSelectionEditUtilsTest method testGetLastSelectedCellEditorWithMultiSelection.
@Test
public void testGetLastSelectedCellEditorWithMultiSelection() {
this.selectionLayer.selectCell(1, 1, false, true);
this.selectionLayer.selectCell(2, 2, false, true);
this.selectionLayer.selectCell(3, 3, false, true);
ICellEditor editor = EditUtils.getLastSelectedCellEditor(this.selectionLayer, this.natTable.getConfigRegistry());
assertNotNull(editor);
assertTrue(editor instanceof TextCellEditor);
}
use of org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor in project nebula.widgets.nattable by eclipse.
the class EditController method editCell.
/**
* Activates the edit mode for the given cell. Will determine whether the
* editor should be opened inline or in a subdialog.
*
* @param cell
* The cell that should be put into the edit mode.
* @param parent
* The parent Composite, needed for the creation of the editor
* control.
* @param initialCanonicalValue
* The value that should be put to the activated editor control.
* Usually this value should be the same as calling
* <code>cell.getDataValue()</code>, but for the special case
* that an editor should be activated pressing a letter or digit
* key on the current selection, the initial value should be the
* Character representing that key.
* @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.
*/
public static void editCell(final ILayerCell cell, final Composite parent, Object initialCanonicalValue, final IConfigRegistry configRegistry) {
try {
// determine the position of the cell to put into edit mode
Rectangle cellBounds = cell.getBounds();
ILayer layer = cell.getLayer();
int columnPosition = cell.getColumnPosition();
int rowPosition = cell.getRowPosition();
// read the configuration for the specified cell for
// - which editor to use for that cell
final List<String> configLabels = cell.getConfigLabels().getLabels();
// check which editor to use
final ICellEditor cellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, configLabels);
if (cellEditor.openInline(configRegistry, configLabels)) {
// edit inline
ICellEditHandler editHandler = new InlineEditHandler(layer, columnPosition, rowPosition);
Rectangle editorBounds = layer.getLayerPainter().adjustCellBounds(columnPosition, rowPosition, new Rectangle(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height));
cellEditor.activateCell(parent, initialCanonicalValue, EditModeEnum.INLINE, editHandler, cell, configRegistry);
final Control editorControl = cellEditor.getEditorControl();
editorBounds = cellEditor.calculateControlBounds(editorBounds);
// NatTableBorderOverlayPainter
if (editorBounds.x == 0) {
editorBounds.x += 1;
editorBounds.width -= 1;
}
if (editorControl != null && !editorControl.isDisposed()) {
editorControl.setBounds(editorBounds);
// We need to add the control listeners after setting the
// bounds to it because of the strange behaviour on Mac OS
// where a control loses focus if its bounds are set
cellEditor.addEditorControlListeners();
layer.fireLayerEvent(new CellEditorCreatedEvent(cellEditor));
}
} else {
List<ILayerCell> cells = new ArrayList<ILayerCell>();
cells.add(cell);
editCells(cells, parent, initialCanonicalValue, configRegistry);
}
} catch (Exception e) {
if (cell == null) {
// $NON-NLS-1$
log.error("Cell being edited is no longer available. Initial value: " + initialCanonicalValue, e);
} else {
// $NON-NLS-1$ //$NON-NLS-2$
log.error("Error while editing cell: Cell: " + cell + "; Initial value: " + initialCanonicalValue, e);
}
}
}
use of org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor in project nebula.widgets.nattable by eclipse.
the class EditUtilsTest method testGetLastSelectedCellEditorWithMultiSelection.
@Test
public void testGetLastSelectedCellEditorWithMultiSelection() {
this.selectionLayer.selectCell(1, 1, false, true);
this.selectionLayer.selectCell(2, 2, false, true);
this.selectionLayer.selectCell(3, 3, false, true);
ICellEditor editor = EditUtils.getLastSelectedCellEditor(this.selectionLayer, this.natTable.getConfigRegistry());
assertNotNull(editor);
assertTrue(editor instanceof TextCellEditor);
}
use of org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor in project nebula.widgets.nattable by eclipse.
the class EditUtilsTest method testGetLastSelectedCellEditorWithSingleSelection.
@Test
public void testGetLastSelectedCellEditorWithSingleSelection() {
this.selectionLayer.selectCell(1, 1, false, false);
ICellEditor editor = EditUtils.getLastSelectedCellEditor(this.selectionLayer, this.natTable.getConfigRegistry());
assertNotNull(editor);
assertTrue(editor instanceof TextCellEditor);
}
Aggregations