Search in sources :

Example 26 with ILayerEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent in project nebula.widgets.nattable by eclipse.

the class AbstractLayer method handleLayerEvent.

/**
 * Handle layer event notification. Convert it to your context and propagate
 * <i>UP</i>.
 *
 * If you override this method you <strong>MUST NOT FORGET</strong> to raise
 * the event up the layer stack by calling
 * <code>super.fireLayerEvent(event)</code> - unless you plan to eat the
 * event yourself.
 */
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void handleLayerEvent(ILayerEvent event) {
    Map<Class<? extends ILayerEvent>, ILayerEventHandler<? extends ILayerEvent>> currentEventHandlers;
    this.eventHelperLock.readLock().lock();
    try {
        currentEventHandlers = this.eventHandlers;
    } finally {
        this.eventHelperLock.readLock().unlock();
    }
    for (Class<? extends ILayerEvent> eventClass : currentEventHandlers.keySet()) {
        if (eventClass.isInstance(event)) {
            ILayerEventHandler eventHandler = currentEventHandlers.get(eventClass);
            eventHandler.handleLayerEvent(event);
        }
    }
    // Pass on the event to our parent
    if (event.convertToLocal(this)) {
        fireLayerEvent(event);
    }
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) ILayerEventHandler(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEventHandler)

Example 27 with ILayerEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent in project nebula.widgets.nattable by eclipse.

the class AbstractLayer method fireLayerEvent.

/**
 * Pass the event to all the {@link ILayerListener} registered on this
 * layer. A cloned copy is passed to each listener.
 */
@Override
public void fireLayerEvent(ILayerEvent event) {
    if (this.listeners.size() > 0) {
        Iterator<ILayerListener> it = this.listeners.iterator();
        boolean isLastListener = false;
        do {
            ILayerListener l = it.next();
            // Lookahead
            isLastListener = !it.hasNext();
            // Fire cloned event to first n-1 listeners; fire original event
            // to last listener
            ILayerEvent eventToFire = isLastListener ? event : event.cloneEvent();
            l.handleLayerEvent(eventToFire);
        } while (!isLastListener);
    }
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent)

Example 28 with ILayerEvent

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

ILayerEvent (org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent)28 Test (org.junit.Test)17 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)14 HashSet (java.util.HashSet)4 IVisualChangeEvent (org.eclipse.nebula.widgets.nattable.layer.event.IVisualChangeEvent)4 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)4 CellSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent)4 BaseDataLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.BaseDataLayerFixture)4 Rectangle (org.eclipse.swt.graphics.Rectangle)4 BigDecimal (java.math.BigDecimal)3 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)3 CellVisualChangeEvent (org.eclipse.nebula.widgets.nattable.layer.event.CellVisualChangeEvent)3 ColumnReorderEvent (org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent)3 RowSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)2 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)2 ColumnReorderLayer (org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer)2 ColumnResizeEvent (org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent)2