Simon Hunt | cc035c5 | 2017-02-22 21:12:51 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Laboratory |
| 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 | |
Thomas Vachuska | 04059f9 | 2017-03-07 15:16:23 -0800 | [diff] [blame] | 17 | package org.onosproject.yang.gui; |
Simon Hunt | cc035c5 | 2017-02-22 21:12:51 -0800 | [diff] [blame] | 18 | |
| 19 | import com.google.common.collect.ImmutableList; |
| 20 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; |
| 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 25 | import org.onosproject.ui.UiExtension; |
| 26 | import org.onosproject.ui.UiExtensionService; |
| 27 | import org.onosproject.ui.UiMessageHandlerFactory; |
| 28 | import org.onosproject.ui.UiView; |
| 29 | import org.slf4j.Logger; |
| 30 | import org.slf4j.LoggerFactory; |
| 31 | |
| 32 | import java.util.List; |
| 33 | |
| 34 | import static org.onosproject.ui.UiView.Category; |
| 35 | |
| 36 | /** |
| 37 | * ONOS UI component for the Yang Models table view. |
| 38 | */ |
| 39 | @Component(immediate = true) |
| 40 | public class YangModelUiComponent { |
| 41 | |
| 42 | private static final ClassLoader CL = |
| 43 | YangModelUiComponent.class.getClassLoader(); |
| 44 | private static final String VIEW_ID = "yangModel"; |
Thomas Vachuska | 9ac4c7e | 2017-02-23 09:01:45 -0800 | [diff] [blame] | 45 | private static final String NAV_LABEL = "YANG Models"; |
Simon Hunt | cc035c5 | 2017-02-22 21:12:51 -0800 | [diff] [blame] | 46 | private static final String NAV_ICON = "nav_yang"; |
| 47 | private static final String HELP_URL = |
| 48 | "https://wiki.onosproject.org/display/ONOS/YANG+Models+in+ONOS"; |
| 49 | |
| 50 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 51 | |
| 52 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 53 | protected UiExtensionService uiExtensionService; |
| 54 | |
| 55 | // List of application views |
| 56 | private final List<UiView> uiViews = ImmutableList.of( |
| 57 | new UiView(Category.PLATFORM, VIEW_ID, NAV_LABEL, NAV_ICON, HELP_URL) |
| 58 | ); |
| 59 | |
| 60 | // Factory for UI message handlers |
| 61 | private final UiMessageHandlerFactory msgHandlerFactory = |
| 62 | () -> ImmutableList.of( |
| 63 | new YangModelMessageHandler() |
| 64 | ); |
| 65 | |
| 66 | // Application UI Extension |
| 67 | private UiExtension extension = |
| 68 | new UiExtension.Builder(CL, uiViews) |
| 69 | .resourcePath(VIEW_ID) |
| 70 | .messageHandlerFactory(msgHandlerFactory) |
| 71 | .build(); |
| 72 | |
| 73 | @Activate |
| 74 | protected void activate() { |
| 75 | uiExtensionService.register(extension); |
| 76 | log.info("Started"); |
| 77 | } |
| 78 | |
| 79 | @Deactivate |
| 80 | protected void deactivate() { |
| 81 | uiExtensionService.unregister(extension); |
| 82 | log.info("Stopped"); |
| 83 | } |
| 84 | |
| 85 | } |