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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations