Search in sources :

Example 21 with PositionCoordinate

use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.

the class ColumnSelectionTest method onlyOneCellSelectedAtAnyTime.

@Test
public void onlyOneCellSelectedAtAnyTime() {
    this.selectionLayer.getSelectionModel().setMultipleSelectionAllowed(false);
    this.selectionLayer.clear();
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 1, 0, false, true));
    Collection<PositionCoordinate> cells = ArrayUtil.asCollection(this.selectionLayer.getSelectedCellPositions());
    assertEquals(1, cells.size());
    assertEquals(1, this.selectionLayer.getSelectedColumnPositions().length);
    assertEquals(1, this.selectionLayer.getSelectedColumnPositions()[0]);
    assertEquals(1, this.selectionLayer.getSelectedRowCount());
    // select another column with control mask
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 2, 0, false, true));
    cells = ArrayUtil.asCollection(this.selectionLayer.getSelectedCellPositions());
    assertEquals(1, cells.size());
    assertEquals(1, this.selectionLayer.getSelectedColumnPositions().length);
    assertEquals(2, this.selectionLayer.getSelectedColumnPositions()[0]);
    assertEquals(1, this.selectionLayer.getSelectedRowCount());
    // select additional columns with shift mask
    // only the last column should be selected afterwards
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 5, 0, true, false));
    cells = ArrayUtil.asCollection(this.selectionLayer.getSelectedCellPositions());
    assertEquals(1, cells.size());
    assertEquals(1, this.selectionLayer.getSelectedColumnPositions().length);
    assertEquals(5, this.selectionLayer.getSelectedColumnPositions()[0]);
    assertEquals(1, this.selectionLayer.getSelectedRowCount());
}
Also used : SelectColumnCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Test(org.junit.Test)

Example 22 with PositionCoordinate

use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.

the class SelectionIntegrationTest method assertCellSelected.

// Convenience asserts
private void assertCellSelected(int column, int row) {
    PositionCoordinate[] selectedCells = this.selectionLayer.getSelectedCellPositions();
    boolean selected = false;
    for (PositionCoordinate positionCoordinate : selectedCells) {
        if (column == positionCoordinate.getColumnPosition() && row == positionCoordinate.getRowPosition()) {
            selected = true;
            break;
        }
    }
    Assert.assertTrue(selected);
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)

Example 23 with PositionCoordinate

use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.

the class InternalPasteDataCommandHandler method doCommand.

@Override
protected boolean doCommand(PasteDataCommand command) {
    if (this.clipboard.getCopiedCells() != null) {
        preInternalPaste();
        PositionCoordinate coord = this.selectionLayer.getSelectionAnchor();
        int pasteColumn = coord.getColumnPosition();
        int pasteRow = coord.getRowPosition();
        for (ILayerCell[] cells : this.clipboard.getCopiedCells()) {
            for (ILayerCell cell : cells) {
                if (EditUtils.isCellEditable(this.selectionLayer, command.configRegistry, new PositionCoordinate(this.selectionLayer, pasteColumn, pasteRow))) {
                    this.selectionLayer.doCommand(new UpdateDataCommand(this.selectionLayer, pasteColumn, pasteRow, getPasteValue(cell, pasteColumn, pasteRow)));
                }
                pasteColumn++;
                if (pasteColumn >= this.selectionLayer.getColumnCount()) {
                    break;
                }
            }
            pasteRow++;
            pasteColumn = coord.getColumnPosition();
        }
        postInternalPaste();
    }
    return true;
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 24 with PositionCoordinate

use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.

the class FillHandleDragMode method mouseDown.

@Override
public void mouseDown(NatTable natTable, MouseEvent event) {
    PositionCoordinate[] selectedCellPositions = this.selectionLayer.getSelectedCellPositions();
    if (selectedCellPositions.length > 0) {
        this.startEvent = event;
        this.selectionCell = this.selectionLayer.getCellByPosition(selectedCellPositions[0].columnPosition, selectedCellPositions[0].rowPosition);
        this.startIndex = new Point(this.selectionCell.getColumnIndex(), this.selectionCell.getRowIndex());
    }
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Point(org.eclipse.swt.graphics.Point)

Example 25 with PositionCoordinate

use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.

the class FillHandlePasteCommandHandler method doCommand.

@Override
public boolean doCommand(ILayer targetLayer, FillHandlePasteCommand command) {
    if (this.clipboard.getCopiedCells() != null) {
        int pasteColumn = -1;
        int pasteRow = -1;
        int pasteWidth = this.clipboard.getCopiedCells().length;
        int pasteHeight = this.clipboard.getCopiedCells()[0].length;
        Rectangle handleRegion = this.selectionLayer.getFillHandleRegion();
        if (handleRegion != null) {
            pasteColumn = handleRegion.x;
            pasteRow = handleRegion.y;
            pasteWidth = handleRegion.width;
            pasteHeight = handleRegion.height;
        } else {
            PositionCoordinate coord = this.selectionLayer.getSelectionAnchor();
            pasteColumn = coord.getColumnPosition();
            pasteRow = coord.getRowPosition();
        }
        int pasteStartColumn = pasteColumn;
        int rowStartAdjustment = 0;
        if (command.direction == MoveDirectionEnum.UP) {
            rowStartAdjustment = pasteHeight % this.clipboard.getCopiedCells().length;
        }
        int columnStartAdjustment = 0;
        if (command.direction == MoveDirectionEnum.LEFT) {
            columnStartAdjustment = pasteWidth % this.clipboard.getCopiedCells()[0].length;
        }
        for (int i = 0; i < pasteHeight; i++) {
            ILayerCell[] cells = this.clipboard.getCopiedCells()[(i + rowStartAdjustment) % this.clipboard.getCopiedCells().length];
            for (int j = 0; j < pasteWidth; j++) {
                ILayerCell cell = cells[(j + columnStartAdjustment) % this.clipboard.getCopiedCells()[0].length];
                Object cellValue = getPasteValue(cell, command, pasteColumn, pasteRow);
                if (EditUtils.isCellEditable(this.selectionLayer, command.configRegistry, new PositionCoordinate(this.selectionLayer, pasteColumn, pasteRow))) {
                    this.selectionLayer.doCommand(new UpdateDataCommand(this.selectionLayer, pasteColumn, pasteRow, cellValue));
                }
                pasteColumn++;
                if (pasteColumn >= this.selectionLayer.getColumnCount()) {
                    break;
                }
            }
            pasteRow++;
            pasteColumn = pasteStartColumn;
        }
    }
    return true;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Aggregations

PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)97 Test (org.junit.Test)55 SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)15 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)10 Rectangle (org.eclipse.swt.graphics.Rectangle)9 SelectRegionCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand)7 ArrayList (java.util.ArrayList)5 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)5 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)5 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)4 ViewportSelectColumnGroupCommand (org.eclipse.nebula.widgets.nattable.group.command.ViewportSelectColumnGroupCommand)4 SearchEvent (org.eclipse.nebula.widgets.nattable.search.event.SearchEvent)4 SelectAllCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectAllCommand)4 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)3 HashSet (java.util.HashSet)2 Pattern (java.util.regex.Pattern)2 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)2 ColumnPositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate)2 RowPositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate)2 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)2