ONOS-6258: UiTopo2Overlay et al.
- initial support for topo-2 highlighting.
Change-Id: I71c61b902047153ea420a8b2ecd89f6950daa4a9
diff --git a/core/api/src/main/java/org/onosproject/ui/UiExtension.java b/core/api/src/main/java/org/onosproject/ui/UiExtension.java
index 17201cb..9edcba9a 100644
--- a/core/api/src/main/java/org/onosproject/ui/UiExtension.java
+++ b/core/api/src/main/java/org/onosproject/ui/UiExtension.java
@@ -47,6 +47,7 @@
private final List<UiView> viewList;
private final UiMessageHandlerFactory messageHandlerFactory;
private final UiTopoOverlayFactory topoOverlayFactory;
+ private final UiTopo2OverlayFactory topo2OverlayFactory;
private final UiTopoMapFactory topoMapFactory;
private boolean isValid = true;
@@ -55,12 +56,14 @@
private UiExtension(ClassLoader cl, String path, List<UiView> views,
UiMessageHandlerFactory mhFactory,
UiTopoOverlayFactory toFactory,
+ UiTopo2OverlayFactory to2Factory,
UiTopoMapFactory tmFactory) {
classLoader = cl;
resourcePath = path;
viewList = views;
messageHandlerFactory = mhFactory;
topoOverlayFactory = toFactory;
+ topo2OverlayFactory = to2Factory;
topoMapFactory = tmFactory;
}
@@ -122,6 +125,15 @@
}
/**
+ * Returns the topology-2 overlay factory, if one was defined.
+ *
+ * @return topology-2 overlay factory
+ */
+ public UiTopo2OverlayFactory topo2OverlayFactory() {
+ return topo2OverlayFactory;
+ }
+
+ /**
* Returns the topology map factory, if one was defined.
*
* @return topology map factory
@@ -152,6 +164,7 @@
private List<UiView> viewList = new ArrayList<>();
private UiMessageHandlerFactory messageHandlerFactory = null;
private UiTopoOverlayFactory topoOverlayFactory = null;
+ private UiTopo2OverlayFactory topo2OverlayFactory = null;
private UiTopoMapFactory topoMapFactory = null;
/**
@@ -205,6 +218,17 @@
}
/**
+ * Sets the topology-2 overlay factory for this extension.
+ *
+ * @param to2Factory topology-2 overlay factory
+ * @return self, for chaining
+ */
+ public Builder topo2OverlayFactory(UiTopo2OverlayFactory to2Factory) {
+ topo2OverlayFactory = to2Factory;
+ return this;
+ }
+
+ /**
* Sets the topology map factory for this extension.
*
* @param tmFactory topology map factory
@@ -222,8 +246,8 @@
*/
public UiExtension build() {
return new UiExtension(classLoader, resourcePath, viewList,
- messageHandlerFactory, topoOverlayFactory,
- topoMapFactory);
+ messageHandlerFactory, topoOverlayFactory,
+ topo2OverlayFactory, topoMapFactory);
}
}
}
diff --git a/core/api/src/main/java/org/onosproject/ui/UiTopo2Overlay.java b/core/api/src/main/java/org/onosproject/ui/UiTopo2Overlay.java
new file mode 100644
index 0000000..940080e
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/ui/UiTopo2Overlay.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2017-present 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;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Represents a user interface topology-2 view overlay.
+ * <p>
+ * This base class does little more than provide a logger, an identifier,
+ * name, and glyph ID.
+ * Subclasses will probably want to override some or all of the base methods
+ * to do useful things during the life-cycle of the (topo-2) overlay.
+ */
+public class UiTopo2Overlay {
+
+ private static final String DEFAULT_GLYPH_ID = "m_topo";
+
+ /**
+ * Logger for this overlay.
+ */
+ protected final Logger log = LoggerFactory.getLogger(getClass());
+
+ private final String id;
+ private final String name;
+
+ private boolean isActive = false;
+
+ /**
+ * Creates a new user interface topology view overlay descriptor, with
+ * the given identifier and (human readable) name.
+ *
+ * @param id overlay identifier
+ * @param name overlay name
+ */
+ public UiTopo2Overlay(String id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ /**
+ * Returns the identifier for this overlay.
+ *
+ * @return the identifier
+ */
+ public String id() {
+ return id;
+ }
+
+ /**
+ * Returns the name for this overlay.
+ *
+ * @return the name
+ */
+ public String name() {
+ return name;
+ }
+
+ /**
+ * Returns the glyph identifier to use in the toolbar.
+ * This implementation returns a default value. Subclasses may override
+ * this to provide the identity of a custom glyph.
+ *
+ * @return glyph ID
+ */
+ public String glyphId() {
+ return DEFAULT_GLYPH_ID;
+ }
+
+ /**
+ * Callback invoked to initialize this overlay, soon after creation.
+ * This default implementation does nothing.
+ */
+ public void init() {
+ }
+
+ /**
+ * Callback invoked when this overlay is activated.
+ */
+ public void activate() {
+ isActive = true;
+ }
+
+ /**
+ * Callback invoked when this overlay is deactivated.
+ */
+ public void deactivate() {
+ isActive = false;
+ }
+
+ /**
+ * Returns true if this overlay is currently active.
+ *
+ * @return true if overlay active
+ */
+ public boolean isActive() {
+ return isActive;
+ }
+
+ /**
+ * Callback invoked to destroy this instance by cleaning up any
+ * internal state ready for garbage collection.
+ * This default implementation holds no state and does nothing.
+ */
+ public void destroy() {
+ }
+
+ /**
+ * Callback invoked when the topology highlighting should be updated.
+ * It is the implementation's responsibility to update the Model
+ * Highlighter state. This implementation does nothing.
+ */
+ public void highlightingCallback(/* ref to highlight model ? */) {
+
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/ui/UiTopo2OverlayFactory.java b/core/api/src/main/java/org/onosproject/ui/UiTopo2OverlayFactory.java
new file mode 100644
index 0000000..d6718fa
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/ui/UiTopo2OverlayFactory.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2017-present 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;
+
+import java.util.Collection;
+
+/**
+ * Abstraction of an entity capable of producing one or more topology-2
+ * overlay handlers specific to a given user interface connection.
+ */
+public interface UiTopo2OverlayFactory {
+
+ /**
+ * Produces a collection of new overlay handlers for topology-2 view.
+ *
+ * @return collection of new overlay handlers
+ */
+ Collection<UiTopo2Overlay> newOverlays();
+}