use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.
the class RowSelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionOnClearingTableWithStructuralRefresh.
@Test
public void shouldClearSelectionOnClearingTableWithStructuralRefresh() throws Exception {
assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(0, this.selectionLayer.getSelectedRowCount());
this.nattable.doCommand(new SelectRowsCommand(this.nattable, 1, 1, false, false));
assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(1, this.selectionLayer.getSelectedRowCount());
// Ford motor at top and selected
assertEquals("B Ford Motor", this.nattable.getDataValueByPosition(2, 1).toString());
assertEquals("B Ford Motor", getSelected().getSecurity_description());
// clear the table
this.listFixture.clear();
// fire event to trigger structural refresh
this.bodyDataLayer.fireLayerEvent(new StructuralRefreshEvent(this.bodyDataLayer));
// row count of 1 for NatTable because of header
assertEquals(1, this.nattable.getRowCount());
assertEquals(0, this.selectionLayer.getSelectedRowCount());
assertTrue("selection model is not empty", this.selectionLayer.getSelectionModel().getSelections().isEmpty());
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.
the class RowSelectionModelStructuralChangeEventHandlerTest method shouldOnlyRemoveSelectionForDeleted.
@Test
public void shouldOnlyRemoveSelectionForDeleted() {
assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(0, this.selectionLayer.getSelectedRowCount());
this.nattable.doCommand(new SelectRowsCommand(this.nattable, 1, new int[] { 1, 2 }, true, false, 1));
assertEquals(2, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(2, this.selectionLayer.getSelectedRowCount());
// Ford motor at top and selected
assertEquals("B Ford Motor", this.nattable.getDataValueByPosition(2, 1).toString());
boolean fordFound = false;
boolean alphabetFound = false;
for (Range selection : this.selectionLayer.getSelectedRowPositions()) {
for (int i = selection.start; i < selection.end; i++) {
if ("B Ford Motor".equals(this.listFixture.get(i).getSecurity_description())) {
fordFound = true;
}
if ("A Alphabet Co.".equals(this.listFixture.get(i).getSecurity_description())) {
alphabetFound = true;
}
}
}
assertTrue("B Ford Motor not found", fordFound);
assertTrue("A Alphabet Co. not found", alphabetFound);
this.listFixture.remove(0);
// fire event to trigger structural refresh
this.bodyDataLayer.fireLayerEvent(new RowDeleteEvent(this.bodyDataLayer, 0));
// another value on top now
assertEquals("A Alphabet Co.", this.nattable.getDataValueByPosition(2, 1).toString());
assertEquals("A Alphabet Co.", getSelected().getSecurity_description());
assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(1, this.selectionLayer.getSelectedRowCount());
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.
the class RowSelectionTest method shouldSetAnchorWithInitialShiftKeyPressed.
@Test
public void shouldSetAnchorWithInitialShiftKeyPressed() {
// start from a clear selection state
this.selectionLayer.clear();
this.selectionLayer.doCommand(new SelectRowsCommand(this.selectionLayer, 0, 4, true, false));
assertEquals(0, this.selectionLayer.getSelectionAnchor().getColumnPosition());
assertEquals(4, this.selectionLayer.getSelectionAnchor().getRowPosition());
assertFalse("row 3 fully selected", this.selectionLayer.isRowPositionFullySelected(3));
assertTrue("row 4 not fully selected", this.selectionLayer.isRowPositionFullySelected(4));
assertFalse("row 5 fully selected", this.selectionLayer.isRowPositionFullySelected(5));
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.
the class RowSelectionTest method shouldNotIncludeDeselectedCellsWithCtrlModifier.
@Test
public void shouldNotIncludeDeselectedCellsWithCtrlModifier() {
// test a previous bug where single deselected cells where added to the
// selection with following modifier selections
// start from a clear selection state
this.selectionLayer.clear();
// select a single cell
this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 0, 2, false, false));
// deselect the cell again
this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 0, 2, false, true));
// trigger selection of row 4 with ctrl
this.selectionLayer.doCommand(new SelectRowsCommand(this.selectionLayer, 0, 4, false, true));
assertEquals(0, this.selectionLayer.getSelectionAnchor().getColumnPosition());
assertEquals(4, this.selectionLayer.getSelectionAnchor().getRowPosition());
assertFalse("[0, 2] is selected", this.selectionLayer.isCellPositionSelected(0, 2));
assertTrue("row 4 not fully selected", this.selectionLayer.isRowPositionFullySelected(4));
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.
the class RowSelectionTest method onlyOneCellSelectedAtAnyTime.
@Test
public void onlyOneCellSelectedAtAnyTime() {
this.selectionLayer.getSelectionModel().setMultipleSelectionAllowed(false);
this.selectionLayer.clear();
this.selectionLayer.doCommand(new SelectRowsCommand(this.selectionLayer, 1, 0, false, true));
Collection<PositionCoordinate> cells = ArrayUtil.asCollection(this.selectionLayer.getSelectedCellPositions());
assertEquals(1, cells.size());
assertEquals(1, this.selectionLayer.getSelectedRowPositions().size());
assertEquals(1, this.selectionLayer.getSelectedRowCount());
// select another row with control mask
this.selectionLayer.doCommand(new SelectRowsCommand(this.selectionLayer, 1, 2, false, true));
cells = ArrayUtil.asCollection(this.selectionLayer.getSelectedCellPositions());
assertEquals(1, cells.size());
assertEquals(1, this.selectionLayer.getSelectedRowPositions().size());
assertEquals(1, this.selectionLayer.getSelectedRowCount());
// select additional rows with shift mask
this.selectionLayer.doCommand(new SelectRowsCommand(this.selectionLayer, 1, 5, true, false));
cells = ArrayUtil.asCollection(this.selectionLayer.getSelectedCellPositions());
assertEquals(1, cells.size());
assertEquals(1, this.selectionLayer.getSelectedRowPositions().size());
assertEquals(1, this.selectionLayer.getSelectedRowCount());
}
Aggregations