Search in sources :

Example 26 with SelectRowsCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand 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 27 with SelectRowsCommand

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

the class RowSelectionModelStructuralChangeEventHandlerTest method shouldFireRowSelectionEventOnDelete.

@Test
public void shouldFireRowSelectionEventOnDelete() {
    // Select single row
    this.nattable.doCommand(new SelectRowsCommand(this.nattable, 5, 5, false, false));
    assertEquals(1, this.selectionLayer.getSelectedRowCount());
    assertEquals(1, this.listener.getEventsCount());
    assertTrue(this.listener.containsInstanceOf(RowSelectionEvent.class));
    RowSelectionEvent event = (RowSelectionEvent) this.listener.getReceivedEvents().get(0);
    assertEquals(4, event.getRowPositionRanges().iterator().next().start);
    assertEquals(5, event.getRowPositionRanges().iterator().next().end);
    // Delete the selected row
    this.listFixture.remove(4);
    this.bodyDataLayer.fireLayerEvent(new RowDeleteEvent(this.bodyDataLayer, 4));
    assertEquals(0, this.selectionLayer.getSelectedRowCount());
    assertEquals(3, this.listener.getEventsCount());
    assertTrue(this.listener.containsInstanceOf(RowSelectionEvent.class));
    event = (RowSelectionEvent) this.listener.getReceivedEvents().get(1);
    assertEquals(1, event.getRowPositionRanges().size());
    assertEquals(4, event.getRowPositionRanges().iterator().next().start);
    assertEquals(5, event.getRowPositionRanges().iterator().next().end);
}
Also used : RowSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 28 with SelectRowsCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand 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)

Example 29 with SelectRowsCommand

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

the class RowSelectionModelStructuralChangeEventHandlerTest method shouldFireRowSelectionEventOnClear.

@Test
public void shouldFireRowSelectionEventOnClear() {
    // Select single row
    this.nattable.doCommand(new SelectRowsCommand(this.nattable, 5, 5, false, false));
    assertEquals(1, this.selectionLayer.getSelectedRowCount());
    assertEquals(1, this.listener.getEventsCount());
    assertTrue(this.listener.containsInstanceOf(RowSelectionEvent.class));
    RowSelectionEvent event = (RowSelectionEvent) this.listener.getReceivedEvents().get(0);
    assertEquals(4, event.getRowPositionRanges().iterator().next().start);
    assertEquals(5, event.getRowPositionRanges().iterator().next().end);
    // clear
    this.listFixture.clear();
    this.bodyDataLayer.fireLayerEvent(new StructuralRefreshEvent(this.bodyDataLayer));
    assertEquals(0, this.selectionLayer.getSelectedRowCount());
    assertEquals(3, this.listener.getEventsCount());
    assertTrue(this.listener.containsInstanceOf(RowSelectionEvent.class));
    event = (RowSelectionEvent) this.listener.getReceivedEvents().get(1);
    // since the underlying collection is cleared the ranges should be empty
    assertEquals(0, event.getRowPositionRanges().size());
}
Also used : RowSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent) 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 30 with SelectRowsCommand

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

the class RowSelectionModelStructuralChangeEventHandlerTest method shouldFireRowSelectionEventOnDeselect.

@Test
public void shouldFireRowSelectionEventOnDeselect() {
    // Select single row
    this.nattable.doCommand(new SelectRowsCommand(this.nattable, 5, 5, false, false));
    assertEquals(1, this.selectionLayer.getSelectedRowCount());
    assertEquals(1, this.listener.getEventsCount());
    assertTrue(this.listener.containsInstanceOf(RowSelectionEvent.class));
    RowSelectionEvent event = (RowSelectionEvent) this.listener.getReceivedEvents().get(0);
    assertEquals(4, event.getRowPositionRanges().iterator().next().start);
    assertEquals(5, event.getRowPositionRanges().iterator().next().end);
    // Deselect single row again
    this.nattable.doCommand(new SelectRowsCommand(this.nattable, 5, 5, false, true));
    assertEquals(0, this.selectionLayer.getSelectedRowCount());
    assertEquals(2, this.listener.getEventsCount());
    assertTrue(this.listener.containsInstanceOf(RowSelectionEvent.class));
    event = (RowSelectionEvent) this.listener.getReceivedEvents().get(1);
    assertEquals(1, event.getRowPositionRanges().size());
    assertEquals(4, event.getRowPositionRanges().iterator().next().start);
    assertEquals(5, event.getRowPositionRanges().iterator().next().end);
}
Also used : RowSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent) 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