Search in sources :

Example 1 with ICellEditor

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);
}
Also used : ICellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor) TextCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor) Test(org.junit.Test)

Example 2 with ICellEditor

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);
}
Also used : ICellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor) TextCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor) Test(org.junit.Test)

Example 3 with ICellEditor

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);
        }
    }
}
Also used : ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) Rectangle(org.eclipse.swt.graphics.Rectangle) ArrayList(java.util.ArrayList) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Control(org.eclipse.swt.widgets.Control) ICellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor)

Example 4 with ICellEditor

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);
}
Also used : ICellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor) TextCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor) Test(org.junit.Test)

Example 5 with ICellEditor

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);
}
Also used : ICellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor) TextCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor) Test(org.junit.Test)

Aggregations

ICellEditor (org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor)9 TextCellEditor (org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor)5 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)5 Test (org.junit.Test)5 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)2 Control (org.eclipse.swt.widgets.Control)2 ArrayList (java.util.ArrayList)1 EditCellCommand (org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand)1 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)1 ICellEditDialog (org.eclipse.nebula.widgets.nattable.edit.gui.ICellEditDialog)1 LabelStack (org.eclipse.nebula.widgets.nattable.layer.LabelStack)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 Text (org.eclipse.swt.widgets.Text)1