--- /dev/null
+package jalview.ws2;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import jalview.ws2.WebServiceDiscovererI.OperationsChangeListener;
+import jalview.ws2.operations.Operation;
+
+/**
+ * A helper class that manages a list of OperationsChangeListeners
+ * Used by web service discoverers to store listeners.
+ * @author mmwarowny
+ *
+ */
+public class OperationsChangeListenerList
+{
+ private List<OperationsChangeListener> listeners = new CopyOnWriteArrayList<>();
+ private WebServiceDiscovererI discoverer;
+
+ public OperationsChangeListenerList(WebServiceDiscovererI discoverer)
+ {
+ this.discoverer = discoverer;
+ }
+
+ /**
+ * Add an operations list observer that will be notified of any changes.
+ *
+ * @param listener
+ * operations list listener
+ */
+ public void addListener(OperationsChangeListener listener)
+ {
+ listeners.add(listener);
+ }
+
+ /**
+ * Remove the listener from the observers list.
+ *
+ * @param listener
+ * listener to be removed
+ */
+ public void removeListener(OperationsChangeListener listener)
+ {
+ listeners.remove(listener);
+ }
+
+ /**
+ * Called whenever the list of operations changes. Notifies all listeners of
+ * the change to the operations list. Typically, should be called with an
+ * empty list at the beginning of the service discovery process and for the
+ * second time with the list of discovered operations after that.
+ *
+ * @param list
+ * new list of discovered operations
+ */
+ public void fireOperationsChanged(List<Operation> list)
+ {
+ for (var listener : listeners)
+ {
+ listener.operationsChanged(discoverer, list);
+ }
+ }
+}
List<Operation> operations);
}
- List<OperationsChangeListener> serviceListeners = new CopyOnWriteArrayList<>();
-
/**
* Add an operations list observer that will be notified of any changes.
*
* @param listener
* operations list listener
*/
- public default void addOperationsChangeListener(
- OperationsChangeListener listener)
- {
- serviceListeners.add(listener);
- }
+ public void addOperationsChangeListener(OperationsChangeListener listener);
/**
* Remove the listener from the observers list.
* @param listener
* listener to be removed
*/
- public default void removeOperationsChangeListener(
- OperationsChangeListener listener)
- {
- serviceListeners.remove(listener);
- }
-
- /**
- * Called whenever the list of operations changes. Notifies all listeners of
- * the change to the operations list. Typically, should be called with an
- * empty list at the beginning of the service discovery process and for the
- * second time with the list of discovered operations after that.
- *
- * @param list
- * new list of discovered operations
- */
- default void fireOperationsChanged(List<Operation> list)
- {
- for (var listener : serviceListeners)
- {
- listener.operationsChanged(this, list);
- }
- }
+ public void removeOperationsChangeListener(OperationsChangeListener listener);
}
return "";
}
+
+ private OperationsChangeListenerList operationsChangeListeners =
+ new OperationsChangeListenerList(this);
+
+ @Override
+ public void addOperationsChangeListener(OperationsChangeListener listener)
+ {
+ operationsChangeListeners.addListener(listener);
+ }
+
+ @Override
+ public void removeOperationsChangeListener(
+ OperationsChangeListener listener)
+ {
+ operationsChangeListeners.removeListener(listener);
+ }
+
+ private void fireOperationsChanged(List<Operation> list)
+ {
+ operationsChangeListeners.fireOperationsChanged(list);
+ }
+
}