use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand 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);
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.
the class SelectionEventsTest method shouldFireRowSelectionEvent.
@Test
public void shouldFireRowSelectionEvent() throws Exception {
// Select single row
this.nattable.doCommand(new SelectRowsCommand(this.nattable, 5, 5, NO_SHIFT, NO_CTRL));
assertEquals(1, this.listener.getEventsCount());
assertTrue(this.listener.containsInstanceOf(RowSelectionEvent.class));
RowSelectionEvent event = (RowSelectionEvent) this.listener.getReceivedEvents().get(0);
assertEquals(5, event.getRowPositionRanges().iterator().next().start);
assertEquals(6, event.getRowPositionRanges().iterator().next().end);
// Select additional rows with shift
this.nattable.doCommand(new SelectRowsCommand(this.nattable, 5, 7, WITH_SHIFT, NO_CTRL));
assertEquals(2, this.listener.getEventsCount());
assertTrue(this.listener.containsInstanceOf(RowSelectionEvent.class));
event = (RowSelectionEvent) this.listener.getReceivedEvents().get(1);
assertEquals(1, event.getRowPositionRanges().size());
assertEquals(5, event.getRowPositionRanges().iterator().next().start);
assertEquals(8, event.getRowPositionRanges().iterator().next().end);
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.
the class RowSelectionModelStructuralChangeEventHandlerTest method shouldRemoveSelectionOnDelete.
@Test
public void shouldRemoveSelectionOnDelete() {
assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
this.nattable.doCommand(new SelectRowsCommand(this.nattable, 1, 1, false, false));
assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
// 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.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());
// selection should be empty since the selected row was deleted
assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(0, this.selectionLayer.getSelectedRowCount());
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.
the class RowSelectionModelStructuralChangeEventHandlerTest method shouldFireRowSelectionEvent.
@Test
public void shouldFireRowSelectionEvent() {
// 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);
// Select additional rows with shift
this.nattable.doCommand(new SelectRowsCommand(this.nattable, 5, 7, true, false));
assertEquals(3, 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(7, event.getRowPositionRanges().iterator().next().end);
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand in project nebula.widgets.nattable by eclipse.
the class RowSelectionModelStructuralChangeEventHandlerTest 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());
}
Aggregations