Search in sources :

Example 1 with LayerCell

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

the class ColumnGroupGroupHeaderLayer 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);
    if (rowPosition == 0) {
        if (this.model.isPartOfAGroup(bodyColumnIndex)) {
            return new LayerCell(this, getStartPositionOfGroup(columnPosition), rowPosition, columnPosition, rowPosition, getColumnSpan(columnPosition), 1);
        } else {
            ILayerCell underlyingCell = this.columnGroupHeaderLayer.getCellByPosition(columnPosition, rowPosition);
            return new LayerCell(this, underlyingCell.getOriginColumnPosition(), underlyingCell.getOriginRowPosition(), columnPosition, rowPosition, underlyingCell.getColumnSpan(), underlyingCell.getRowSpan() + 1);
        }
    } else if (rowPosition == 1) {
        ILayerCell underlyingCell = this.columnGroupHeaderLayer.getCellByPosition(columnPosition, rowPosition - 1);
        boolean partOfAGroup = this.model.isPartOfAGroup(bodyColumnIndex);
        return new LayerCell(this, underlyingCell.getOriginColumnPosition(), underlyingCell.getOriginRowPosition() + (partOfAGroup ? 1 : 0), columnPosition, rowPosition, underlyingCell.getColumnSpan(), underlyingCell.getRowSpan() + (partOfAGroup ? 0 : 1));
    } else if (rowPosition == 2) {
        ILayerCell underlyingCell = this.columnGroupHeaderLayer.getCellByPosition(columnPosition, rowPosition - 1);
        boolean partOfAGroup = this.model.isPartOfAGroup(bodyColumnIndex) || this.columnGroupHeaderLayer.isColumnInGroup(bodyColumnIndex);
        return new LayerCell(this, underlyingCell.getOriginColumnPosition(), underlyingCell.getOriginRowPosition() + (partOfAGroup ? 1 : 0), columnPosition, rowPosition, underlyingCell.getColumnSpan(), underlyingCell.getRowSpan() + (partOfAGroup ? 0 : 1));
    }
    return null;
}
Also used : 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)

Example 2 with LayerCell

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

the class HierarchicalTreeLayer method getCellByPosition.

@Override
public ILayerCell getCellByPosition(int columnPosition, int rowPosition) {
    if (isLevelHeaderColumn(columnPosition)) {
        ILayerCell right = getCellByPosition(columnPosition + 1, rowPosition);
        if (right != null) {
            return new LayerCell(this, columnPosition, right.getOriginRowPosition(), columnPosition, rowPosition, 1, right.getRowSpan());
        }
        return null;
    }
    int underlyingColumnPosition = localToUnderlyingColumnPosition(columnPosition);
    int underlyingRowPosition = localToUnderlyingRowPosition(rowPosition);
    ILayerCell cell = this.underlyingLayer.getCellByPosition(underlyingColumnPosition, underlyingRowPosition);
    if (cell != null) {
        ILayerCell localCell = new TranslatedLayerCell(cell, this, underlyingToLocalColumnPosition(this.underlyingLayer, cell.getOriginColumnPosition()), underlyingToLocalRowPosition(this.underlyingLayer, cell.getOriginRowPosition()), underlyingToLocalColumnPosition(this.underlyingLayer, cell.getColumnPosition()), underlyingToLocalRowPosition(this.underlyingLayer, cell.getRowPosition()));
        if (cell.isSpannedCell()) {
            // in case a deeper level is collapsed, rows are hidden via row
            // hide/show mechanism
            // therefore the spanning needs to be updated to reflect the
            // hiding accordingly
            int rowSpan = cell.getRowSpan();
            for (int row = 0; row < cell.getRowSpan(); row++) {
                int rowIndex = this.underlyingLayer.getRowIndexByPosition(cell.getOriginRowPosition() + row);
                if (isRowIndexHidden(rowIndex)) {
                    rowSpan--;
                }
            }
            cell = new SpanningLayerCell(localCell, localCell.getColumnSpan(), rowSpan);
        } else {
            cell = localCell;
        }
    }
    return cell;
}
Also used : TranslatedLayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.TranslatedLayerCell) SpanningLayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.SpanningLayerCell) SpanningLayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.SpanningLayerCell) TranslatedLayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.TranslatedLayerCell) 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)

Example 3 with LayerCell

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

the class ButtonCellPainterTest method setup.

@Before
public void setup() {
    this.buttonRaisedPainter = new CellPainterFixture();
    this.buttonPressedPainter = new CellPainterFixture();
    this.buttonCellPainter = new ButtonCellPainter(this.buttonRaisedPainter, this.buttonPressedPainter);
    this.buttonCellPainter.setButtonFlashTime(500);
    this.natTable = new NatTableFixture();
    this.cellFixture = new LayerCell(this.natTable, 1, 5);
    this.gcFixture = new GC(this.natTable);
    this.mouseClickEvent = new MouseEvent(SWTUtils.getLeftClickEvent(100, 100, 0, this.natTable));
    this.mouseClickEvent.data = NatEventData.createInstanceFromEvent(this.mouseClickEvent);
}
Also used : CellPainterFixture(org.eclipse.nebula.widgets.nattable.test.fixture.CellPainterFixture) MouseEvent(org.eclipse.swt.events.MouseEvent) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) LayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.LayerCell) GC(org.eclipse.swt.graphics.GC) Before(org.junit.Before)

Example 4 with LayerCell

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

Aggregations

ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)4 LayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.LayerCell)4 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)1 SpanningLayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.SpanningLayerCell)1 TransformedLayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.TransformedLayerCell)1 TranslatedLayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.TranslatedLayerCell)1 CellPainterFixture (org.eclipse.nebula.widgets.nattable.test.fixture.CellPainterFixture)1 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 GC (org.eclipse.swt.graphics.GC)1 Before (org.junit.Before)1