Search in sources :

Example 36 with ILayerCell

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

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

the class HierarchicalTreeLayer method handleLayerEvent.

@Override
public void handleLayerEvent(ILayerEvent event) {
    if (event instanceof IStructuralChangeEvent) {
        IStructuralChangeEvent structuralChangeEvent = (IStructuralChangeEvent) event;
        if (structuralChangeEvent.isVerticalStructureChanged()) {
            // recalculate node row indexes
            // build a new collection of nodes to avoid duplication clashes
            // as nodes are equal per column and row index
            int negativeIndex = -1;
            Set<HierarchicalTreeNode> updatedCollapsedNodes = new HashSet<HierarchicalTreeNode>();
            for (HierarchicalTreeNode node : this.collapsedNodes) {
                int newRowIndex = findTopRowIndex(node.columnIndex, node.rowObject);
                // the underlying collection
                if (newRowIndex >= 0) {
                    updatedCollapsedNodes.add(new HierarchicalTreeNode(node.columnIndex, newRowIndex, this.underlyingList.get(newRowIndex)));
                } else if (this.retainRemovedRowObjectNodes) {
                    updatedCollapsedNodes.add(new HierarchicalTreeNode(node.columnIndex, negativeIndex, node.rowObject));
                    negativeIndex--;
                }
            }
            this.collapsedNodes.clear();
            this.collapsedNodes.addAll(updatedCollapsedNodes);
            // recalculate hidden rows based on updated collapsed nodes
            Set<Integer> updatedHiddenRows = new HashSet<Integer>();
            for (HierarchicalTreeNode node : this.collapsedNodes) {
                updatedHiddenRows.addAll(getChildIndexes(node.columnIndex, node.rowIndex));
            }
            getHiddenRowIndexes().clear();
            getHiddenRowIndexes().addAll(updatedHiddenRows);
        }
    } else if (event instanceof SearchEvent) {
        PositionCoordinate coord = ((SearchEvent) event).getCellCoordinate();
        if (coord != null) {
            Integer foundIndex = coord.getLayer().getRowIndexByPosition(coord.rowPosition);
            if (getHiddenRowIndexes().contains(foundIndex)) {
                if (this.expandOnSearch) {
                    // not collapsible
                    for (int level = this.nodeColumnMapping.size() - 2; level >= 0; level--) {
                        ILayerCell nodeCell = coord.getLayer().getCellByPosition(this.nodeColumnMapping.get(level), coord.rowPosition);
                        int colIdx = coord.getLayer().getColumnIndexByPosition(nodeCell.getOriginColumnPosition());
                        int rowIdx = coord.getLayer().getRowIndexByPosition(nodeCell.getOriginRowPosition());
                        if (this.collapsedNodes.contains(new HierarchicalTreeNode(colIdx, rowIdx, null))) {
                            expandOrCollapse(colIdx, rowIdx);
                        }
                    }
                } else {
                    // only make the single row visible again
                    getHiddenRowIndexes().remove(foundIndex);
                }
            }
            invalidateCache();
            fireLayerEvent(new ShowRowPositionsEvent(this, Arrays.asList(foundIndex)));
        }
    }
    super.handleLayerEvent(event);
}
Also used : IStructuralChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.IStructuralChangeEvent) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) SearchEvent(org.eclipse.nebula.widgets.nattable.search.event.SearchEvent) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) ShowRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent) HashSet(java.util.HashSet)

Example 38 with ILayerCell

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

the class HierarchicalTreeExpandCollapseAction method run.

@Override
public void run(NatTable natTable, MouseEvent event) {
    int c = natTable.getColumnPositionByX(event.x);
    int r = natTable.getRowPositionByY(event.y);
    ILayerCell cell = natTable.getCellByPosition(c, r);
    int rowIndex = cell.getLayer().getRowIndexByPosition(cell.getOriginRowPosition());
    int columnIndex = cell.getLayer().getColumnIndexByPosition(cell.getOriginColumnPosition());
    HierarchicalTreeExpandCollapseCommand command = new HierarchicalTreeExpandCollapseCommand(rowIndex, columnIndex, this.toLevel);
    natTable.doCommand(command);
}
Also used : HierarchicalTreeExpandCollapseCommand(org.eclipse.nebula.widgets.nattable.hierarchical.command.HierarchicalTreeExpandCollapseCommand) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 39 with ILayerCell

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

the class AbstractLayer method getBoundsByPosition.

@Override
public Rectangle getBoundsByPosition(int columnPosition, int rowPosition) {
    ILayerCell cell = getCellByPosition(columnPosition, rowPosition);
    ILayer cellLayer = cell.getLayer();
    int xOffset = -1;
    int yOffset = -1;
    int width = 0;
    int height = 0;
    {
        int column = cell.getOriginColumnPosition();
        int end = column + cell.getColumnSpan();
        for (; column < end; column++) {
            int columnOffset = cellLayer.getStartXOfColumnPosition(column);
            if (column < cellLayer.getColumnCount()) {
                xOffset = columnOffset;
                break;
            }
        }
        for (; column < end; column++) {
            width += cellLayer.getColumnWidthByPosition(column);
        }
    }
    {
        int row = cell.getOriginRowPosition();
        int end = row + cell.getRowSpan();
        for (; row < end; row++) {
            int rowOffset = cellLayer.getStartYOfRowPosition(row);
            if (row < cellLayer.getRowCount()) {
                yOffset = rowOffset;
                break;
            }
        }
        for (; row < end; row++) {
            height += cellLayer.getRowHeightByPosition(row);
        }
    }
    return new Rectangle(xOffset, yOffset, width, height);
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 40 with ILayerCell

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

the class TableCellPainter method getPreferredHeight.

@Override
public int getPreferredHeight(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {
    Object[] cellDataArray = getDataAsArray(cell);
    if (cellDataArray != null) {
        int height = 0;
        for (Object data : cellDataArray) {
            ILayerCell subCell = createSubLayerCell(cell, data);
            height += this.getInternalPainter().getPreferredHeight(subCell, gc, configRegistry);
        }
        // add number of items-1 to calculate the pixels for grid lines
        height += cellDataArray.length;
        return height;
    }
    return this.getInternalPainter().getPreferredHeight(cell, gc, configRegistry);
}
Also used : 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