Search in sources :

Example 6 with SelectRowsCommand

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());
}
Also used : StructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent) RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 7 with SelectRowsCommand

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());
}
Also used : RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 8 with SelectRowsCommand

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));
}
Also used : SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 9 with SelectRowsCommand

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));
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 10 with SelectRowsCommand

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());
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Aggregations

SelectRowsCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand)35 Test (org.junit.Test)32 RowStructuralRefreshEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent)12 StructuralRefreshEvent (org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent)9 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)5 RowDataFixture (org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture)5 RowDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent)5 RowSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent)5 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)4 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)4 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)2 AbstractDpiConverter (org.eclipse.nebula.widgets.nattable.layer.AbstractDpiConverter)2 IDpiConverter (org.eclipse.nebula.widgets.nattable.layer.IDpiConverter)2 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)2 GridLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture)2 EventList (ca.odell.glazedlists.EventList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1