ONOS-2186 - GUI Topo Overlay - (WIP)
- added isActive() predicate to UiTopoOverlay.
- auto-select single intent in an intent selection group.
- clean up mouse over/out handling.

Change-Id: I0f951bd26fcfc791d73bb8121ebbe002086294ea
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TopoOverlayCache.java b/web/gui/src/main/java/org/onosproject/ui/impl/TopoOverlayCache.java
index f7690e8..99557c2 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/TopoOverlayCache.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/TopoOverlayCache.java
@@ -30,6 +30,7 @@
  */
 public class TopoOverlayCache {
 
+    private static final String EMPTY = "";
     private static final UiTopoOverlay NONE = new NullOverlay();
 
     private final Map<String, UiTopoOverlay> overlays = new HashMap<>();
@@ -95,20 +96,21 @@
         return overlays.size();
     }
 
+    /**
+     * Returns true if the identifier of the currently active overlay
+     * matches the given parameter.
+     *
+     * @param overlayId overlay identifier
+     * @return true if this matches the ID of currently active overlay
+     */
+    public boolean isActive(String overlayId) {
+        return currentOverlay().id().equals(overlayId);
+    }
 
     // overlay instance representing "no overlay selected"
     private static class NullOverlay extends UiTopoOverlay {
         public NullOverlay() {
-            super(null);
-        }
-
-        // override activate and deactivate, so no log messages are written
-        @Override
-        public void activate() {
-        }
-
-        @Override
-        public void deactivate() {
+            super(EMPTY);
         }
     }
 }
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java
index 57054e0..1c629c7 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java
@@ -399,7 +399,9 @@
                     .build();
 
             intentService.submit(intent);
-            traffic.monitor(intent);
+            if (overlayCache.isActive(TrafficOverlay.TRAFFIC_ID)) {
+                traffic.monitor(intent);
+            }
         }
     }
 
@@ -432,7 +434,9 @@
                             .build();
 
             intentService.submit(intent);
-            traffic.monitor(intent);
+            if (overlayCache.isActive(TrafficOverlay.TRAFFIC_ID)) {
+                traffic.monitor(intent);
+            }
         }
     }
 
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TrafficOverlay.java b/web/gui/src/main/java/org/onosproject/ui/impl/TrafficOverlay.java
index 6eec92f..ea8ca3e 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/TrafficOverlay.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/TrafficOverlay.java
@@ -25,7 +25,10 @@
  * Topology Overlay for network traffic.
  */
 public class TrafficOverlay extends UiTopoOverlay {
-    private static final String TRAFFIC_ID = "traffic";
+    /**
+     * Traffic Overlay identifier.
+     */
+    public static final String TRAFFIC_ID = "traffic";
 
     private static final String SDF_ID = "showDeviceFlows";
     private static final String SRT_ID = "showRelatedTraffic";
@@ -38,10 +41,22 @@
         super(TRAFFIC_ID);
     }
 
+    // override activate and deactivate, to write log messages
+    @Override
+    public void activate() {
+        super.activate();
+        log.debug("TrafficOverlay Activated");
+    }
+
+    @Override
+    public void deactivate() {
+        super.deactivate();
+        log.debug("TrafficOverlay Deactivated");
+    }
+
     @Override
     public void modifyDeviceDetails(PropertyPanel pp) {
         pp.addButton(SHOW_DEVICE_FLOWS)
             .addButton(SHOW_RELATED_TRAFFIC);
     }
-
 }
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/IntentSelection.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/IntentSelection.java
index f99ff7c..01ae93d 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/topo/IntentSelection.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/IntentSelection.java
@@ -51,6 +51,9 @@
     public IntentSelection(NodeSelection nodes, TopoIntentFilter filter) {
         this.nodes = nodes;
         intents = filter.findPathIntents(nodes.hosts(), nodes.devices());
+        if (intents.size() == 1) {
+            index = 0;  // pre-select a single intent
+        }
     }
 
     /**