ONOS-1479 -- GUI - augmenting topology view for extensibility:
- Implemented server-side topo panel button descriptors, with overlay ability to remove core buttons and add custom buttons.

Change-Id: Id9ecc4c5e2d2db942232d2156ecf3bc858c0c61f
diff --git a/core/api/src/main/java/org/onosproject/ui/topo/ButtonDescriptor.java b/core/api/src/main/java/org/onosproject/ui/topo/ButtonDescriptor.java
new file mode 100644
index 0000000..e797130
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/ui/topo/ButtonDescriptor.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.onosproject.ui.topo;
+
+/**
+ * Designates a descriptor for a button on the topology view panels.
+ */
+public class ButtonDescriptor {
+
+    private final String id;
+    private final String glyphId;
+    private final String tooltip;
+
+    /**
+     * Creates a button descriptor with the given identifier, glyph ID, and
+     * tooltip text. To reference a custom glyph defined in the overlay itself,
+     * prefix its ID with an asterisk, (e.g. {@code "*myGlyph"}). Alternatively,
+     * use one of the {@link TopoConstants.Glyphs predefined constant}.
+     *
+     * @param id identifier for the button
+     * @param glyphId identifier for the glyph
+     * @param tooltip tooltip text
+     */
+    public ButtonDescriptor(String id, String glyphId, String tooltip) {
+        this.id = id;
+        this.glyphId = glyphId;
+        this.tooltip = tooltip;
+    }
+
+    /**
+     * Returns the identifier for this button.
+     *
+     * @return identifier
+     */
+    public String id() {
+        return id;
+    }
+
+    /**
+     * Returns the glyph identifier for this button.
+     *
+     * @return glyph identifier
+     */
+    public String glyphId() {
+        return glyphId;
+    }
+
+    /**
+     * Returns the tooltip text for this button.
+     *
+     * @return tooltip text
+     */
+    public String tooltip() {
+        return tooltip;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        ButtonDescriptor that = (ButtonDescriptor) o;
+        return id.equals(that.id);
+
+    }
+
+    @Override
+    public int hashCode() {
+        return id.hashCode();
+    }
+}
diff --git a/core/api/src/main/java/org/onosproject/ui/topo/PropertyPanel.java b/core/api/src/main/java/org/onosproject/ui/topo/PropertyPanel.java
index 03ff2a3..43364ea 100644
--- a/core/api/src/main/java/org/onosproject/ui/topo/PropertyPanel.java
+++ b/core/api/src/main/java/org/onosproject/ui/topo/PropertyPanel.java
@@ -35,7 +35,7 @@
     private String typeId;
     private String id;
     private List<Prop> properties = new ArrayList<>();
-    private List<Button> buttons = new ArrayList<>();
+    private List<ButtonDescriptor> buttons = new ArrayList<>();
 
     /**
      * Constructs a property panel model with the given title and
@@ -181,7 +181,7 @@
      * @return the button list
      */
     // TODO: consider protecting this?
-    public List<Button> buttons() {
+    public List<ButtonDescriptor> buttons() {
         return buttons;
     }
 
@@ -216,14 +216,14 @@
      * @return self, for chaining
      */
     public PropertyPanel removeProps(String... keys) {
-        Set<String> keysForRemoval = Sets.newHashSet(keys);
-        List<Prop> propsToKeep = new ArrayList<>();
+        Set<String> forRemoval = Sets.newHashSet(keys);
+        List<Prop> toKeep = new ArrayList<>();
         for (Prop p: properties) {
-            if (!keysForRemoval.contains(p.key())) {
-                propsToKeep.add(p);
+            if (!forRemoval.contains(p.key())) {
+                toKeep.add(p);
             }
         }
-        properties = propsToKeep;
+        properties = toKeep;
         return this;
     }
 
@@ -238,13 +238,41 @@
     }
 
     /**
-     * Adds a button descriptor with the given identifier, to the panel data.
+     * Adds the given button descriptor to the panel data.
      *
-     * @param id button identifier
+     * @param button button descriptor
      * @return self, for chaining
      */
-    public PropertyPanel addButton(String id) {
-        buttons.add(new Button(id));
+    public PropertyPanel addButton(ButtonDescriptor button) {
+        buttons.add(button);
+        return this;
+    }
+
+    /**
+     * Removes buttons with the given descriptors from the list.
+     *
+     * @param descriptors descriptors to remove
+     * @return self, for chaining
+     */
+    public PropertyPanel removeButtons(ButtonDescriptor... descriptors) {
+        Set<ButtonDescriptor> forRemoval = Sets.newHashSet(descriptors);
+        List<ButtonDescriptor> toKeep = new ArrayList<>();
+        for (ButtonDescriptor bd: buttons) {
+            if (!forRemoval.contains(bd)) {
+                toKeep.add(bd);
+            }
+        }
+        buttons = toKeep;
+        return this;
+    }
+
+    /**
+     * Removes all currently defined buttons.
+     *
+     * @return self, for chaining
+     */
+    public PropertyPanel removeAllButtons() {
+        buttons.clear();
         return this;
     }
 
@@ -322,29 +350,4 @@
         }
     }
 
-    /**
-     * Button descriptor. Note that these work in conjunction with
-     * "buttons" defined in the JavaScript code for the overlay.
-     */
-    public static class Button {
-        private final String id;
-
-        /**
-         * Constructs a button descriptor with the given identifier.
-         *
-         * @param id button identifier
-         */
-        public Button(String id) {
-            this.id = id;
-        }
-
-        /**
-         * Returns the identifier for this button.
-         *
-         * @return button identifier
-         */
-        public String id() {
-            return id;
-        }
-    }
 }
diff --git a/core/api/src/main/java/org/onosproject/ui/topo/TopoConstants.java b/core/api/src/main/java/org/onosproject/ui/topo/TopoConstants.java
index d44ba9f..a48c253 100644
--- a/core/api/src/main/java/org/onosproject/ui/topo/TopoConstants.java
+++ b/core/api/src/main/java/org/onosproject/ui/topo/TopoConstants.java
@@ -79,6 +79,8 @@
      * details panels.
      */
     public static final class Properties {
+        public static final String SEPARATOR = "-";
+
         // summary panel
         public static final String DEVICES = "Devices";
         public static final String LINKS = "Links";
@@ -106,4 +108,30 @@
         public static final String VLAN = "VLAN";
     }
 
+    private static final class CoreButton extends ButtonDescriptor {
+        private CoreButton(String tag, String glyphId, boolean extra) {
+            super("show" + tag + "View",
+                  glyphId,
+                  "Show " + tag + " View" + (extra ? " for this Device" : ""));
+        }
+    }
+
+    /**
+     * Defines constants for core buttons that appear on the topology
+     * details panel.
+     */
+    public static final class CoreButtons {
+        public static final ButtonDescriptor SHOW_DEVICE_VIEW =
+                new CoreButton("Device", Glyphs.SWITCH, false);
+
+        public static final ButtonDescriptor SHOW_FLOW_VIEW =
+                new CoreButton("Flow", Glyphs.FLOW_TABLE, true);
+
+        public static final ButtonDescriptor SHOW_PORT_VIEW =
+                new CoreButton("Port", Glyphs.PORT_TABLE, true);
+
+        public static final ButtonDescriptor SHOW_GROUP_VIEW =
+                new CoreButton("Group", Glyphs.GROUP_TABLE, true);
+    }
+
 }