blob: 3571c5f553b36d6101b3386b08d1ab0021a204a6 [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;
Thomas Vachuska9e5dd902015-05-04 12:49:03 -070030import org.onosproject.ui.RequestHandler;
Thomas Vachuskaa2ae4222015-04-29 18:42:09 -070031import org.onosproject.ui.UiExtension;
32import org.onosproject.ui.UiExtensionService;
33import org.onosproject.ui.UiMessageHandler;
34import org.onosproject.ui.UiMessageHandlerFactory;
35import org.onosproject.ui.UiView;
36import org.slf4j.Logger;
37import org.slf4j.LoggerFactory;
38
Thomas Vachuska9e5dd902015-05-04 12:49:03 -070039import java.util.Collection;
Thomas Vachuskaa2ae4222015-04-29 18:42:09 -070040import java.util.List;
41
42/**
43 * Skeletal ONOS UI application component.
44 */
45@Component(immediate = true)
46public class AppUiComponent {
47
48 private final Logger log = LoggerFactory.getLogger(getClass());
49
50 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
51 protected UiExtensionService uiExtensionService;
52
53 // List of application views
54 private final List<UiView> uiViews = ImmutableList.of(
55 new UiView(UiView.Category.OTHER, "sample", "Sample")
56 );
57
58 // Factory for UI message handlers
59 private final UiMessageHandlerFactory messageHandlerFactory =
60 () -> ImmutableList.of(
61 new AppUiMessageHandler()
62 );
63
Thomas Vachuska92900532015-05-20 17:21:44 -070064 // Application UI extension
Thomas Vachuskaa2ae4222015-04-29 18:42:09 -070065 protected UiExtension extension = new UiExtension(uiViews, messageHandlerFactory,
66 getClass().getClassLoader());
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
80 // Application UI message handler
81 private class AppUiMessageHandler extends UiMessageHandler {
Thomas Vachuskaa2ae4222015-04-29 18:42:09 -070082
83 @Override
Thomas Vachuska92900532015-05-20 17:21:44 -070084 protected Collection<RequestHandler> createRequestHandlers() {
Thomas Vachuska9e5dd902015-05-04 12:49:03 -070085 return ImmutableSet.of(new SampleRequest());
86 }
87
88 private class SampleRequest extends RequestHandler {
89 public SampleRequest() {
90 super("sampleRequest");
91 }
92
93 @Override
94 public void process(long sid, ObjectNode objectNode) {
95 log.info("We got a message: {}", objectNode);
96 }
Thomas Vachuskaa2ae4222015-04-29 18:42:09 -070097 }
98 }
99
100}