Jonghwan Hyun | 13a430d | 2018-07-22 17:02:51 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015-present Open Networking Foundation |
| 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.inbandtelemetry.app.ui; |
| 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; |
Jonghwan Hyun | 13a430d | 2018-07-22 17:02:51 +0900 | [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.slf4j.Logger; |
| 29 | import org.slf4j.LoggerFactory; |
| 30 | |
| 31 | import java.util.List; |
| 32 | |
| 33 | /** |
| 34 | * Skeletal ONOS UI Custom-View application component. |
| 35 | */ |
| 36 | @Component(immediate = true) |
| 37 | public class IntAppUiComponent { |
| 38 | |
| 39 | private static final String VIEW_ID = "intApp"; |
| 40 | private static final String VIEW_TEXT = "In-band Telemetry Control"; |
| 41 | |
| 42 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 43 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 44 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jonghwan Hyun | 13a430d | 2018-07-22 17:02:51 +0900 | [diff] [blame] | 45 | protected UiExtensionService uiExtensionService; |
| 46 | |
| 47 | // List of application views |
| 48 | private final List<UiView> uiViews = ImmutableList.of( |
| 49 | new UiView(UiView.Category.OTHER, VIEW_ID, VIEW_TEXT) |
| 50 | ); |
| 51 | |
| 52 | // Factory for UI message handlers |
| 53 | private final UiMessageHandlerFactory messageHandlerFactory = |
| 54 | () -> ImmutableList.of( |
| 55 | new IntAppUiMessageHandler(), |
| 56 | new IntAppTableMessageHandler() |
| 57 | ); |
| 58 | |
| 59 | // Application UI extension |
| 60 | protected UiExtension extension = |
| 61 | new UiExtension.Builder(getClass().getClassLoader(), uiViews) |
| 62 | .resourcePath(VIEW_ID) |
| 63 | .messageHandlerFactory(messageHandlerFactory) |
| 64 | .build(); |
| 65 | |
| 66 | @Activate |
| 67 | protected void activate() { |
| 68 | uiExtensionService.register(extension); |
| 69 | log.info("Started"); |
| 70 | } |
| 71 | |
| 72 | @Deactivate |
| 73 | protected void deactivate() { |
| 74 | uiExtensionService.unregister(extension); |
| 75 | log.info("Stopped"); |
| 76 | } |
| 77 | } |