blob: c052346b2acaa1891a3891c742755ca01a093dce [file] [log] [blame]
Thomas Vachuskaa2ae4222015-04-29 18:42:09 -07001#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 */
19package ${package};
20
21import com.fasterxml.jackson.databind.node.ObjectNode;
22import com.google.common.collect.ImmutableList;
23import com.google.common.collect.ImmutableSet;
24import org.apache.felix.scr.annotations.Activate;
25import org.apache.felix.scr.annotations.Component;
26import org.apache.felix.scr.annotations.Deactivate;
27import org.apache.felix.scr.annotations.Service;
28import org.apache.felix.scr.annotations.Reference;
29import org.apache.felix.scr.annotations.ReferenceCardinality;
30import org.onosproject.ui.UiExtension;
31import org.onosproject.ui.UiExtensionService;
32import org.onosproject.ui.UiMessageHandler;
33import org.onosproject.ui.UiMessageHandlerFactory;
34import org.onosproject.ui.UiView;
35import org.slf4j.Logger;
36import org.slf4j.LoggerFactory;
37
38import java.util.List;
39
40/**
41 * Skeletal ONOS UI application component.
42 */
43@Component(immediate = true)
44public 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}