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());
}
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);
}
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;
}
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());
}
}
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;
}
Aggregations