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