Commit cba7d1f2 authored by Nico Mack's avatar Nico Mack

added notification suspension mechanism.

parent 1bf6a021
......@@ -26,6 +26,8 @@ import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import org.jdom2.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collection;
......@@ -49,6 +51,14 @@ public class SelectionGroup implements SelectionListener {
private List<Selectable> members;
protected List<SelectionListener> listeners;
protected int suspendNotificationSemaphore = 0;
// ***************************************************************************
// * Constants
// ***************************************************************************
private static final Logger LOGGER = LoggerFactory.getLogger(SelectionGroup.class.getSimpleName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
......@@ -178,11 +188,45 @@ public class SelectionGroup implements SelectionListener {
// ---------------------------------------------------------------------------
public void notifyListeners(SelectionEvent event) {
if (this.notificationSuspended()) {
return;
}
for (SelectionListener listener : listeners) {
listener.selectionStateChanged(event);
}
}
// ---------------------------------------------------------------------------
/**
* Sets the suspendNotification flag for InputChangeListeners. When suspend, InputChangeListeners
* will not be notified on value changes.
*
* @param suspend
* specify <code>true</true> to suspend listener notification, <code>false</code> to enable
* notification of InputChangeListerners on value change.
* @see #consolidateListeners
*/
// ---------------------------------------------------------------------------
public synchronized void suspendListenerNotification(boolean suspend) {
if (suspend) {
suspendNotificationSemaphore++;
if (LOGGER.isTraceEnabled())
LOGGER.trace("Suspend Notification Semaphore of Selection Group {} raised to {}!", this.name, suspendNotificationSemaphore); //$NON-NLS-1$
} else if (suspendNotificationSemaphore > 0) {
suspendNotificationSemaphore--;
if (LOGGER.isTraceEnabled())
LOGGER.trace("Suspend Notification Semaphore of Selection Group {} lowered to {}!", this.name, suspendNotificationSemaphore); //$NON-NLS-1$
}
}
// ---------------------------------------------------------------------------
public boolean notificationSuspended() {
return (suspendNotificationSemaphore > 0);
}
// ---------------------------------------------------------------------------
/**
* Simple getter method for name.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment