Search in sources :

Example 1 with TransformedLayerCell

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

the class TestLayer method parseCellsInfo.

public void parseCellsInfo(String cellsInfo) {
    int rowPosition = 0;
    StringTokenizer rowOfCellInfoTokenizer = new StringTokenizer(cellsInfo, "\n");
    while (rowOfCellInfoTokenizer.hasMoreTokens()) {
        String rowOfCellInfo = rowOfCellInfoTokenizer.nextToken().trim();
        int columnPosition = 0;
        StringTokenizer cellInfoTokenizer = new StringTokenizer(rowOfCellInfo, "|");
        while (cellInfoTokenizer.hasMoreTokens()) {
            String cellInfo = cellInfoTokenizer.nextToken().trim();
            StringTokenizer cellInfoFieldTokenizer = new StringTokenizer(cellInfo, "~:", true);
            while (cellInfoFieldTokenizer.hasMoreTokens()) {
                String token = cellInfoFieldTokenizer.nextToken().trim();
                if ("<".equals(token)) {
                    // Span from left
                    this.dataValues[columnPosition][rowPosition] = this.dataValues[columnPosition - 1][rowPosition];
                    ILayerCell cell = this.cells[columnPosition - 1][rowPosition];
                    Rectangle boundsRect = this.bounds[columnPosition - 1][rowPosition];
                    if (columnPosition >= cell.getColumnPosition() + cell.getColumnSpan()) {
                        boundsRect = new Rectangle(boundsRect.x, boundsRect.y, boundsRect.width + getColumnWidthByPosition(columnPosition), boundsRect.height);
                        final ILayerCell underlyingCell = cell;
                        cell = new TransformedLayerCell(cell) {

                            @Override
                            public int getColumnSpan() {
                                return underlyingCell.getColumnSpan() + 1;
                            }
                        };
                    }
                    this.cells[columnPosition][rowPosition] = cell;
                    this.bounds[columnPosition][rowPosition] = boundsRect;
                    if (cellInfoFieldTokenizer.hasMoreTokens()) {
                        System.out.println("Extra tokens detected after parsing span for cell position " + columnPosition + "," + rowPosition + "; ignoring");
                    }
                    break;
                } else if ("^".equals(token)) {
                    // Span from above
                    this.dataValues[columnPosition][rowPosition] = this.dataValues[columnPosition][rowPosition - 1];
                    ILayerCell cell = this.cells[columnPosition][rowPosition - 1];
                    Rectangle boundsRect = this.bounds[columnPosition][rowPosition - 1];
                    if (rowPosition >= cell.getRowPosition() + cell.getRowSpan()) {
                        boundsRect = new Rectangle(boundsRect.x, boundsRect.y, boundsRect.width, boundsRect.height + getRowHeightByPosition(rowPosition));
                        final ILayerCell underlyingCell = cell;
                        cell = new TransformedLayerCell(cell) {

                            @Override
                            public int getRowSpan() {
                                return underlyingCell.getRowSpan() + 1;
                            }
                        };
                    }
                    this.cells[columnPosition][rowPosition] = cell;
                    this.bounds[columnPosition][rowPosition] = boundsRect;
                    if (cellInfoFieldTokenizer.hasMoreTokens()) {
                        System.out.println("Extra tokens detected after parsing span for cell position " + columnPosition + "," + rowPosition + "; ignoring");
                    }
                    break;
                } else if ("~".equals(token)) {
                    String nextToken = cellInfoFieldTokenizer.nextToken().trim();
                    if ("~".equals(nextToken)) {
                        throw new IllegalArgumentException("Bad " + nextToken + " delimiter found when parsing display mode for cell position " + columnPosition + "," + rowPosition);
                    } else if (":".equals(nextToken)) {
                        // Parse config labels
                        parseConfigLabels(columnPosition, rowPosition, cellInfoFieldTokenizer, cellInfoFieldTokenizer.nextToken().trim());
                        break;
                    } else {
                        // Parse display mode
                        this.displayModes[columnPosition][rowPosition] = nextToken;
                    }
                } else if (":".equals(token)) {
                    String nextToken = cellInfoFieldTokenizer.nextToken().trim();
                    if ("~".equals(nextToken)) {
                        throw new IllegalArgumentException("Bad " + nextToken + " delimiter found when parsing config labels for cell position " + columnPosition + "," + rowPosition);
                    } else if (":".equals(nextToken)) {
                        throw new IllegalArgumentException("Bad " + nextToken + " delimiter found when parsing config labels for cell position " + columnPosition + "," + rowPosition);
                    } else {
                        // Parse config labels
                        parseConfigLabels(columnPosition, rowPosition, cellInfoFieldTokenizer, nextToken);
                        break;
                    }
                } else {
                    // Parse data value
                    this.dataValues[columnPosition][rowPosition] = token;
                    this.cells[columnPosition][rowPosition] = new TestLayerCell(this, columnPosition, rowPosition);
                    this.bounds[columnPosition][rowPosition] = new Rectangle(getStartXOfColumnPosition(columnPosition), getStartYOfRowPosition(rowPosition), getColumnWidthByPosition(columnPosition), getRowHeightByPosition(rowPosition));
                }
            }
            columnPosition++;
        }
        rowPosition++;
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) Rectangle(org.eclipse.swt.graphics.Rectangle) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) TransformedLayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.TransformedLayerCell)

Example 2 with TransformedLayerCell

use of org.eclipse.nebula.widgets.nattable.layer.cell.TransformedLayerCell 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)2 TransformedLayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.TransformedLayerCell)2 StringTokenizer (java.util.StringTokenizer)1 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)1 LayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.LayerCell)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1