Commit dfd5c10d authored by Nico Mack's avatar Nico Mack

Added notification suspension mechanism

parent 1c08b9c7
......@@ -25,6 +25,9 @@ import lu.list.itis.dkd.tui.event.conditional.Conditional;
import lu.list.itis.dkd.tui.feature.selection.Selectable;
import lu.list.itis.dkd.tui.widget.corona.builder.BaseSelectableCoronaBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
......@@ -44,6 +47,14 @@ public abstract class SelectableCorona extends FadingCorona implements Selectabl
protected Condition<Integer> condition;
protected List<SelectionListener> listeners;
protected int suspendNotificationSemaphore = 0;
// ***************************************************************************
// * Constants *
// ***************************************************************************
private static final Logger LOGGER = LoggerFactory.getLogger(SelectableCorona.class.getSimpleName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
......@@ -122,6 +133,40 @@ public abstract class SelectableCorona extends FadingCorona implements Selectabl
}
}
// ---------------------------------------------------------------------------
/**
* 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 SelectableCorona with Index {} raised to {}!", this.index, suspendNotificationSemaphore); //$NON-NLS-1$
} else if (suspendNotificationSemaphore > 0) {
suspendNotificationSemaphore--;
if (LOGGER.isTraceEnabled())
LOGGER.trace("Suspend Notification Semaphore of SelectableCorona with Index {} raised to {}!", this.index, suspendNotificationSemaphore); //$NON-NLS-1$
}
}
// ---------------------------------------------------------------------------
/**
* @return
*/
// ---------------------------------------------------------------------------
public boolean notificationSuspended() {
return (suspendNotificationSemaphore > 0);
}
// ---------------------------------------------------------------------------
/**
*
......@@ -129,6 +174,10 @@ public abstract class SelectableCorona extends FadingCorona implements Selectabl
// ---------------------------------------------------------------------------
public void notifyListeners() {
if (this.notificationSuspended()) {
return;
}
SelectionEvent event = new SelectionEvent(this, this.isSelected);
for (SelectionListener listener : listeners) {
......
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