use of org.eclipse.nebula.widgets.nattable.layer.ILayer 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.ILayer in project nebula.widgets.nattable by eclipse.
the class ReorderColumnsAndGroupsCommandHandler method doCommand.
/**
* Check if any column belongs to a group. If yes, add all columns in that
* group. Assumes that the 'toLocation' is not inside another group
*/
@Override
protected boolean doCommand(ReorderColumnsAndGroupsCommand command) {
final ILayer underlyingLayer = this.columnGroupReorderLayer.getUnderlyingLayer();
List<String> groupsProcessed = new ArrayList<String>();
List<Integer> fromColumnPositions = command.getFromColumnPositions();
List<Integer> fromColumnPositionsWithGroupColumns = new ArrayList<Integer>();
for (Integer fromColumnPosition : fromColumnPositions) {
int fromColumnIndex = underlyingLayer.getColumnIndexByPosition(fromColumnPosition.intValue());
ColumnGroupModel model = this.columnGroupReorderLayer.getModel();
if (model.isPartOfAGroup(fromColumnIndex)) {
String groupName = model.getColumnGroupByIndex(fromColumnIndex).getName();
if (!groupsProcessed.contains(groupName)) {
groupsProcessed.add(groupName);
fromColumnPositionsWithGroupColumns.addAll(this.columnGroupReorderLayer.getColumnGroupPositions(fromColumnIndex));
}
} else {
fromColumnPositionsWithGroupColumns.add(fromColumnPosition);
}
}
return underlyingLayer.doCommand(new MultiColumnReorderCommand(this.columnGroupReorderLayer, fromColumnPositionsWithGroupColumns, command.getToColumnPosition(), command.isReorderToLeftEdge()));
}
use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class ViewportSelectColumnGroupCommandHandler method doCommand.
@Override
protected boolean doCommand(ViewportSelectColumnGroupCommand command) {
int start = -1;
int span = -1;
// if a column group group is configured, we inspect the row position
if (this.columnGroupGroupHeaderLayer != null && command.getNatTableRowPosition() == 0) {
start = this.columnGroupGroupHeaderLayer.getStartPositionOfGroup(command.getColumnPosition());
span = this.columnGroupGroupHeaderLayer.getColumnSpan(command.getColumnPosition());
} else {
start = this.columnGroupHeaderLayer.getStartPositionOfGroup(command.getColumnPosition());
span = this.columnGroupHeaderLayer.getColumnSpan(command.getColumnPosition());
}
// the SelectRegionCommand needs to be executed on the underlying layer
// this way the row range from 0 to MAX works, which otherwise breaks
// when selecting a column group on scrolled state
ILayer underlyingLayer = this.viewportLayer.getUnderlyingLayerByPosition(0, 0);
ColumnPositionCoordinate underlyingStart = LayerCommandUtil.convertColumnPositionToTargetContext(new ColumnPositionCoordinate(this.viewportLayer, start), underlyingLayer);
SelectRegionCommand regionCommand = new SelectRegionCommand(underlyingLayer, underlyingStart.getColumnPosition(), 0, span, Integer.MAX_VALUE, command.isWithShiftMask(), command.isWithControlMask());
// set the anchor row position to the first row in the viewport
RowPositionCoordinate underlyingRow = LayerCommandUtil.convertRowPositionToTargetContext(new RowPositionCoordinate(this.viewportLayer, 0), underlyingLayer);
regionCommand.setAnchorRowPosition(underlyingRow.rowPosition);
underlyingLayer.doCommand(regionCommand);
return true;
}
use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class ColumnHeaderLayer method renameColumnIndex.
public boolean renameColumnIndex(int columnIndex, String customColumnName) {
boolean renamed = this.renameColumnHelper.renameColumnIndex(columnIndex, customColumnName);
if (renamed) {
// search for the bottom layer in the horizontal dependency to
// create the event for index and correct layer
ILayer baseLayer = getHorizontalLayerDependency();
while (baseLayer.getUnderlyingLayerByPosition(0, 0) != null) {
baseLayer = baseLayer.getUnderlyingLayerByPosition(0, 0);
}
baseLayer.fireLayerEvent(new RenameColumnHeaderEvent(baseLayer, columnIndex));
}
return renamed;
}
use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class AbstractColumnHideShowLayer method cacheVisibleColumnIndexes.
private void cacheVisibleColumnIndexes() {
this.cachedVisibleColumnIndexOrder = new ArrayList<Integer>();
this.cachedVisibleColumnIndexPositionMap = new HashMap<Integer, Integer>();
this.cachedHiddenColumnIndexToPositionMap = new HashMap<Integer, Integer>();
this.startXCache.clear();
ILayer underlyingLayer = getUnderlyingLayer();
int columnPosition = 0;
for (int parentColumnPosition = 0; parentColumnPosition < underlyingLayer.getColumnCount(); parentColumnPosition++) {
int columnIndex = underlyingLayer.getColumnIndexByPosition(parentColumnPosition);
if (!isColumnIndexHidden(columnIndex)) {
this.cachedVisibleColumnIndexOrder.add(columnIndex);
this.cachedVisibleColumnIndexPositionMap.put(columnIndex, columnPosition);
columnPosition++;
} else {
this.cachedHiddenColumnIndexToPositionMap.put(columnIndex, columnPosition);
}
}
}
Aggregations