Search in sources :

Example 6 with CellSelectionEvent

use of org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent 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

CellSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent)6 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)4 ILayerEvent (org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent)4 RowSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent)3 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)2 ColumnSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.ColumnSelectionEvent)2 Test (org.junit.Test)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)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 CellEditorCreatedEvent (org.eclipse.nebula.widgets.nattable.edit.CellEditorCreatedEvent)1 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)1 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)1 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)1 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)1 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)1