Fixing GUI to respond to server-side layout changes.

Change-Id: Ida1052d6bec4a92d29774ede47942410db189732
diff --git a/core/api/src/main/java/org/onosproject/net/config/basics/BasicElementConfig.java b/core/api/src/main/java/org/onosproject/net/config/basics/BasicElementConfig.java
index 1cb00dc..0504624 100644
--- a/core/api/src/main/java/org/onosproject/net/config/basics/BasicElementConfig.java
+++ b/core/api/src/main/java/org/onosproject/net/config/basics/BasicElementConfig.java
@@ -84,8 +84,10 @@
     protected static final double ZERO_THRESHOLD = Double.MIN_VALUE * 2.0;
 
     private static final double DEFAULT_COORD = 0.0;
-    private static final String LOC_TYPE_GEO = "geo";
-    private static final String LOC_TYPE_GRID = "grid";
+
+    public static final String LOC_TYPE_GEO = "geo";
+    public static final String LOC_TYPE_GRID = "grid";
+    public static final String LOC_TYPE_NONE = "none";
 
     private static final int NAME_MAX_LENGTH = 256;
     private static final int UI_TYPE_MAX_LENGTH = 128;
@@ -137,23 +139,29 @@
 
     /**
      * Returns the location type (geo or grid) for the element in
-     * the Topology View. If not set, returns the default of "geo".
+     * the Topology View. If not set, the type will be determined implicitly
+     * by latitude being set ("geo") or gridX being set ("grid");
+     * otherwise returns the default of "none".
      *
      * @return location type (string)
      */
     public String locType() {
-        return get(LOC_TYPE, LOC_TYPE_GEO);
+        String l = get(LATITUDE, null);
+        String x = get(GRID_X, null);
+        String def = l != null ? LOC_TYPE_GEO : (x != null ? LOC_TYPE_GRID : LOC_TYPE_NONE);
+        return get(LOC_TYPE, def);
     }
 
     /**
      * Sets the location type (geo or grid) for the element in
-     * the Topology View. If null is passsed, it will default to "geo".
+     * the Topology View. If null is passed, it will default to "geo".
      *
      * @param locType the UI type; null for default
      * @return self
      */
     public BasicElementConfig locType(String locType) {
-        String lt = LOC_TYPE_GRID.equals(locType) ? LOC_TYPE_GRID : LOC_TYPE_GEO;
+        String lt = Objects.equals(LOC_TYPE_GRID, locType) || Objects.equals(LOC_TYPE_GEO, locType)
+                ? locType : LOC_TYPE_NONE;
         return (BasicElementConfig) setOrClear(LOC_TYPE, lt);
     }
 
diff --git a/core/api/src/test/java/org/onosproject/net/config/basics/BasicElementConfigTest.java b/core/api/src/test/java/org/onosproject/net/config/basics/BasicElementConfigTest.java
index 0d65eb9..f2e4b99 100644
--- a/core/api/src/test/java/org/onosproject/net/config/basics/BasicElementConfigTest.java
+++ b/core/api/src/test/java/org/onosproject/net/config/basics/BasicElementConfigTest.java
@@ -32,8 +32,8 @@
     private static final ObjectMapper MAPPER = new ObjectMapper();
 
     private static final String E1 = "e1";
-    private static final String GEO = "geo";
-    private static final String GRID = "grid";
+    private static final String GEO = BasicElementConfig.LOC_TYPE_GEO;
+    private static final String GRID = BasicElementConfig.LOC_TYPE_GRID;
     public static final ImmutableSet<String> ROLES = ImmutableSet.of("spine", "primary");
 
     // concrete subclass of abstract class we are testing
@@ -128,7 +128,7 @@
     @Test
     public void defaultLocationType() {
         print(cfg);
-        assertEquals("not geo", GEO, cfg.locType());
+        assertEquals("not none", BasicElementConfig.LOC_TYPE_NONE, cfg.locType());
     }
 
     @Test
@@ -149,7 +149,7 @@
     public void otherLocationType() {
         cfg.locType("foobar");
         print(cfg);
-        assertEquals("not geo", GEO, cfg.locType());
+        assertEquals("not none", BasicElementConfig.LOC_TYPE_NONE, cfg.locType());
     }
 
     @Test
diff --git a/core/net/src/main/java/org/onosproject/net/device/impl/BasicElementOperator.java b/core/net/src/main/java/org/onosproject/net/device/impl/BasicElementOperator.java
index 09a154d..29333e6 100644
--- a/core/net/src/main/java/org/onosproject/net/device/impl/BasicElementOperator.java
+++ b/core/net/src/main/java/org/onosproject/net/device/impl/BasicElementOperator.java
@@ -21,6 +21,8 @@
 import org.onosproject.net.config.ConfigOperator;
 import org.onosproject.net.config.basics.BasicElementConfig;
 
+import java.util.Objects;
+
 /**
  * Abstract base implementation for element operators.
  */
@@ -46,12 +48,18 @@
         if (cfg.locType() != null) {
             builder.set(AnnotationKeys.LOC_TYPE, cfg.locType());
         }
-        if (cfg.geoCoordsSet()) {
+
+        if (Objects.equals(cfg.locType(), BasicElementConfig.LOC_TYPE_NONE)) {
+            builder.remove(AnnotationKeys.GRID_X).remove(AnnotationKeys.GRID_Y);
+            builder.remove(AnnotationKeys.LATITUDE).remove(AnnotationKeys.LONGITUDE);
+        } else if (cfg.geoCoordsSet()) {
             builder.set(AnnotationKeys.LATITUDE, Double.toString(cfg.latitude()));
             builder.set(AnnotationKeys.LONGITUDE, Double.toString(cfg.longitude()));
+            builder.remove(AnnotationKeys.GRID_X).remove(AnnotationKeys.GRID_Y);
         } else if (cfg.gridCoordsSet()) {
             builder.set(AnnotationKeys.GRID_Y, Double.toString(cfg.gridY()));
             builder.set(AnnotationKeys.GRID_X, Double.toString(cfg.gridX()));
+            builder.remove(AnnotationKeys.LATITUDE).remove(AnnotationKeys.LONGITUDE);
         }
 
         if (cfg.rackAddress() != null) {