Search in sources :

Example 1 with SelectRowsCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.

the class SelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionOnClearingTableWithRowStructuralRefresh.

@Test
public void shouldClearSelectionOnClearingTableWithRowStructuralRefresh() throws Exception {
    List<RowDataFixture> listFixture = RowDataListFixture.getList(10);
    IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<RowDataFixture>(listFixture, new ReflectiveColumnPropertyAccessor<RowDataFixture>(RowDataListFixture.getPropertyNames()));
    GridLayerFixture gridLayer = new GridLayerFixture(bodyDataProvider);
    NatTable nattable = new NatTableFixture(gridLayer, false);
    DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    SelectionLayer selectionLayer = gridLayer.getBodyLayer().getSelectionLayer();
    // test SelectionModel updates
    assertEquals(0, selectionLayer.getFullySelectedRowPositions().length);
    nattable.doCommand(new SelectRowsCommand(nattable, 1, 1, false, false));
    assertEquals(1, selectionLayer.getFullySelectedRowPositions().length);
    // Ford motor at top and selected
    assertEquals("B Ford Motor", nattable.getDataValueByPosition(2, 1).toString());
    Range selection = selectionLayer.getSelectedRowPositions().iterator().next();
    assertEquals("B Ford Motor", listFixture.get(selection.start).getSecurity_description());
    // clear the table
    listFixture.clear();
    // fire event to trigger structural refresh
    bodyDataLayer.fireLayerEvent(new RowStructuralRefreshEvent(bodyDataLayer));
    // row count of 1 for NatTable because of header
    assertEquals(1, nattable.getRowCount());
    assertTrue("selection is not empty", selectionLayer.getSelectedCells().isEmpty());
    assertTrue("selection model is not empty", selectionLayer.getSelectionModel().getSelections().isEmpty());
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) GridLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 2 with SelectRowsCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.

the class SelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionOnClearingTableWithStructuralRefresh.

@Test
public void shouldClearSelectionOnClearingTableWithStructuralRefresh() throws Exception {
    List<RowDataFixture> listFixture = RowDataListFixture.getList(10);
    IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<RowDataFixture>(listFixture, new ReflectiveColumnPropertyAccessor<RowDataFixture>(RowDataListFixture.getPropertyNames()));
    GridLayerFixture gridLayer = new GridLayerFixture(bodyDataProvider);
    NatTable nattable = new NatTableFixture(gridLayer, false);
    DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    SelectionLayer selectionLayer = gridLayer.getBodyLayer().getSelectionLayer();
    // test SelectionModel updates
    assertEquals(0, selectionLayer.getFullySelectedRowPositions().length);
    nattable.doCommand(new SelectRowsCommand(nattable, 1, 1, false, false));
    assertEquals(1, selectionLayer.getFullySelectedRowPositions().length);
    // Ford motor at top and selected
    assertEquals("B Ford Motor", nattable.getDataValueByPosition(2, 1).toString());
    Range selection = selectionLayer.getSelectedRowPositions().iterator().next();
    assertEquals("B Ford Motor", listFixture.get(selection.start).getSecurity_description());
    // clear the table
    listFixture.clear();
    // fire event to trigger structural refresh
    bodyDataLayer.fireLayerEvent(new StructuralRefreshEvent(bodyDataLayer));
    // row count of 1 for NatTable because of header
    assertEquals(1, nattable.getRowCount());
    assertTrue("selection is not empty", selectionLayer.getSelectedCells().isEmpty());
    assertTrue("selection model is not empty", selectionLayer.getSelectionModel().getSelections().isEmpty());
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) StructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent) RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) GridLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 3 with SelectRowsCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.

the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRetainRowSelectionOnUpdates.

@Test
public void shouldRetainRowSelectionOnUpdates() 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());
    this.listFixture.add(0, RowDataFixture.getInstance("Tata motors", "A"));
    // fire event to trigger structural refresh
    this.bodyDataLayer.fireLayerEvent(new StructuralRefreshEvent(this.bodyDataLayer));
    // Tata motors at top but Ford motors still selected
    assertEquals("Tata motors", this.nattable.getDataValueByPosition(2, 1).toString());
    assertEquals("B Ford Motor", getSelected().getSecurity_description());
}
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 4 with SelectRowsCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.

the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionOnClearingTableWithRowStructuralRefresh.

@Test
public void shouldClearSelectionOnClearingTableWithRowStructuralRefresh() 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 RowStructuralRefreshEvent(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 : RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 5 with SelectRowsCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.

the class PreserveSelectionModelStructuralChangeEventHandlerTest 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)

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