[ONOS-6958] Add glyph registration java code
Change-Id: I954c790062f8ff5498c34c334827c4f695278a9e
diff --git a/core/api/src/main/java/org/onosproject/security/AppPermission.java b/core/api/src/main/java/org/onosproject/security/AppPermission.java
index c0f7fe9..c0ab697 100644
--- a/core/api/src/main/java/org/onosproject/security/AppPermission.java
+++ b/core/api/src/main/java/org/onosproject/security/AppPermission.java
@@ -85,7 +85,9 @@
UI_WRITE,
UPGRADE_READ,
UPGRADE_WRITE,
- UPGRADE_EVENT
+ UPGRADE_EVENT,
+ GLYPH_READ,
+ GLYPH_WRITE
}
protected Type type;
diff --git a/core/api/src/main/java/org/onosproject/ui/GlyphConstants.java b/core/api/src/main/java/org/onosproject/ui/GlyphConstants.java
index f760abb..d5bae5e 100644
--- a/core/api/src/main/java/org/onosproject/ui/GlyphConstants.java
+++ b/core/api/src/main/java/org/onosproject/ui/GlyphConstants.java
@@ -85,6 +85,10 @@
public static final String CLOUD = "m_cloud";
+ public static final String ID = "id";
+ public static final String VIEWBOX = "viewbox";
+ public static final String PATH = "path";
+
// non-instantiable
private GlyphConstants() {
}
diff --git a/core/api/src/main/java/org/onosproject/ui/UiExtensionService.java b/core/api/src/main/java/org/onosproject/ui/UiExtensionService.java
index 4764412..9e03a51 100644
--- a/core/api/src/main/java/org/onosproject/ui/UiExtensionService.java
+++ b/core/api/src/main/java/org/onosproject/ui/UiExtensionService.java
@@ -17,6 +17,7 @@
import org.onosproject.ui.lion.LionBundle;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -39,6 +40,22 @@
void unregister(UiExtension extension);
/**
+ * Registers the specified user interface glyph factory.
+ *
+ * @param factory UI glyph factory to register
+ */
+ default void register(UiGlyphFactory factory) {
+ }
+
+ /**
+ * Unregisters the specified user interface glyph factory.
+ *
+ * @param factory UI glyph factory to unregister
+ */
+ default void unregister(UiGlyphFactory factory) {
+ }
+
+ /**
* Returns the list of registered user interface extensions.
*
* @return list of extensions
@@ -54,6 +71,15 @@
UiExtension getViewExtension(String viewId);
/**
+ * Returns the list of registered user interface glyphs.
+ *
+ * @return list of glyphs
+ */
+ default List<UiGlyph> getGlyphs() {
+ return new ArrayList<UiGlyph>();
+ }
+
+ /**
* Returns the navigation pane localization bundle.
*
* @return the navigation localization bundle
diff --git a/core/api/src/main/java/org/onosproject/ui/UiGlyph.java b/core/api/src/main/java/org/onosproject/ui/UiGlyph.java
new file mode 100644
index 0000000..767ccd4
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/ui/UiGlyph.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2018 Open Networking Foundation
+ *
+ * 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;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * Represents a glyph to be used in the user interface topology view. Instances
+ * of this class are immutable.
+ */
+public class UiGlyph {
+
+ private final String id;
+ private final String viewbox;
+ private final String path;
+
+
+ /**
+ * Creates a new glyph.
+ *
+ * The value of the viewbox parameter is a string of four numbers min-x,
+ * min-y, width and height, separated by whitespace and/or a comma.
+ *
+ * The path parameter specifies how this element is to be drawn inside of
+ * the viewbox. The ONOS GUI only uses single paths – not rectangles,
+ * strokes, circles, or anything else. One path definition has to be used
+ * for the entire glyph.
+ *
+ * @param id glyph identifier
+ * @param viewbox glyph viewbox
+ * @param path glyph path
+ */
+ public UiGlyph(String id, String viewbox, String path) {
+ this.id = id;
+ this.viewbox = viewbox;
+ this.path = path;
+ }
+
+ /**
+ * Returns the identifier for this glyph.
+ *
+ * @return the identifier
+ */
+ public String id() {
+ return id;
+ }
+
+ /**
+ * Returns the viewbox for this glyph.
+ *
+ * @return the viewbox
+ */
+ public String viewbox() {
+ return viewbox;
+ }
+
+ /**
+ * Returns the path for this glyph.
+ *
+ * @return the path
+ */
+ public String path() {
+ return path;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("id", id)
+ .add("viewbox", viewbox)
+ .add("path", path)
+ .toString();
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/ui/UiGlyphFactory.java b/core/api/src/main/java/org/onosproject/ui/UiGlyphFactory.java
new file mode 100644
index 0000000..c98c0e2
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/ui/UiGlyphFactory.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2018 Open Networking Foundation
+ *
+ * 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;
+
+import java.util.List;
+
+/**
+ * Abstraction of an entity capable of producing one or more glyphs for the
+ * topology view.
+ */
+public interface UiGlyphFactory {
+
+ /**
+ * Produces a list of glyphns to be added to the topology view.
+ *
+ * @return list of glyphs
+ */
+ List<UiGlyph> glyphs();
+}