Search in sources :

Example 96 with ILayerCell

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

the class ColumnGroupHeaderLayer method getCellByPosition.

// Cell features
/**
 * If a cell belongs to a column group: column position - set to the start
 * position of the group span - set to the width/size of the column group
 *
 * NOTE: gc.setClip() is used in the CompositeLayerPainter to ensure that
 * partially visible Column group header cells are rendered properly.
 */
@Override
public ILayerCell getCellByPosition(int columnPosition, int rowPosition) {
    int bodyColumnIndex = getColumnIndexByPosition(columnPosition);
    // Column group header cell
    if (this.model.isPartOfAGroup(bodyColumnIndex)) {
        if (rowPosition == 0) {
            return new LayerCell(this, getStartPositionOfGroup(columnPosition), rowPosition, columnPosition, rowPosition, getColumnSpan(columnPosition), 1);
        } else {
            return new LayerCell(this, columnPosition, rowPosition);
        }
    } else {
        // render column header w/ rowspan = 2
        // as in this case we ask the column header layer for the cell
        // position and the column header layer asks his data provider for
        // the row count which should always return 1, we ask for row
        // position 0 instead of using getGroupHeaderRowPosition(), if we
        // would use getGroupHeaderRowPosition() the
        // ColumnGroupGroupHeaderLayer wouldn't work anymore
        ILayerCell cell = this.columnHeaderLayer.getCellByPosition(columnPosition, 0);
        if (cell != null) {
            final int rowSpan;
            if (this.calculateHeight && this.model.size() == 0) {
                rowSpan = 1;
            } else {
                rowSpan = 2;
            }
            cell = new TransformedLayerCell(cell) {

                @Override
                public ILayer getLayer() {
                    return ColumnGroupHeaderLayer.this;
                }

                @Override
                public int getRowSpan() {
                    return rowSpan;
                }
            };
        }
        return cell;
    }
}
Also used : ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) TransformedLayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.TransformedLayerCell) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) LayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.LayerCell) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) TransformedLayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.TransformedLayerCell)

Example 97 with ILayerCell

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

the class FreezeSelectionStrategy method getBottomRightPosition.

@Override
public PositionCoordinate getBottomRightPosition() {
    if (this.selectionLayer.getSelectedCells().size() > 1) {
        if (this.selectionLayer.getFullySelectedColumnPositions().length > 0) {
            // if columns are fully selected we will freeze the columns to
            // the left including the selected column with the greatest
            // index
            int columnPosition = 0;
            int[] selColPos = this.selectionLayer.getFullySelectedColumnPositions();
            for (int col : selColPos) {
                columnPosition = Math.max(columnPosition, col);
            }
            return new PositionCoordinate(this.freezeLayer, columnPosition, -1);
        } else if (this.selectionLayer.getFullySelectedRowPositions().length > 0) {
            // if rows are fully selected we will freeze the rows to the top
            // including the selected row with the greatest index
            int rowPosition = 0;
            int[] selRowPos = this.selectionLayer.getFullySelectedRowPositions();
            for (int row : selRowPos) {
                rowPosition = Math.max(rowPosition, row);
            }
            return new PositionCoordinate(this.freezeLayer, -1, rowPosition);
        } else {
            // find the selected cell that is most to the left and to the
            // top of the selection
            int columnPosition = -1;
            int rowPosition = -1;
            PositionCoordinate[] coords = this.selectionLayer.getSelectedCellPositions();
            for (PositionCoordinate coord : coords) {
                if (columnPosition < 0) {
                    columnPosition = coord.columnPosition;
                } else {
                    if (!this.include) {
                        columnPosition = Math.min(columnPosition, coord.columnPosition);
                    } else {
                        columnPosition = Math.max(columnPosition, coord.columnPosition);
                    }
                }
                if (rowPosition < 0) {
                    rowPosition = coord.rowPosition;
                } else {
                    if (!this.include) {
                        rowPosition = Math.min(rowPosition, coord.rowPosition);
                    } else {
                        rowPosition = Math.max(rowPosition, coord.rowPosition);
                    }
                }
            }
            return new PositionCoordinate(this.freezeLayer, !this.include ? columnPosition - 1 : columnPosition, !this.include ? rowPosition - 1 : rowPosition);
        }
    } else {
        PositionCoordinate selectionAnchor = this.selectionLayer.getSelectionAnchor();
        if (selectionAnchor != null) {
            if (!this.include) {
                return new PositionCoordinate(this.freezeLayer, selectionAnchor.columnPosition - 1, selectionAnchor.rowPosition - 1);
            } else {
                ILayerCell selectionAnchorCell = this.selectionLayer.getCellByPosition(selectionAnchor.columnPosition, selectionAnchor.rowPosition);
                return new PositionCoordinate(this.freezeLayer, selectionAnchor.columnPosition + selectionAnchorCell.getColumnSpan() - 1, selectionAnchor.rowPosition + selectionAnchorCell.getRowSpan() - 1);
            }
        }
    }
    return null;
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 98 with ILayerCell

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

the class AbstractLayerTransform method getCellByPosition.

// Cell features
@Override
public ILayerCell getCellByPosition(int columnPosition, int rowPosition) {
    int underlyingColumnPosition = localToUnderlyingColumnPosition(columnPosition);
    int underlyingRowPosition = localToUnderlyingRowPosition(rowPosition);
    ILayerCell cell = this.underlyingLayer.getCellByPosition(underlyingColumnPosition, underlyingRowPosition);
    if (cell != null) {
        cell = new TranslatedLayerCell(cell, this, underlyingToLocalColumnPosition(this.underlyingLayer, cell.getOriginColumnPosition()), underlyingToLocalRowPosition(this.underlyingLayer, cell.getOriginRowPosition()), underlyingToLocalColumnPosition(this.underlyingLayer, cell.getColumnPosition()), underlyingToLocalRowPosition(this.underlyingLayer, cell.getRowPosition()));
    }
    return cell;
}
Also used : TranslatedLayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.TranslatedLayerCell) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 99 with ILayerCell

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

the class CompositeLayer method getCellByPosition.

// Cell features
@Override
public ILayerCell getCellByPosition(int compositeColumnPosition, int compositeRowPosition) {
    Point layoutCoordinate = getLayoutXYByPosition(compositeColumnPosition, compositeRowPosition);
    if (layoutCoordinate == null) {
        return null;
    }
    ILayer childLayer = this.childLayerLayout[layoutCoordinate.x][layoutCoordinate.y];
    int childColumnPosition = compositeColumnPosition - getColumnPositionOffset(layoutCoordinate.x);
    int childRowPosition = compositeRowPosition - getRowPositionOffset(layoutCoordinate.y);
    ILayerCell cell = childLayer.getCellByPosition(childColumnPosition, childRowPosition);
    if (cell != null) {
        cell = new TranslatedLayerCell(cell, this, underlyingToLocalColumnPosition(childLayer, cell.getOriginColumnPosition()), underlyingToLocalRowPosition(childLayer, cell.getOriginRowPosition()), underlyingToLocalColumnPosition(childLayer, cell.getColumnPosition()), underlyingToLocalRowPosition(childLayer, cell.getRowPosition()));
    }
    return cell;
}
Also used : TranslatedLayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.TranslatedLayerCell) Point(org.eclipse.swt.graphics.Point) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Point(org.eclipse.swt.graphics.Point)

Example 100 with ILayerCell

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

the class HierarchicalTreeLayer method doCommand.

@Override
public boolean doCommand(ILayerCommand command) {
    if (command instanceof SelectCellCommand && command.convertToTargetLayer(this)) {
        // perform selection of level on level header click
        SelectCellCommand selection = (SelectCellCommand) command;
        if (isLevelHeaderColumn(selection.getColumnPosition())) {
            ILayerCell clickedCell = getCellByPosition(selection.getColumnPosition(), selection.getRowPosition());
            // calculate number of header columns to the right
            int levelHeaderCount = 0;
            for (int i = this.levelHeaderPositions.length - 1; i >= 0; i--) {
                if (this.levelHeaderPositions[i] >= selection.getColumnPosition()) {
                    levelHeaderCount++;
                }
            }
            SelectRegionCommand selectRegion = new SelectRegionCommand(this, clickedCell.getColumnPosition() + 1, clickedCell.getOriginRowPosition(), getColumnCount() - levelHeaderCount - (clickedCell.getColumnPosition()), clickedCell.getRowSpan(), selection.isShiftMask(), selection.isControlMask());
            this.underlyingLayer.doCommand(selectRegion);
            return true;
        }
    } else if (command instanceof ConfigureScalingCommand) {
        this.dpiConverter = ((ConfigureScalingCommand) command).getHorizontalDpiConverter();
    } else if (command instanceof ClientAreaResizeCommand && command.convertToTargetLayer(this)) {
        ClientAreaResizeCommand clientAreaResizeCommand = (ClientAreaResizeCommand) command;
        Rectangle possibleArea = clientAreaResizeCommand.getScrollable().getClientArea();
        // remove the tree level header width from the client area to
        // ensure that the percentage calculation is correct
        possibleArea.width = possibleArea.width - (this.levelHeaderPositions.length * getScaledLevelHeaderWidth());
        clientAreaResizeCommand.setCalcArea(possibleArea);
    } else if (command instanceof ColumnReorderCommand) {
        ColumnReorderCommand crCommand = ((ColumnReorderCommand) command);
        if (!isValidTargetColumnPosition(crCommand.getFromColumnPosition(), crCommand.getToColumnPosition())) {
            // command without doing anything
            return true;
        }
        if (isLevelHeaderColumn(crCommand.getToColumnPosition())) {
            // tree level header
            return super.doCommand(new ColumnReorderCommand(this, crCommand.getFromColumnPosition(), crCommand.getToColumnPosition() + 1));
        }
    } else if (command instanceof MultiColumnReorderCommand) {
        MultiColumnReorderCommand crCommand = ((MultiColumnReorderCommand) command);
        for (int fromColumnPosition : crCommand.getFromColumnPositions()) {
            if (!isValidTargetColumnPosition(fromColumnPosition, crCommand.getToColumnPosition())) {
                // command would be skipped
                return true;
            }
        }
        if (isLevelHeaderColumn(crCommand.getToColumnPosition())) {
            // tree level header
            return super.doCommand(new MultiColumnReorderCommand(this, crCommand.getFromColumnPositions(), crCommand.getToColumnPosition() + 1));
        }
    }
    return super.doCommand(command);
}
Also used : SelectRegionCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand) MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand) SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand) ConfigureScalingCommand(org.eclipse.nebula.widgets.nattable.layer.command.ConfigureScalingCommand)

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