use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.
the class CellSelectionTest method onlyOneCellSelectedAtAnyTime.
@Test
public void onlyOneCellSelectedAtAnyTime() {
this.selectionLayer.getSelectionModel().setMultipleSelectionAllowed(false);
this.selectionLayer.clear();
this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 1, 0, false, true));
Collection<PositionCoordinate> cells = ArrayUtil.asCollection(this.selectionLayer.getSelectedCellPositions());
Assert.assertEquals(1, cells.size());
Assert.assertTrue(cells.contains(new PositionCoordinate(this.selectionLayer, 1, 0)));
// select another cell with control mask
this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 2, 0, false, true));
cells = ArrayUtil.asCollection(this.selectionLayer.getSelectedCellPositions());
Assert.assertEquals(1, cells.size());
Assert.assertTrue(cells.contains(new PositionCoordinate(this.selectionLayer, 2, 0)));
// select additional cells with shift mask
// only the first cell should be selected afterwards
this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 2, 10, true, false));
cells = ArrayUtil.asCollection(this.selectionLayer.getSelectedCellPositions());
Assert.assertEquals(1, cells.size());
Assert.assertTrue(cells.contains(new PositionCoordinate(this.selectionLayer, 2, 0)));
// select additional cells with shift mask
// only the first cell should be selected afterwards
this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 10, 0, true, false));
cells = ArrayUtil.asCollection(this.selectionLayer.getSelectedCellPositions());
Assert.assertEquals(1, cells.size());
Assert.assertTrue(cells.contains(new PositionCoordinate(this.selectionLayer, 2, 0)));
}
use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate 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.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.
the class LayerCommandUtil method convertPositionToTargetContext.
public static PositionCoordinate convertPositionToTargetContext(PositionCoordinate positionCoordinate, ILayer targetLayer) {
ILayer layer = positionCoordinate.getLayer();
if (layer == targetLayer) {
return positionCoordinate;
}
int columnPosition = positionCoordinate.getColumnPosition();
int underlyingColumnPosition = layer.localToUnderlyingColumnPosition(columnPosition);
if (underlyingColumnPosition < 0) {
return null;
}
int rowPosition = positionCoordinate.getRowPosition();
int underlyingRowPosition = layer.localToUnderlyingRowPosition(rowPosition);
if (underlyingRowPosition < 0) {
return null;
}
ILayer underlyingLayer = layer.getUnderlyingLayerByPosition(columnPosition, rowPosition);
if (underlyingLayer == null) {
return null;
}
return convertPositionToTargetContext(new PositionCoordinate(underlyingLayer, underlyingColumnPosition, underlyingRowPosition), targetLayer);
}
use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.
the class EditSelectionCommandHandler method doCommand.
@Override
public boolean doCommand(EditSelectionCommand command) {
Composite parent = command.getParent();
IConfigRegistry configRegistry = command.getConfigRegistry();
Character initialValue = command.getCharacter();
if (EditUtils.allCellsEditable(this.selectionLayer, configRegistry) && EditUtils.isEditorSame(this.selectionLayer, configRegistry) && EditUtils.isConverterSame(this.selectionLayer, configRegistry) && EditUtils.activateLastSelectedCellEditor(this.selectionLayer, configRegistry, command.isByTraversal())) {
// check how many cells are selected
Collection<ILayerCell> selectedCells = EditUtils.getSelectedCellsForEditing(this.selectionLayer);
if (selectedCells.size() == 1) {
// editing is triggered by key for a single cell
// we need to fire the InlineCellEditEvent here because we
// don't know the correct bounds of the cell to edit inline
// corresponding to the NatTable.
// On firing the event, a translation process is triggered,
// converting the information to the correct values
// needed for inline editing
ILayerCell cell = selectedCells.iterator().next();
this.selectionLayer.fireLayerEvent(new InlineCellEditEvent(this.selectionLayer, new PositionCoordinate(this.selectionLayer, cell.getOriginColumnPosition(), cell.getOriginRowPosition()), parent, configRegistry, (initialValue != null ? initialValue : cell.getDataValue())));
} else if (selectedCells.size() > 1) {
// determine the initial value
Object initialEditValue = initialValue;
if (initialValue == null && EditUtils.isValueSame(this.selectionLayer)) {
ILayerCell cell = selectedCells.iterator().next();
initialEditValue = this.selectionLayer.getDataValueByPosition(cell.getColumnPosition(), cell.getRowPosition());
}
EditController.editCells(selectedCells, parent, initialEditValue, configRegistry);
}
}
// successful or not
return true;
}
use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.
the class FreezeEventHandler method handleLayerEvent.
@Override
public void handleLayerEvent(IStructuralChangeEvent event) {
PositionCoordinate topLeftPosition = this.freezeLayer.getTopLeftPosition();
PositionCoordinate bottomRightPosition = this.freezeLayer.getBottomRightPosition();
Collection<StructuralDiff> columnDiffs = event.getColumnDiffs();
if (columnDiffs != null) {
int leftOffset = 0;
int rightOffset = 0;
for (StructuralDiff columnDiff : columnDiffs) {
switch(columnDiff.getDiffType()) {
case ADD:
Range afterPositionRange = columnDiff.getAfterPositionRange();
if (afterPositionRange.start < topLeftPosition.columnPosition) {
leftOffset += afterPositionRange.size();
}
if (afterPositionRange.start <= bottomRightPosition.columnPosition) {
rightOffset += afterPositionRange.size();
}
break;
case DELETE:
Range beforePositionRange = columnDiff.getBeforePositionRange();
if (beforePositionRange.start < topLeftPosition.columnPosition) {
leftOffset -= Math.min(beforePositionRange.end, topLeftPosition.columnPosition + 1) - beforePositionRange.start;
}
if (beforePositionRange.start <= bottomRightPosition.columnPosition) {
rightOffset -= Math.min(beforePositionRange.end, bottomRightPosition.columnPosition + 1) - beforePositionRange.start;
}
break;
}
}
topLeftPosition.columnPosition += leftOffset;
bottomRightPosition.columnPosition += rightOffset;
}
Collection<StructuralDiff> rowDiffs = event.getRowDiffs();
if (rowDiffs != null) {
int leftOffset = 0;
int rightOffset = 0;
for (StructuralDiff rowDiff : rowDiffs) {
switch(rowDiff.getDiffType()) {
case ADD:
Range afterPositionRange = rowDiff.getAfterPositionRange();
if (afterPositionRange.start < topLeftPosition.rowPosition) {
leftOffset += afterPositionRange.size();
}
if (afterPositionRange.start <= bottomRightPosition.rowPosition) {
rightOffset += afterPositionRange.size();
}
break;
case DELETE:
Range beforePositionRange = rowDiff.getBeforePositionRange();
if (beforePositionRange.start < topLeftPosition.rowPosition) {
leftOffset -= Math.min(beforePositionRange.end, topLeftPosition.rowPosition + 1) - beforePositionRange.start;
}
if (beforePositionRange.start <= bottomRightPosition.rowPosition) {
rightOffset -= Math.min(beforePositionRange.end, bottomRightPosition.rowPosition + 1) - beforePositionRange.start;
}
break;
}
}
topLeftPosition.rowPosition += leftOffset;
bottomRightPosition.rowPosition += rightOffset;
}
}
Aggregations