use of org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent 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.event.RowSelectionEvent 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);
}
use of org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent 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());
}
use of org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent 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);
}
use of org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent in project nebula.widgets.nattable by eclipse.
the class Selection_events method addCustomSelectionBehaviour.
private void addCustomSelectionBehaviour() {
this.nattable.addLayerListener(new ILayerListener() {
// Default selection behavior selects cells by default.
@Override
public void handleLayerEvent(ILayerEvent event) {
if (event instanceof CellSelectionEvent) {
CellSelectionEvent cellEvent = (CellSelectionEvent) event;
log("Selected cell: [" + cellEvent.getRowPosition() + ", " + cellEvent.getColumnPosition() + "], " + Selection_events.this.nattable.getDataValueByPosition(cellEvent.getColumnPosition(), cellEvent.getRowPosition()));
}
}
});
// Events are fired whenever selection occurs. These can be use to
// trigger
// external actions as required. Also you can use this data to pull out
// the backing data from the IRowDataProvider. Example:
// rowDataProvider.getRowObject(natTable.getRowIndexByPosition(selectedRowPosition));
this.nattable.addLayerListener(new ILayerListener() {
@Override
public void handleLayerEvent(ILayerEvent event) {
if (event instanceof RowSelectionEvent) {
RowSelectionEvent rowEvent = (RowSelectionEvent) event;
log("Selected Row: " + ObjectUtils.toString(rowEvent.getRowPositionRanges()));
}
}
});
this.nattable.addLayerListener(new ILayerListener() {
@Override
public void handleLayerEvent(ILayerEvent event) {
if (event instanceof ColumnSelectionEvent) {
ColumnSelectionEvent columnEvent = (ColumnSelectionEvent) event;
log("Selected Column: " + columnEvent.getColumnPositionRanges());
}
}
});
}
Aggregations