Search in sources :

Example 6 with StructuralRefreshEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent in project nebula.widgets.nattable by eclipse.

the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRetainRowSelectionOnMove.

@Test
public void shouldRetainRowSelectionOnMove() 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());
    RowDataFixture ford = getSelected();
    // move selected to the bottom
    this.listFixture.remove(ford);
    this.listFixture.add(ford);
    // fire event to trigger structural refresh
    this.bodyDataLayer.fireLayerEvent(new StructuralRefreshEvent(this.bodyDataLayer));
    // Tata motors at top but Ford motors still selected
    assertEquals("A Alphabet Co.", this.nattable.getDataValueByPosition(2, 1).toString());
    assertEquals("B Ford Motor", getSelected().getSecurity_description());
    assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
    assertEquals(1, this.selectionLayer.getSelectedRowCount());
    assertEquals(this.listFixture.size() - 1, this.selectionLayer.getFullySelectedRowPositions()[0]);
}
Also used : StructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent) RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 7 with StructuralRefreshEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent in project nebula.widgets.nattable by eclipse.

the class SelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionOnStructuralChanges.

@Test
public void shouldClearSelectionOnStructuralChanges() {
    this.selectionModel.addSelection(3, 4);
    Assert.assertFalse(this.selectionModel.isEmpty());
    this.selectionModel.handleLayerEvent(new StructuralRefreshEvent(this.dataLayer));
    Assert.assertTrue(this.selectionModel.isEmpty());
}
Also used : StructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent) RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent) Test(org.junit.Test)

Example 8 with StructuralRefreshEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent in project nebula.widgets.nattable by eclipse.

the class SelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionOnDataUpdates.

@Test
public void shouldClearSelectionOnDataUpdates() 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());
    listFixture.add(0, RowDataFixture.getInstance("Tata motors", "A"));
    // fire event to trigger structural refresh
    bodyDataLayer.fireLayerEvent(new StructuralRefreshEvent(bodyDataLayer));
    assertEquals(0, selectionLayer.getFullySelectedRowPositions().length);
}
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 9 with StructuralRefreshEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent in project nebula.widgets.nattable by eclipse.

the class RowSelectionModelStructuralChangeEventHandlerTest 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 10 with StructuralRefreshEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent in project nebula.widgets.nattable by eclipse.

the class RowSelectionModelStructuralChangeEventHandlerTest method shouldRetainRowSelectionOnMove.

@Test
public void shouldRetainRowSelectionOnMove() 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());
    RowDataFixture ford = getSelected();
    // move selected to the bottom
    this.listFixture.remove(ford);
    this.listFixture.add(ford);
    // fire event to trigger structural refresh
    this.bodyDataLayer.fireLayerEvent(new StructuralRefreshEvent(this.bodyDataLayer));
    // Tata motors at top but Ford motors still selected
    assertEquals("A Alphabet Co.", this.nattable.getDataValueByPosition(2, 1).toString());
    assertEquals("B Ford Motor", getSelected().getSecurity_description());
    assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
    assertEquals(1, this.selectionLayer.getSelectedRowCount());
    assertEquals(this.listFixture.size() - 1, this.selectionLayer.getFullySelectedRowPositions()[0]);
}
Also used : StructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent) RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Aggregations

RowStructuralRefreshEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent)11 StructuralRefreshEvent (org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent)11 Test (org.junit.Test)11 SelectRowsCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand)9 RowDataFixture (org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture)4 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)2 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)2 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)2 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)2 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)2 GridLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture)2 RowSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent)1