Search in sources :

Example 6 with ICellEditor

use of org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor in project nebula.widgets.nattable by eclipse.

the class EditIntegrationTest method testEditorActivatedDuringInlineCellEdit.

@Test
public void testEditorActivatedDuringInlineCellEdit() {
    this.natTable.enableEditingOnAllCells();
    ILayerCell cell = this.natTable.getCellByPosition(4, 4);
    this.natTable.doCommand(new EditCellCommand(this.natTable, this.natTable.getConfigRegistry(), cell));
    ICellEditor cellEditor = this.natTable.getActiveCellEditor();
    assertNotNull(cellEditor);
    assertTrue(cellEditor instanceof TextCellEditor);
    TextCellEditor textCellEditor = (TextCellEditor) cellEditor;
    assertEquals("Col: 4, Row: 4", textCellEditor.getCanonicalValue());
    Control control = cellEditor.getEditorControl();
    assertNotNull(control);
    assertTrue(control instanceof Text);
}
Also used : Control(org.eclipse.swt.widgets.Control) ICellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor) Text(org.eclipse.swt.widgets.Text) TextCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) EditCellCommand(org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand) Test(org.junit.Test)

Example 7 with ICellEditor

use of org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor in project nebula.widgets.nattable by eclipse.

the class EditUtils method isEditorSame.

/**
 * Checks if all selected cells have the same {@link ICellEditor}
 * configured. This is needed for the multi edit feature to determine if a
 * multi edit is possible. If the collection of selected cells is
 * <code>null</code> or empty, this method will also return
 * <code>true</code>.
 *
 * @param selectedCells
 *            The collection of selected cells that should be checked.
 * @param configRegistry
 *            The {@link IConfigRegistry} needed to access the configured
 *            {@link ICellEditor}s.
 * @return <code>true</code> if all selected cells have the same
 *         {@link ICellEditor} configured, <code>false</code> if at least
 *         one cell has another {@link ICellEditor} configured.
 */
public static boolean isEditorSame(Collection<ILayerCell> selectedCells, IConfigRegistry configRegistry) {
    if (selectedCells != null) {
        ICellEditor lastSelectedCellEditor = null;
        for (ILayerCell selectedCell : selectedCells) {
            LabelStack labelStack = selectedCell.getConfigLabels();
            ICellEditor cellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, labelStack.getLabels());
            // anchor
            if (lastSelectedCellEditor == null) {
                lastSelectedCellEditor = cellEditor;
            }
            if (cellEditor != lastSelectedCellEditor) {
                return false;
            }
        }
    }
    return true;
}
Also used : LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) ICellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 8 with ICellEditor

use of org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor in project nebula.widgets.nattable by eclipse.

the class EditUtils method activateLastSelectedCellEditor.

/**
 * @param selectionLayer
 *            The {@link SelectionLayer} to retrieve the current selection.
 * @param configRegistry
 *            The {@link IConfigRegistry} needed to access the configured
 *            {@link ICellEditor}.
 * @param byTraversal
 *            <code>true</code> if the activation is triggered by traversal,
 *            <code>false</code> if not
 * @return <code>true</code> if the current selected cell contains an editor
 *         that should be activated, <code>false</code> if not
 */
public static boolean activateLastSelectedCellEditor(SelectionLayer selectionLayer, IConfigRegistry configRegistry, boolean byTraversal) {
    ILayerCell lastSelectedCell = EditUtils.getLastSelectedCell(selectionLayer);
    if (lastSelectedCell != null) {
        final List<String> lastSelectedCellLabelsArray = lastSelectedCell.getConfigLabels().getLabels();
        ICellEditor editor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, lastSelectedCellLabelsArray);
        if (editor != null) {
            return (!byTraversal || editor.activateOnTraversal(configRegistry, lastSelectedCellLabelsArray));
        }
    }
    return false;
}
Also used : ICellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 9 with ICellEditor

use of org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor 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);
                }
            }
        }
    }
}
Also used : ICellEditDialog(org.eclipse.nebula.widgets.nattable.edit.gui.ICellEditDialog) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ICellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

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