use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand in project nebula.widgets.nattable by eclipse.
the class RegionSelectionTest method shouldUpdateSelectedRegionLeftWithShift.
@Test
public void shouldUpdateSelectedRegionLeftWithShift() {
this.selectionLayer.doCommand(new SelectRegionCommand(this.selectionLayer, 2, 3, 3, 3, false, false));
this.selectionLayer.doCommand(new SelectRegionCommand(this.selectionLayer, 0, 3, 2, 3, true, false));
PositionCoordinate[] cellPositions = this.selectionLayer.getSelectedCellPositions();
assertEquals(9, cellPositions.length);
Rectangle region = new Rectangle(0, 3, 3, 3);
assertTrue("not all cells in region selected", this.selectionLayer.allCellsSelectedInRegion(region));
assertEquals(2, this.selectionLayer.getSelectionAnchor().getColumnPosition());
assertEquals(3, this.selectionLayer.getSelectionAnchor().getRowPosition());
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand in project nebula.widgets.nattable by eclipse.
the class RegionSelectionTest method shouldUpdateSelectedRegionUpWithShift.
@Test
public void shouldUpdateSelectedRegionUpWithShift() {
this.selectionLayer.doCommand(new SelectRegionCommand(this.selectionLayer, 2, 3, 3, 3, false, false));
this.selectionLayer.doCommand(new SelectRegionCommand(this.selectionLayer, 2, 0, 3, 1, true, false));
PositionCoordinate[] cellPositions = this.selectionLayer.getSelectedCellPositions();
assertEquals(12, cellPositions.length);
Rectangle region = new Rectangle(2, 0, 3, 3);
assertTrue("not all cells in region selected", this.selectionLayer.allCellsSelectedInRegion(region));
assertEquals(2, this.selectionLayer.getSelectionAnchor().getColumnPosition());
assertEquals(3, this.selectionLayer.getSelectionAnchor().getRowPosition());
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand in project nebula.widgets.nattable by eclipse.
the class RegionSelectionTest method shouldExtendSelectedRegionRightWithShift.
@Test
public void shouldExtendSelectedRegionRightWithShift() {
this.selectionLayer.doCommand(new SelectRegionCommand(this.selectionLayer, 2, 3, 3, 3, false, false));
this.selectionLayer.doCommand(new SelectRegionCommand(this.selectionLayer, 6, 3, 2, 3, true, false));
PositionCoordinate[] cellPositions = this.selectionLayer.getSelectedCellPositions();
assertEquals(18, cellPositions.length);
Rectangle region = new Rectangle(2, 3, 6, 3);
assertTrue("not all cells in region selected", this.selectionLayer.allCellsSelectedInRegion(region));
assertEquals(2, this.selectionLayer.getSelectionAnchor().getColumnPosition());
assertEquals(3, this.selectionLayer.getSelectionAnchor().getRowPosition());
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand 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.selection.command.SelectRegionCommand 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