Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 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 | package org.onosproject.pathpainter; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableList; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 19 | import org.osgi.service.component.annotations.Activate; |
| 20 | import org.osgi.service.component.annotations.Component; |
| 21 | import org.osgi.service.component.annotations.Deactivate; |
| 22 | import org.osgi.service.component.annotations.Reference; |
| 23 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 24 | import org.onosproject.ui.UiExtension; |
| 25 | import org.onosproject.ui.UiExtensionService; |
| 26 | import org.onosproject.ui.UiMessageHandlerFactory; |
| 27 | import org.onosproject.ui.UiTopoOverlayFactory; |
| 28 | import org.onosproject.ui.UiView; |
| 29 | import org.onosproject.ui.UiViewHidden; |
| 30 | import org.slf4j.Logger; |
| 31 | import org.slf4j.LoggerFactory; |
| 32 | |
| 33 | import java.util.List; |
| 34 | |
| 35 | /** |
Andrea Campanella | a4ef01d | 2017-02-02 09:34:26 -0800 | [diff] [blame] | 36 | * ONOS UI PathPainter Topology-Overlay application component. |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 37 | */ |
| 38 | @Component(immediate = true) |
| 39 | public class PathPainter { |
| 40 | |
| 41 | private static final ClassLoader CL = PathPainter.class.getClassLoader(); |
| 42 | private static final String VIEW_ID = "ppTopov"; |
| 43 | |
| 44 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 45 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 46 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 47 | protected UiExtensionService uiExtensionService; |
| 48 | |
| 49 | // List of application views |
| 50 | private final List<UiView> uiViews = ImmutableList.of( |
| 51 | new UiViewHidden(VIEW_ID) |
| 52 | ); |
| 53 | |
| 54 | // Factory for UI message handlers |
| 55 | private final UiMessageHandlerFactory messageHandlerFactory = |
| 56 | () -> ImmutableList.of( |
| 57 | new PathPainterTopovMessageHandler() |
| 58 | ); |
| 59 | |
| 60 | // Factory for UI topology overlays |
| 61 | private final UiTopoOverlayFactory topoOverlayFactory = |
| 62 | () -> ImmutableList.of( |
| 63 | new PathPainterTopovOverlay() |
| 64 | ); |
| 65 | |
| 66 | // Application UI extension |
| 67 | protected UiExtension extension = |
| 68 | new UiExtension.Builder(CL, uiViews) |
| 69 | .resourcePath(VIEW_ID) |
| 70 | .messageHandlerFactory(messageHandlerFactory) |
| 71 | .topoOverlayFactory(topoOverlayFactory) |
| 72 | .build(); |
| 73 | |
| 74 | @Activate |
| 75 | protected void activate() { |
| 76 | uiExtensionService.register(extension); |
| 77 | log.info("Started"); |
| 78 | } |
| 79 | |
| 80 | @Deactivate |
| 81 | protected void deactivate() { |
| 82 | uiExtensionService.unregister(extension); |
| 83 | log.info("Stopped"); |
| 84 | } |
| 85 | |
| 86 | } |