Search in sources :

Example 6 with SelectRegionCommand

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());
}
Also used : SelectRegionCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Rectangle(org.eclipse.swt.graphics.Rectangle) Test(org.junit.Test)

Example 7 with SelectRegionCommand

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());
}
Also used : SelectRegionCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Rectangle(org.eclipse.swt.graphics.Rectangle) Test(org.junit.Test)

Example 8 with SelectRegionCommand

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());
}
Also used : SelectRegionCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Rectangle(org.eclipse.swt.graphics.Rectangle) Test(org.junit.Test)

Example 9 with SelectRegionCommand

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;
}
Also used : SelectRegionCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand) ColumnPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) RowPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate)

Example 10 with SelectRegionCommand

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);
}
Also used : SelectRegionCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand) MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand) SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand) ConfigureScalingCommand(org.eclipse.nebula.widgets.nattable.layer.command.ConfigureScalingCommand)

Aggregations

SelectRegionCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand)10 Rectangle (org.eclipse.swt.graphics.Rectangle)8 Test (org.junit.Test)8 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)7 ColumnPositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate)1 RowPositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate)1 ClientAreaResizeCommand (org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand)1 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)1 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)1 ConfigureScalingCommand (org.eclipse.nebula.widgets.nattable.layer.command.ConfigureScalingCommand)1 ColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand)1 MultiColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand)1 SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)1