ONOS-1479 -- GUI - augmenting topology view for extensibility: WIP.
Change-Id: I11820a9ff8f446c0d10a0311cee5ce448c15f402
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
deleted file mode 100644
index e797130..0000000
--- a/core/api/src/main/java/org/onosproject/ui/topo/ButtonDescriptor.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * 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/ButtonId.java b/core/api/src/main/java/org/onosproject/ui/topo/ButtonId.java
new file mode 100644
index 0000000..ca2eccc
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/ui/topo/ButtonId.java
@@ -0,0 +1,70 @@
+/*
+ * 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;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Designates the identity of a button on the topology view panels.
+ */
+public class ButtonId {
+
+ private final String id;
+
+ /**
+ * Creates a button ID with the given identifier.
+ *
+ * @param id identifier for the button
+ */
+ public ButtonId(String id) {
+ this.id = id;
+ }
+
+ /**
+ * Returns the identifier for this button.
+ *
+ * @return identifier
+ */
+ public String id() {
+ return id;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("id", id()).toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ ButtonId that = (ButtonId) 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 43364ea..121e083 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<ButtonDescriptor> buttons = new ArrayList<>();
+ private List<ButtonId> 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<ButtonDescriptor> buttons() {
+ public List<ButtonId> buttons() {
return buttons;
}
@@ -243,7 +243,7 @@
* @param button button descriptor
* @return self, for chaining
*/
- public PropertyPanel addButton(ButtonDescriptor button) {
+ public PropertyPanel addButton(ButtonId button) {
buttons.add(button);
return this;
}
@@ -254,10 +254,10 @@
* @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) {
+ public PropertyPanel removeButtons(ButtonId... descriptors) {
+ Set<ButtonId> forRemoval = Sets.newHashSet(descriptors);
+ List<ButtonId> toKeep = new ArrayList<>();
+ for (ButtonId bd: buttons) {
if (!forRemoval.contains(bd)) {
toKeep.add(bd);
}
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 a48c253..38a8f03 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
@@ -108,30 +108,22 @@
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
+ * Defines identities of 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 ButtonId SHOW_DEVICE_VIEW =
+ new ButtonId("showDeviceView");
- public static final ButtonDescriptor SHOW_FLOW_VIEW =
- new CoreButton("Flow", Glyphs.FLOW_TABLE, true);
+ public static final ButtonId SHOW_FLOW_VIEW =
+ new ButtonId("showFlowView");
- public static final ButtonDescriptor SHOW_PORT_VIEW =
- new CoreButton("Port", Glyphs.PORT_TABLE, true);
+ public static final ButtonId SHOW_PORT_VIEW =
+ new ButtonId("showPortView");
- public static final ButtonDescriptor SHOW_GROUP_VIEW =
- new CoreButton("Group", Glyphs.GROUP_TABLE, true);
+ public static final ButtonId SHOW_GROUP_VIEW =
+ new ButtonId("showGroupView");
}
}
diff --git a/core/api/src/test/java/org/onosproject/ui/topo/ButtonDescriptorTest.java b/core/api/src/test/java/org/onosproject/ui/topo/ButtonDescriptorTest.java
deleted file mode 100644
index 1f47a09..0000000
--- a/core/api/src/test/java/org/onosproject/ui/topo/ButtonDescriptorTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * Unit tests for {@link ButtonDescriptor}.
- */
-public class ButtonDescriptorTest {
-
- private static final String ID = "my-id";
- private static final String GID = "my-glyphId";
- private static final String TT = "my-tewltyp";
-
- private ButtonDescriptor bd;
-
-
- @Test
- public void basic() {
- bd = new ButtonDescriptor(ID, GID, TT);
-
- assertEquals("bad id", ID, bd.id());
- assertEquals("bad gid", GID, bd.glyphId());
- assertEquals("bad tt", TT, bd.tooltip());
- }
-
-}
diff --git a/core/api/src/test/java/org/onosproject/ui/topo/ButtonIdTest.java b/core/api/src/test/java/org/onosproject/ui/topo/ButtonIdTest.java
new file mode 100644
index 0000000..04c6dc1
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/ui/topo/ButtonIdTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Unit tests for {@link ButtonId}.
+ */
+public class ButtonIdTest {
+
+ private static final String ID1 = "id-1";
+ private static final String ID2 = "id-2";
+
+ private ButtonId b1, b2;
+
+
+ @Test
+ public void basic() {
+ b1 = new ButtonId(ID1);
+ }
+
+ @Test
+ public void same() {
+ b1 = new ButtonId(ID1);
+ b2 = new ButtonId(ID1);
+ assertFalse("same ref?", b1 == b2);
+ assertTrue("not equal?", b1.equals(b2));
+ }
+
+ @Test
+ public void notSame() {
+ b1 = new ButtonId(ID1);
+ b2 = new ButtonId(ID2);
+ assertFalse("same ref?", b1 == b2);
+ assertFalse("equal?", b1.equals(b2));
+ }
+}
diff --git a/core/api/src/test/java/org/onosproject/ui/topo/PropertyPanelTest.java b/core/api/src/test/java/org/onosproject/ui/topo/PropertyPanelTest.java
index e97c037..b08ee4d 100644
--- a/core/api/src/test/java/org/onosproject/ui/topo/PropertyPanelTest.java
+++ b/core/api/src/test/java/org/onosproject/ui/topo/PropertyPanelTest.java
@@ -47,14 +47,6 @@
private static final String VALUE_B = "Bee";
private static final String VALUE_C = "Sea";
private static final String VALUE_Z = "Zed";
- private static final String GID_A = "gid-A";
- private static final String GID_B = "gid-B";
- private static final String GID_C = "gid-C";
- private static final String GID_Z = "gid-Z";
- private static final String TT_A = "toolTip-A";
- private static final String TT_B = "toolTip-B";
- private static final String TT_C = "toolTip-C";
- private static final String TT_Z = "toolTip-Z";
private static final Map<String, Prop> PROP_MAP = new HashMap<>();
@@ -211,17 +203,13 @@
validateProp(KEY_B, ">byyy<");
}
- private static final ButtonDescriptor BD_A =
- new ButtonDescriptor(KEY_A, GID_A, TT_A);
- private static final ButtonDescriptor BD_B =
- new ButtonDescriptor(KEY_B, GID_B, TT_B);
- private static final ButtonDescriptor BD_C =
- new ButtonDescriptor(KEY_C, GID_C, TT_C);
- private static final ButtonDescriptor BD_Z =
- new ButtonDescriptor(KEY_Z, GID_Z, TT_Z);
+ private static final ButtonId BD_A = new ButtonId(KEY_A);
+ private static final ButtonId BD_B = new ButtonId(KEY_B);
+ private static final ButtonId BD_C = new ButtonId(KEY_C);
+ private static final ButtonId BD_Z = new ButtonId(KEY_Z);
private void verifyButtons(String... keys) {
- Iterator<ButtonDescriptor> iter = pp.buttons().iterator();
+ Iterator<ButtonId> iter = pp.buttons().iterator();
for (String k: keys) {
assertEquals("wrong button", k, iter.next().id());
}