Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 1 | #set( $symbol_pound = '#' ) |
| 2 | #set( $symbol_dollar = '$' ) |
| 3 | #set( $symbol_escape = '\' ) |
| 4 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 5 | * Copyright ${year}-present Open Networking Foundation |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | */ |
| 19 | package ${package}; |
| 20 | |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 21 | import com.google.common.collect.ImmutableList; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 22 | import org.osgi.service.component.annotations.Activate; |
| 23 | import org.osgi.service.component.annotations.Component; |
| 24 | import org.osgi.service.component.annotations.Deactivate; |
| 25 | import org.osgi.service.component.annotations.Reference; |
| 26 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 27 | import org.onosproject.ui.UiExtension; |
| 28 | import org.onosproject.ui.UiExtensionService; |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 29 | import org.onosproject.ui.UiMessageHandlerFactory; |
| 30 | import org.onosproject.ui.UiView; |
| 31 | import org.slf4j.Logger; |
| 32 | import org.slf4j.LoggerFactory; |
| 33 | |
| 34 | import java.util.List; |
| 35 | |
| 36 | /** |
Simon Hunt | 84f4c2a | 2015-09-23 17:52:45 -0700 | [diff] [blame] | 37 | * Skeletal ONOS UI Custom-View application component. |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 38 | */ |
| 39 | @Component(immediate = true) |
| 40 | public class AppUiComponent { |
| 41 | |
Simon Hunt | afce2ae | 2015-10-01 10:38:10 -0700 | [diff] [blame] | 42 | private static final String VIEW_ID = "sampleCustom"; |
| 43 | private static final String VIEW_TEXT = "Sample Custom"; |
| 44 | |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 45 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 46 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 47 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 48 | protected UiExtensionService uiExtensionService; |
| 49 | |
| 50 | // List of application views |
| 51 | private final List<UiView> uiViews = ImmutableList.of( |
Simon Hunt | afce2ae | 2015-10-01 10:38:10 -0700 | [diff] [blame] | 52 | new UiView(UiView.Category.OTHER, VIEW_ID, VIEW_TEXT) |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 53 | ); |
| 54 | |
| 55 | // Factory for UI message handlers |
| 56 | private final UiMessageHandlerFactory messageHandlerFactory = |
| 57 | () -> ImmutableList.of( |
| 58 | new AppUiMessageHandler() |
| 59 | ); |
| 60 | |
Thomas Vachuska | 9290053 | 2015-05-20 17:21:44 -0700 | [diff] [blame] | 61 | // Application UI extension |
Simon Hunt | e11ce5a | 2015-07-21 12:11:04 -0700 | [diff] [blame] | 62 | protected UiExtension extension = |
Simon Hunt | e05cae4 | 2015-07-23 17:35:24 -0700 | [diff] [blame] | 63 | new UiExtension.Builder(getClass().getClassLoader(), uiViews) |
Thomas Vachuska | 731193d | 2015-12-10 11:41:46 -0800 | [diff] [blame] | 64 | .resourcePath(VIEW_ID) |
Simon Hunt | e05cae4 | 2015-07-23 17:35:24 -0700 | [diff] [blame] | 65 | .messageHandlerFactory(messageHandlerFactory) |
| 66 | .build(); |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 67 | |
| 68 | @Activate |
| 69 | protected void activate() { |
| 70 | uiExtensionService.register(extension); |
| 71 | log.info("Started"); |
| 72 | } |
| 73 | |
| 74 | @Deactivate |
| 75 | protected void deactivate() { |
| 76 | uiExtensionService.unregister(extension); |
| 77 | log.info("Stopped"); |
| 78 | } |
| 79 | |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 80 | } |