Search in sources :

Example 1 with ILayer

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

the class LayerCommandUtil method convertColumnPositionToTargetContext.

public static ColumnPositionCoordinate convertColumnPositionToTargetContext(ColumnPositionCoordinate columnPositionCoordinate, ILayer targetLayer) {
    if (columnPositionCoordinate != null) {
        ILayer layer = columnPositionCoordinate.getLayer();
        if (layer == targetLayer) {
            return columnPositionCoordinate;
        }
        int columnPosition = columnPositionCoordinate.getColumnPosition();
        int underlyingColumnPosition = layer.localToUnderlyingColumnPosition(columnPosition);
        if (underlyingColumnPosition < 0) {
            return null;
        }
        Collection<ILayer> underlyingLayers = layer.getUnderlyingLayersByColumnPosition(columnPosition);
        if (underlyingLayers != null) {
            for (ILayer underlyingLayer : underlyingLayers) {
                if (underlyingLayer != null) {
                    ColumnPositionCoordinate convertedColumnPositionCoordinate = convertColumnPositionToTargetContext(new ColumnPositionCoordinate(underlyingLayer, underlyingColumnPosition), targetLayer);
                    if (convertedColumnPositionCoordinate != null) {
                        return convertedColumnPositionCoordinate;
                    }
                }
            }
        }
    }
    return null;
}
Also used : ColumnPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer)

Example 2 with ILayer

use of org.eclipse.nebula.widgets.nattable.layer.ILayer 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 3 with ILayer

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

the class DefaultGridLayer method init.

protected void init(IUniqueIndexLayer bodyDataLayer, IUniqueIndexLayer columnHeaderDataLayer, IUniqueIndexLayer rowHeaderDataLayer, IUniqueIndexLayer cornerDataLayer) {
    // Body
    this.bodyDataLayer = bodyDataLayer;
    DefaultBodyLayerStack bodyLayer = new DefaultBodyLayerStack(bodyDataLayer);
    SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
    // Column header
    this.columnHeaderDataLayer = columnHeaderDataLayer;
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayer, selectionLayer);
    // Row header
    this.rowHeaderDataLayer = rowHeaderDataLayer;
    ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayer, selectionLayer);
    // Corner
    this.cornerDataLayer = cornerDataLayer;
    ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnHeaderLayer);
    setBodyLayer(bodyLayer);
    setColumnHeaderLayer(columnHeaderLayer);
    setRowHeaderLayer(rowHeaderLayer);
    setCornerLayer(cornerLayer);
    CopyDataCommandHandler cdch = new CopyDataCommandHandler(selectionLayer, columnHeaderDataLayer, rowHeaderDataLayer);
    cdch.setCopyFormattedText(true);
    registerCommandHandler(cdch);
}
Also used : SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) CopyDataCommandHandler(org.eclipse.nebula.widgets.nattable.copy.command.CopyDataCommandHandler) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack)

Example 4 with ILayer

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

the class AbstractRowHideShowLayer method cacheVisibleRowIndexes.

protected void cacheVisibleRowIndexes() {
    this.cachedVisibleRowIndexOrder = new HashMap<Integer, Integer>();
    this.cachedVisibleRowPositionOrder = new HashMap<Integer, Integer>();
    this.cachedHiddenRowIndexToPositionMap = new HashMap<Integer, Integer>();
    this.startYCache.clear();
    ILayer underlyingLayer = getUnderlyingLayer();
    int rowPosition = 0;
    for (int parentRowPosition = 0; parentRowPosition < underlyingLayer.getRowCount(); parentRowPosition++) {
        int rowIndex = underlyingLayer.getRowIndexByPosition(parentRowPosition);
        if (!isRowIndexHidden(rowIndex)) {
            this.cachedVisibleRowIndexOrder.put(rowIndex, rowPosition);
            this.cachedVisibleRowPositionOrder.put(rowPosition, rowIndex);
            rowPosition++;
        } else {
            this.cachedHiddenRowIndexToPositionMap.put(rowIndex, rowPosition);
        }
    }
}
Also used : ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer)

Example 5 with ILayer

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

the class ImagePainter method paintCell.

@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
    if (this.paintBg) {
        super.paintCell(cell, gc, bounds, configRegistry);
    }
    Image image = getImage(cell, configRegistry);
    if (image != null) {
        Rectangle imageBounds = image.getBounds();
        IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
        int contentHeight = imageBounds.height;
        if (this.calculateByHeight && (contentHeight > bounds.height)) {
            int contentToCellDiff = (cell.getBounds().height - bounds.height);
            ILayer layer = cell.getLayer();
            layer.doCommand(new RowResizeCommand(layer, cell.getRowPosition(), contentHeight + contentToCellDiff, true));
        }
        int contentWidth = imageBounds.width;
        if (this.calculateByWidth && (contentWidth > bounds.width)) {
            int contentToCellDiff = (cell.getBounds().width - bounds.width);
            ILayer layer = cell.getLayer();
            layer.doCommand(new ColumnResizeCommand(layer, cell.getColumnPosition(), contentWidth + contentToCellDiff, true));
        }
        gc.drawImage(image, bounds.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, imageBounds.width), bounds.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, imageBounds.height));
    }
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) RowResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand)

Aggregations

ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)127 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)91 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)90 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)82 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)73 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)71 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)68 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)68 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)67 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)67 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)64 HashMap (java.util.HashMap)62 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)60 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)58 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)58 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)53 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)48 GridLayout (org.eclipse.swt.layout.GridLayout)35 CompositeLayer (org.eclipse.nebula.widgets.nattable.layer.CompositeLayer)34 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)33