Jimmy Yan | da878fc | 2016-09-02 16:32:01 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Jimmy Yan | da878fc | 2016-09-02 16:32:01 -0700 | [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.roadm; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableList; |
| 19 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; |
| 22 | import org.apache.felix.scr.annotations.Reference; |
| 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 24 | import org.onosproject.ui.UiExtension; |
| 25 | import org.onosproject.ui.UiExtensionService; |
| 26 | import org.onosproject.ui.UiMessageHandlerFactory; |
| 27 | import org.onosproject.ui.UiView; |
| 28 | import org.onosproject.ui.UiViewHidden; |
| 29 | import org.slf4j.Logger; |
| 30 | import org.slf4j.LoggerFactory; |
| 31 | |
| 32 | import java.util.List; |
| 33 | |
| 34 | /** |
| 35 | * ONOS UI for ROADM application. |
| 36 | */ |
| 37 | @Component(immediate = true) |
| 38 | public class RoadmComponent { |
| 39 | |
| 40 | private static final String DEVICE_VIEW_ID = "roadmDevice"; |
| 41 | private static final String DEVICE_VIEW_TEXT = "ROADM"; |
| 42 | |
| 43 | private static final String RESOURCE_PATH = "webgui"; |
| 44 | |
| 45 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 46 | |
| 47 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 48 | protected UiExtensionService uiExtensionService; |
| 49 | |
| 50 | // List of application views |
| 51 | private final List<UiView> deviceViews = ImmutableList.of( |
| 52 | new UiView(UiView.Category.OTHER, DEVICE_VIEW_ID, DEVICE_VIEW_TEXT), |
| 53 | new UiViewHidden("roadmPort"), |
| 54 | new UiViewHidden("roadmFlow") |
| 55 | ); |
| 56 | |
| 57 | // Factory for UI message handlers |
| 58 | private final UiMessageHandlerFactory messageHandlerFactory = |
| 59 | () -> ImmutableList.of( |
| 60 | new RoadmDeviceViewMessageHandler(), |
| 61 | new RoadmPortViewMessageHandler(), |
| 62 | new RoadmFlowViewMessageHandler() |
| 63 | ); |
| 64 | |
| 65 | // Device UI extension |
| 66 | protected UiExtension deviceExtension = |
| 67 | new UiExtension.Builder(getClass().getClassLoader(), deviceViews) |
| 68 | .resourcePath(RESOURCE_PATH) |
| 69 | .messageHandlerFactory(messageHandlerFactory) |
| 70 | .build(); |
| 71 | |
| 72 | @Activate |
| 73 | protected void activate() { |
| 74 | uiExtensionService.register(deviceExtension); |
| 75 | log.info("Started"); |
| 76 | } |
| 77 | |
| 78 | @Deactivate |
| 79 | protected void deactivate() { |
| 80 | uiExtensionService.unregister(deviceExtension); |
| 81 | log.info("Stopped"); |
| 82 | } |
| 83 | |
| 84 | } |