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);
}
}
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);
}
}
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());
}
}
});
}
Aggregations