Jimmy Yan | da878fc | 2016-09-02 16:32:01 -0700 | [diff] [blame] | 1 | /* |
Boyuan Yan | 6b23b38 | 2019-06-04 11:59:35 -0700 | [diff] [blame] | 2 | * Copyright 2019-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; |
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; |
Jimmy Yan | da878fc | 2016-09-02 16:32:01 -0700 | [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.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 | /** |
Boyuan Yan | 6b23b38 | 2019-06-04 11:59:35 -0700 | [diff] [blame] | 35 | * Skeletal ONOS UI Custom-View application component. |
Jimmy Yan | da878fc | 2016-09-02 16:32:01 -0700 | [diff] [blame] | 36 | */ |
| 37 | @Component(immediate = true) |
Boyuan Yan | 6b23b38 | 2019-06-04 11:59:35 -0700 | [diff] [blame] | 38 | public class RoadmUiComponent { |
Jimmy Yan | da878fc | 2016-09-02 16:32:01 -0700 | [diff] [blame] | 39 | |
Boyuan Yan | 6b23b38 | 2019-06-04 11:59:35 -0700 | [diff] [blame] | 40 | private static final String VIEW_ID = "roadm-gui"; |
Andrea Campanella | 7cbeb97 | 2019-07-25 15:05:59 +0200 | [diff] [blame] | 41 | private static final String VIEW_TEXT = "Optical UI"; |
Jimmy Yan | da878fc | 2016-09-02 16:32:01 -0700 | [diff] [blame] | 42 | |
| 43 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 44 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 45 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jimmy Yan | da878fc | 2016-09-02 16:32:01 -0700 | [diff] [blame] | 46 | protected UiExtensionService uiExtensionService; |
| 47 | |
| 48 | // List of application views |
Boyuan Yan | 6b23b38 | 2019-06-04 11:59:35 -0700 | [diff] [blame] | 49 | private final List<UiView> uiViews = ImmutableList.of( |
| 50 | new UiView(UiView.Category.OTHER, VIEW_ID, VIEW_TEXT), |
| 51 | new UiViewHidden("roadm-port-gui"), |
Jimmy Yan | da878fc | 2016-09-02 16:32:01 -0700 | [diff] [blame] | 52 | new UiViewHidden("roadmFlow") |
| 53 | ); |
| 54 | |
| 55 | // Factory for UI message handlers |
| 56 | private final UiMessageHandlerFactory messageHandlerFactory = |
| 57 | () -> ImmutableList.of( |
| 58 | new RoadmDeviceViewMessageHandler(), |
| 59 | new RoadmPortViewMessageHandler(), |
| 60 | new RoadmFlowViewMessageHandler() |
| 61 | ); |
| 62 | |
Boyuan Yan | 6b23b38 | 2019-06-04 11:59:35 -0700 | [diff] [blame] | 63 | // Roadm UI extension |
| 64 | protected UiExtension extension = |
| 65 | new UiExtension.Builder(getClass().getClassLoader(), uiViews) |
| 66 | .resourcePath(VIEW_ID) |
Jimmy Yan | da878fc | 2016-09-02 16:32:01 -0700 | [diff] [blame] | 67 | .messageHandlerFactory(messageHandlerFactory) |
Boyuan Yan | 6b23b38 | 2019-06-04 11:59:35 -0700 | [diff] [blame] | 68 | .ui2() |
Jimmy Yan | da878fc | 2016-09-02 16:32:01 -0700 | [diff] [blame] | 69 | .build(); |
| 70 | |
| 71 | @Activate |
| 72 | protected void activate() { |
Boyuan Yan | 6b23b38 | 2019-06-04 11:59:35 -0700 | [diff] [blame] | 73 | uiExtensionService.register(extension); |
Jimmy Yan | da878fc | 2016-09-02 16:32:01 -0700 | [diff] [blame] | 74 | log.info("Started"); |
| 75 | } |
| 76 | |
| 77 | @Deactivate |
| 78 | protected void deactivate() { |
Boyuan Yan | 6b23b38 | 2019-06-04 11:59:35 -0700 | [diff] [blame] | 79 | uiExtensionService.unregister(extension); |
Jimmy Yan | da878fc | 2016-09-02 16:32:01 -0700 | [diff] [blame] | 80 | log.info("Stopped"); |
| 81 | } |
| 82 | |
| 83 | } |