use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.
the class FreezeHandlerTest method shouldFreezeRowsAndColumnsBasedOnMultiSelection.
@Test
public void shouldFreezeRowsAndColumnsBasedOnMultiSelection() {
this.compositeFreezeLayer.doCommand(new SelectCellCommand(this.compositeFreezeLayer, 2, 2, false, false));
this.compositeFreezeLayer.doCommand(new SelectCellCommand(this.compositeFreezeLayer, 3, 3, true, false));
// Make sure selection layer processed command
assertEquals(4, this.selectionLayer.getSelectedCellPositions().length);
PositionCoordinate lastSelectedCell = this.selectionLayer.getLastSelectedCellPosition();
assertEquals(3, lastSelectedCell.columnPosition);
assertEquals(3, lastSelectedCell.rowPosition);
// This is what would happen if we selected to freeze from a selected
// cell
this.compositeFreezeLayer.doCommand(new FreezeSelectionCommand());
assertEquals(0, this.freezeLayer.getTopLeftPosition().columnPosition);
assertEquals(0, this.freezeLayer.getTopLeftPosition().rowPosition);
assertNotNull(this.freezeLayer.getBottomRightPosition());
assertEquals(1, this.freezeLayer.getBottomRightPosition().columnPosition);
assertEquals(1, this.freezeLayer.getBottomRightPosition().rowPosition);
// Check viewport origin
assertEquals(2, this.viewportLayer.getMinimumOriginColumnPosition());
assertEquals(2, this.viewportLayer.getMinimumOriginRowPosition());
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.
the class FreezeHandlerTest method shouldFreezeAfterScrolling.
@Test
public void shouldFreezeAfterScrolling() {
// Scroll the viewport to the first column
this.viewportLayer.resetOrigin(this.viewportLayer.getStartXOfColumnPosition(0), this.viewportLayer.getStartYOfRowPosition(0));
this.viewportLayer.setOriginX(this.viewportLayer.getStartXOfColumnPosition(1));
assertEquals(1, this.viewportLayer.getColumnIndexByPosition(0));
this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 3, 3, false, false));
this.compositeFreezeLayer.doCommand(new FreezeSelectionCommand());
// Freezelayer
assertEquals(2, this.freezeLayer.getColumnCount());
// Test Positions
assertEquals(1, this.freezeLayer.getTopLeftPosition().columnPosition);
assertEquals(0, this.freezeLayer.getTopLeftPosition().rowPosition);
assertEquals(2, this.freezeLayer.getBottomRightPosition().columnPosition);
assertEquals(2, this.freezeLayer.getBottomRightPosition().rowPosition);
// Test indexes
assertEquals(1, this.freezeLayer.getColumnIndexByPosition(0));
assertEquals(1, this.freezeLayer.getTopLeftPosition().columnPosition);
assertEquals(0, this.freezeLayer.getTopLeftPosition().rowPosition);
assertEquals(2, this.freezeLayer.getColumnIndexByPosition(this.freezeLayer.getColumnCount() - 1));
assertEquals(2, this.freezeLayer.getBottomRightPosition().columnPosition);
assertEquals(2, this.freezeLayer.getBottomRightPosition().rowPosition);
// Test viewport
assertEquals(3, this.viewportLayer.getMinimumOriginColumnPosition());
assertEquals(3, this.viewportLayer.getMinimumOriginRowPosition());
assertEquals(3, this.viewportLayer.getColumnIndexByPosition(0));
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.
the class FreezeHandlerTest method shouldFreezeRowsAndColumnsBasedOnSelectionInclude.
@Test
public void shouldFreezeRowsAndColumnsBasedOnSelectionInclude() {
this.compositeFreezeLayer.doCommand(new SelectCellCommand(this.compositeFreezeLayer, 2, 2, false, false));
// Make sure selection layer processed command
final PositionCoordinate lastSelectedCell = this.selectionLayer.getLastSelectedCellPosition();
assertEquals(2, lastSelectedCell.columnPosition);
assertEquals(2, lastSelectedCell.rowPosition);
// This is what would happen if we selected to freeze from a selected
// cell
this.compositeFreezeLayer.doCommand(new FreezeSelectionCommand(false, false, true));
assertEquals(0, this.freezeLayer.getTopLeftPosition().columnPosition);
assertEquals(0, this.freezeLayer.getTopLeftPosition().rowPosition);
assertNotNull(this.freezeLayer.getBottomRightPosition());
assertEquals(2, this.freezeLayer.getBottomRightPosition().columnPosition);
assertEquals(2, this.freezeLayer.getBottomRightPosition().rowPosition);
// Check viewport origin
assertEquals(3, this.viewportLayer.getMinimumOriginColumnPosition());
assertEquals(3, this.viewportLayer.getMinimumOriginRowPosition());
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.
the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRemoveCellSelectionOnRowDelete.
@Test
public void shouldRemoveCellSelectionOnRowDelete() {
assertTrue("selection is not empty", this.selectionLayer.getSelectedCells().isEmpty());
this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 1, false, false));
assertEquals(1, this.selectionLayer.getSelectedCells().size());
this.nattable.doCommand(new SelectCellCommand(this.nattable, 2, 1, true, false));
assertEquals(2, this.selectionLayer.getSelectedCells().size());
this.listFixture.remove(0);
// fire event to trigger structural refresh
this.bodyDataLayer.fireLayerEvent(new RowDeleteEvent(this.bodyDataLayer, 0));
Collection<ILayerCell> selectedCells = this.selectionLayer.getSelectedCells();
assertEquals(0, selectedCells.size());
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.
the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRemovePartialSplitCellSelectionOnColumnDelete.
@Test
public void shouldRemovePartialSplitCellSelectionOnColumnDelete() {
assertTrue("selection is not empty", this.selectionLayer.getSelectedCells().isEmpty());
this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 1, false, false));
assertEquals(1, this.selectionLayer.getSelectedCells().size());
this.nattable.doCommand(new SelectCellCommand(this.nattable, 5, 2, true, false));
Collection<ILayerCell> selectedCells = this.selectionLayer.getSelectedCells();
assertEquals(10, selectedCells.size());
boolean[] found = new boolean[5];
for (ILayerCell cell : selectedCells) {
if (cell.getColumnPosition() >= 5) {
fail("wrong column position selected");
} else {
found[cell.getColumnPosition()] = true;
}
}
for (int i = 0; i < found.length; i++) {
assertTrue("columnPosition " + i + " not selected", found[i]);
}
this.nattable.doCommand(new MultiColumnHideCommand(this.nattable, new int[] { 2, 4 }));
selectedCells = this.selectionLayer.getSelectedCells();
assertEquals(6, selectedCells.size());
found = new boolean[3];
for (ILayerCell cell : selectedCells) {
if (cell.getColumnPosition() >= 3) {
fail("wrong column position selected");
} else {
found[cell.getColumnPosition()] = true;
}
}
for (int i = 0; i < found.length; i++) {
assertTrue("columnPosition " + i + " not selected", found[i]);
}
// insert again to verify the column position shift
this.nattable.doCommand(new ShowAllColumnsCommand());
selectedCells = this.selectionLayer.getSelectedCells();
assertEquals(6, selectedCells.size());
found = new boolean[5];
for (ILayerCell cell : selectedCells) {
if (cell.getColumnPosition() >= 5) {
fail("wrong column position selected");
} else {
found[cell.getColumnPosition()] = true;
}
}
for (int i = 0; i < found.length; i++) {
if (i == 0 || i == 2 || i == 4) {
assertTrue("columnPosition " + i + " not selected", found[i]);
}
}
}
Aggregations