Search in sources :

Example 11 with RowSelectionEvent

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);
}
Also used : RowSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 12 with RowSelectionEvent

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);
}
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 13 with RowSelectionEvent

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());
}
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 14 with RowSelectionEvent

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);
}
Also used : RowSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 15 with RowSelectionEvent

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());
            }
        }
    });
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) CellSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent) RowSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent) ColumnSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.ColumnSelectionEvent) ILayerListener(org.eclipse.nebula.widgets.nattable.layer.ILayerListener)

Aggregations

RowSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent)15 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)9 Test (org.junit.Test)7 SelectRowsCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand)5 HashSet (java.util.HashSet)3 ViewportSelectColumnGroupCommand (org.eclipse.nebula.widgets.nattable.group.command.ViewportSelectColumnGroupCommand)3 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)3 ILayerEvent (org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent)3 CellSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent)3 HashMap (java.util.HashMap)2 ColumnSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.ColumnSelectionEvent)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Map (java.util.Map)1 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)1 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)1 ReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor)1 Person (org.eclipse.nebula.widgets.nattable.dataset.person.Person)1