Jian Li | a23f46d | 2017-05-02 18:07:31 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Jian Li | a23f46d | 2017-05-02 18:07:31 +0900 | [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.mapping.web.gui; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableList; |
Jian Li | a23f46d | 2017-05-02 18:07:31 +0900 | [diff] [blame] | 19 | import org.onosproject.ui.UiExtension; |
| 20 | import org.onosproject.ui.UiExtensionService; |
| 21 | import org.onosproject.ui.UiMessageHandlerFactory; |
| 22 | import org.onosproject.ui.UiView; |
Jian Li | 3bc6ef1 | 2017-05-04 21:51:41 +0900 | [diff] [blame] | 23 | import org.onosproject.ui.UiViewHidden; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 24 | import org.osgi.service.component.annotations.Activate; |
| 25 | import org.osgi.service.component.annotations.Component; |
| 26 | import org.osgi.service.component.annotations.Deactivate; |
| 27 | import org.osgi.service.component.annotations.Reference; |
| 28 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Jian Li | a23f46d | 2017-05-02 18:07:31 +0900 | [diff] [blame] | 29 | import org.slf4j.Logger; |
| 30 | import org.slf4j.LoggerFactory; |
| 31 | |
| 32 | import java.util.List; |
| 33 | |
Jian Li | a23f46d | 2017-05-02 18:07:31 +0900 | [diff] [blame] | 34 | /** |
| 35 | * Mechanism to stream data to the GUI. |
| 36 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 37 | @Component(immediate = true, service = MappingsUI.class) |
Jian Li | a23f46d | 2017-05-02 18:07:31 +0900 | [diff] [blame] | 38 | public class MappingsUI { |
| 39 | private static final String MAPPING_ID = "mapping"; |
Jian Li | a23f46d | 2017-05-02 18:07:31 +0900 | [diff] [blame] | 40 | private static final String RES_PATH = "gui"; |
| 41 | private static final ClassLoader CL = MappingsUI.class.getClassLoader(); |
| 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) |
Jian Li | a23f46d | 2017-05-02 18:07:31 +0900 | [diff] [blame] | 46 | protected UiExtensionService uiExtensionService; |
| 47 | |
| 48 | // Factory for UI message handlers |
| 49 | private final UiMessageHandlerFactory messageHandlerFactory = |
| 50 | () -> ImmutableList.of(new MappingsViewMessageHandler()); |
| 51 | |
| 52 | // List of application views |
| 53 | private final List<UiView> views = ImmutableList.of( |
Jian Li | 3bc6ef1 | 2017-05-04 21:51:41 +0900 | [diff] [blame] | 54 | new UiViewHidden(MAPPING_ID) |
Jian Li | a23f46d | 2017-05-02 18:07:31 +0900 | [diff] [blame] | 55 | ); |
| 56 | |
| 57 | // Application UI extension |
| 58 | private final UiExtension uiExtension = |
| 59 | new UiExtension.Builder(CL, views) |
| 60 | .messageHandlerFactory(messageHandlerFactory) |
| 61 | .resourcePath(RES_PATH) |
| 62 | .build(); |
| 63 | |
| 64 | @Activate |
| 65 | protected void activate() { |
| 66 | uiExtensionService.register(uiExtension); |
| 67 | log.info("Started"); |
| 68 | } |
| 69 | |
| 70 | @Deactivate |
| 71 | protected void deactivate() { |
| 72 | uiExtensionService.unregister(uiExtension); |
| 73 | log.info("Stopped"); |
| 74 | } |
| 75 | } |