use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.
the class CellSelectionTest method shouldReturnSixCells.
@Test
public void shouldReturnSixCells() {
this.selectionLayer.clear();
this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 1, 0, false, true));
this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 2, 0, false, true));
this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 1, 1, false, true));
this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 2, 1, false, true));
this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 1, 2, false, true));
this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 2, 2, false, true));
Collection<PositionCoordinate> cells = ArrayUtil.asCollection(this.selectionLayer.getSelectedCellPositions());
Assert.assertEquals(6, cells.size());
// (1, 0)
Assert.assertTrue(cells.contains(new PositionCoordinate(this.selectionLayer, 1, 0)));
// (1, 1)
Assert.assertTrue(cells.contains(new PositionCoordinate(this.selectionLayer, 1, 1)));
// (1, 2)
Assert.assertTrue(cells.contains(new PositionCoordinate(this.selectionLayer, 1, 2)));
// (2, 0)
Assert.assertTrue(cells.contains(new PositionCoordinate(this.selectionLayer, 2, 0)));
// (2, 1)
Assert.assertTrue(cells.contains(new PositionCoordinate(this.selectionLayer, 2, 1)));
// (2, 2)
Assert.assertTrue(cells.contains(new PositionCoordinate(this.selectionLayer, 2, 2)));
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.
the class ColumnSelectionTest method shouldNotIncludeDeselectedCellsWithCtrlModifier.
@Test
public void shouldNotIncludeDeselectedCellsWithCtrlModifier() {
// test a previous bug where single deselected cells where added to the
// selection with following modifier selections
// start from a clear selection state
this.selectionLayer.clear();
// select a single cell
this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 2, 0, false, false));
// deselect the cell again
this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 2, 0, false, true));
// trigger selection of column 4 with ctrl
this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 4, 0, false, true));
assertEquals(4, this.selectionLayer.getSelectionAnchor().getColumnPosition());
assertEquals(0, this.selectionLayer.getSelectionAnchor().getRowPosition());
assertFalse("[2, 0] is selected", this.selectionLayer.isCellPositionSelected(2, 0));
assertTrue("column 4 not fully selected", this.selectionLayer.isColumnPositionFullySelected(4));
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.
the class CellSelectionTest method willSelectBodyCellAndShouldHaveColumnHeaderSelected.
@Test
public void willSelectBodyCellAndShouldHaveColumnHeaderSelected() {
// Select body cell
// The cell position is a grid layer position
this.gridLayer.doCommand(new SelectCellCommand(this.gridLayer, 2, 2, false, false));
// Get body layer cell corresponding to the selected body cell
ILayer bodyLayer = this.gridLayer.getBodyLayer();
// The column position is 1 because it takes into account the offset of
// the row header
ILayerCell cell = bodyLayer.getCellByPosition(1, 1);
// Assert the cell is in selected state
Assert.assertEquals(DisplayMode.SELECT, cell.getDisplayMode());
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand 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