Enhanced layout service and hooked-in the ui topo session.

Change-Id: I357143766deb3f0d697a3e7963a53968ccdf3bc8
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/UiWebSocket.java b/web/gui/src/main/java/org/onosproject/ui/impl/UiWebSocket.java
index 38af57d..2585bc8 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/UiWebSocket.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/UiWebSocket.java
@@ -27,7 +27,11 @@
 import org.onosproject.ui.UiExtensionService;
 import org.onosproject.ui.UiMessageHandler;
 import org.onosproject.ui.UiMessageHandlerFactory;
+import org.onosproject.ui.UiTopoLayoutService;
 import org.onosproject.ui.UiTopoOverlayFactory;
+import org.onosproject.ui.impl.topo.UiTopoSession;
+import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel;
+import org.onosproject.ui.model.topo.UiTopoLayout;
 import org.onosproject.ui.topo.TopoConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -55,6 +59,8 @@
     private static final String USER = "user";
     private static final String BOOTSTRAP = "bootstrap";
 
+    public static final String TOPO = "topo";
+
     private static final long MAX_AGE_MS = 30_000;
 
     private static final byte PING = 0x9;
@@ -63,11 +69,12 @@
 
     private final ObjectMapper mapper = new ObjectMapper();
     private final ServiceDirectory directory;
-//    private final UiTopoSession topoSession;
+    private final UiTopoSession topoSession;
 
     private Connection connection;
     private FrameConnection control;
     private String userName;
+    private String currentView;
 
     private long lastActive = System.currentTimeMillis();
 
@@ -83,8 +90,9 @@
     public UiWebSocket(ServiceDirectory directory, String userName) {
         this.directory = directory;
         this.userName = userName;
-//        this.topoSession =
-//                new UiTopoSession(this, directory.get(UiSharedTopologyModel.class));
+        this.topoSession =
+                new UiTopoSession(this, directory.get(UiSharedTopologyModel.class),
+                                  directory.get(UiTopoLayoutService.class));
     }
 
     @Override
@@ -92,6 +100,27 @@
         return userName;
     }
 
+    @Override
+    public UiTopoLayout currentLayout() {
+        return topoSession.currentLayout();
+    }
+
+    @Override
+    public void setCurrentLayout(UiTopoLayout topoLayout) {
+        topoSession.setCurrentLayout(topoLayout);
+    }
+
+    @Override
+    public String currentView() {
+        return currentView;
+    }
+
+    @Override
+    public void setCurrentView(String viewId) {
+        currentView = viewId;
+        topoSession.enableEvent(viewId.equals(TOPO));
+    }
+
     /**
      * Issues a close on the connection.
      */
@@ -128,7 +157,7 @@
         this.connection = connection;
         this.control = (FrameConnection) connection;
         try {
-//            topoSession.init();
+            topoSession.init();
             createHandlersAndOverlays();
             sendBootstrapData();
             log.info("GUI client connected -- user <{}>", userName);
@@ -143,10 +172,10 @@
 
     @Override
     public synchronized void onClose(int closeCode, String message) {
-//        topoSession.destroy();
+        topoSession.destroy();
         destroyHandlersAndOverlays();
         log.info("GUI client disconnected [close-code={}, message={}]",
-                closeCode, message);
+                 closeCode, message);
     }
 
     @Override
@@ -228,7 +257,7 @@
             }
         });
         log.debug("#handlers = {}, #overlays = {}", handlers.size(),
-                overlayCache.size());
+                  overlayCache.size());
     }
 
     // Destroys message handlers.
@@ -255,7 +284,7 @@
                     .put(ID, node.id().toString())
                     .put(IP, node.ip().toString())
                     .put(TopoConstants.Glyphs.UI_ATTACHED,
-                            node.equals(service.getLocalNode()));
+                         node.equals(service.getLocalNode()));
             instances.add(instance);
         }