Search in sources :

Example 91 with ILayerCell

use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.

the class EditUtils method isConverterSame.

/**
 * Checks if all selected cells have the same {@link IDisplayConverter}
 * 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>.
 * <p>
 * Let's assume there are two columns, one containing an Integer, the other
 * a Date. Both have a TextCellEditor configured, so if only the editor is
 * checked, the multi edit dialog would open. On committing a changed value
 * an error would occur because of wrong conversion.
 * </p>
 *
 * @param selectedCells
 *            The collection of selected cells that should be checked.
 * @param configRegistry
 *            The {@link IConfigRegistry} needed to access the configured
 *            {@link IDisplayConverter}s.
 * @return <code>true</code> if all selected cells have the same
 *         {@link IDisplayConverter} configured, <code>false</code> if at
 *         least one cell has another {@link IDisplayConverter} configured.
 */
@SuppressWarnings("rawtypes")
public static boolean isConverterSame(Collection<ILayerCell> selectedCells, IConfigRegistry configRegistry) {
    if (selectedCells != null) {
        Set<Class> converterSet = new HashSet<Class>();
        for (ILayerCell selectedCell : selectedCells) {
            LabelStack labelStack = selectedCell.getConfigLabels();
            IDisplayConverter dataTypeConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.EDIT, labelStack.getLabels());
            if (dataTypeConverter != null) {
                converterSet.add(dataTypeConverter.getClass());
            }
            if (converterSet.size() > 1)
                return false;
        }
    }
    return true;
}
Also used : LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) IDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter) HashSet(java.util.HashSet)

Example 92 with ILayerCell

use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell 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 93 with ILayerCell

use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell 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 94 with ILayerCell

use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell 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)

Example 95 with ILayerCell

use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.

the class FillHandleLayerPainter method paintCopyBorder.

protected void paintCopyBorder(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle pixelRectangle, IConfigRegistry configRegistry) {
    Rectangle positionRectangle = getPositionRectangleFromPixelRectangle(natLayer, pixelRectangle);
    int columnPositionOffset = positionRectangle.x;
    int rowPositionOffset = positionRectangle.y;
    // Save gc settings
    int originalLineStyle = gc.getLineStyle();
    Color originalForeground = gc.getForeground();
    applyCopyBorderStyle(gc, configRegistry);
    int x0 = 0;
    int x1 = 0;
    int y0 = 0;
    int y1 = 0;
    boolean isFirst = true;
    for (ILayerCell[] cells : this.clipboard.getCopiedCells()) {
        for (ILayerCell cell : cells) {
            if (isFirst) {
                x0 = cell.getBounds().x;
                x1 = cell.getBounds().x + cell.getBounds().width;
                y0 = cell.getBounds().y;
                y1 = cell.getBounds().y + cell.getBounds().height;
                isFirst = false;
            } else {
                x0 = Math.min(x0, cell.getBounds().x);
                x1 = Math.max(x1, cell.getBounds().x + cell.getBounds().width);
                y0 = Math.min(y0, cell.getBounds().y);
                y1 = Math.max(y1, cell.getBounds().y + cell.getBounds().height);
            }
        }
    }
    x0 += xOffset - columnPositionOffset;
    x1 += xOffset - columnPositionOffset;
    y0 += yOffset - rowPositionOffset;
    y1 += yOffset - rowPositionOffset;
    gc.drawLine(x0, y0, x0, y1);
    gc.drawLine(x0, y0, x1, y0);
    gc.drawLine(x0, y1, x1, y1);
    gc.drawLine(x1, y0, x1, y1);
    // Restore original gc settings
    gc.setLineStyle(originalLineStyle);
    gc.setForeground(originalForeground);
}
Also used : Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Aggregations

ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)118 Test (org.junit.Test)45 Rectangle (org.eclipse.swt.graphics.Rectangle)23 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)14 SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)14 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)11 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)10 LabelStack (org.eclipse.nebula.widgets.nattable.layer.LabelStack)10 Color (org.eclipse.swt.graphics.Color)10 EditCellCommand (org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand)9 ICellPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)9 DataProviderFixture (org.eclipse.nebula.widgets.nattable.test.fixture.data.DataProviderFixture)9 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)8 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)5 Point (org.eclipse.swt.graphics.Point)5 HashSet (java.util.HashSet)4 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)4 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)4 IEditableRule (org.eclipse.nebula.widgets.nattable.config.IEditableRule)4 ICellEditor (org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor)4