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 | /* |
| 5 | * Copyright 2014 Open Networking Laboratory |
| 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 | |
| 21 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 22 | import com.google.common.collect.ImmutableList; |
| 23 | import com.google.common.collect.ImmutableSet; |
| 24 | import org.apache.felix.scr.annotations.Activate; |
| 25 | import org.apache.felix.scr.annotations.Component; |
| 26 | import org.apache.felix.scr.annotations.Deactivate; |
| 27 | import org.apache.felix.scr.annotations.Service; |
| 28 | import org.apache.felix.scr.annotations.Reference; |
| 29 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 30 | import org.onosproject.ui.UiExtension; |
| 31 | import org.onosproject.ui.UiExtensionService; |
| 32 | import org.onosproject.ui.UiMessageHandler; |
| 33 | import org.onosproject.ui.UiMessageHandlerFactory; |
| 34 | import org.onosproject.ui.UiView; |
| 35 | import org.slf4j.Logger; |
| 36 | import org.slf4j.LoggerFactory; |
| 37 | |
| 38 | import java.util.List; |
| 39 | |
| 40 | /** |
| 41 | * Skeletal ONOS UI application component. |
| 42 | */ |
| 43 | @Component(immediate = true) |
| 44 | public class AppUiComponent { |
| 45 | |
| 46 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 47 | |
| 48 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 49 | protected UiExtensionService uiExtensionService; |
| 50 | |
| 51 | // List of application views |
| 52 | private final List<UiView> uiViews = ImmutableList.of( |
| 53 | new UiView(UiView.Category.OTHER, "sample", "Sample") |
| 54 | ); |
| 55 | |
| 56 | // Factory for UI message handlers |
| 57 | private final UiMessageHandlerFactory messageHandlerFactory = |
| 58 | () -> ImmutableList.of( |
| 59 | new AppUiMessageHandler() |
| 60 | ); |
| 61 | |
| 62 | // Application UI exctension |
| 63 | protected UiExtension extension = new UiExtension(uiViews, messageHandlerFactory, |
| 64 | getClass().getClassLoader()); |
| 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 | |
| 78 | // Application UI message handler |
| 79 | private class AppUiMessageHandler extends UiMessageHandler { |
| 80 | protected AppUiMessageHandler() { |
| 81 | super(ImmutableSet.of("sampleRequest")); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public void process(ObjectNode objectNode) { |
| 86 | log.info("We got a message: {}", objectNode); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | } |