Thomas Vachuska | 8871691 | 2015-11-13 08:15:01 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2014-2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.byon.gui; |
| 18 | |
| 19 | import com.google.common.collect.ImmutableList; |
| 20 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; |
| 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 25 | import org.onosproject.ui.UiExtension; |
| 26 | import org.onosproject.ui.UiExtensionService; |
| 27 | import org.onosproject.ui.UiMessageHandlerFactory; |
| 28 | import org.onosproject.ui.UiTopoOverlayFactory; |
| 29 | import org.onosproject.ui.UiView; |
| 30 | import org.onosproject.ui.UiViewHidden; |
| 31 | import org.slf4j.Logger; |
| 32 | import org.slf4j.LoggerFactory; |
| 33 | |
| 34 | import java.util.List; |
| 35 | |
| 36 | /** |
| 37 | * BYON GUI component. When activated, registers a {@link UiExtension} with |
| 38 | * the {@link UiExtensionService}, so that new content is injected into the |
| 39 | * ONOS Web UI. This example injects one new view as well as providing a |
| 40 | * topology view overlay. |
| 41 | */ |
| 42 | @Component(immediate = true) |
| 43 | public class NetworkUiComponent { |
| 44 | |
| 45 | private static final ClassLoader CL = NetworkUiComponent.class.getClassLoader(); |
| 46 | |
| 47 | // There should be matching directory names under ~/resources/app/view/ |
| 48 | private static final String TABLE_VIEW_ID = "byonNetworks"; |
| 49 | private static final String TOPOV_VIEW_ID = "byonTopov"; |
| 50 | |
| 51 | // Text to appear in the UI navigation pane |
| 52 | private static final String TABLE_VIEW_TEXT = "BYON Networks"; |
| 53 | |
| 54 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 55 | |
| 56 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 57 | protected UiExtensionService uiExtensionService; |
| 58 | |
| 59 | // List of application views |
| 60 | private final List<UiView> uiViews = ImmutableList.of( |
| 61 | new UiView(UiView.Category.OTHER, TABLE_VIEW_ID, TABLE_VIEW_TEXT), |
| 62 | new UiViewHidden(TOPOV_VIEW_ID) |
| 63 | ); |
| 64 | |
| 65 | // Factory for message handlers |
| 66 | private final UiMessageHandlerFactory messageHandlerFactory = |
| 67 | () -> ImmutableList.of( |
| 68 | new NetworkTableViewMessageHandler(), |
| 69 | new NetworkOverlayMessageHandler() |
| 70 | ); |
| 71 | |
| 72 | // Factory for topology overlays |
| 73 | private final UiTopoOverlayFactory topoOverlayFactory = |
| 74 | () -> ImmutableList.of( |
| 75 | new NetworkTopoOverlay() |
| 76 | ); |
| 77 | |
| 78 | // Build our UI extension definition |
| 79 | private UiExtension extension = |
| 80 | new UiExtension.Builder(CL, uiViews) |
| 81 | .messageHandlerFactory(messageHandlerFactory) |
| 82 | .topoOverlayFactory(topoOverlayFactory) |
| 83 | .build(); |
| 84 | |
| 85 | @Activate |
| 86 | protected void activate() { |
| 87 | uiExtensionService.register(extension); |
| 88 | log.info("Started"); |
| 89 | } |
| 90 | |
| 91 | @Deactivate |
| 92 | protected void deactivate() { |
| 93 | uiExtensionService.unregister(extension); |
| 94 | log.info("Stopped"); |
| 95 | } |
| 96 | |
| 97 | } |