blob: b8d66de144693aa78ef9babcd489f0bc8ff4a67a [file] [log] [blame]
Thomas Vachuskabbf10502015-12-09 13:41:58 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Thomas Vachuskabbf10502015-12-09 13:41:58 -08003 *
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 */
16package org.onosproject.drivermatrix;
17
18import com.google.common.collect.ImmutableList;
19import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Reference;
23import org.apache.felix.scr.annotations.ReferenceCardinality;
24import org.onosproject.ui.UiExtension;
25import org.onosproject.ui.UiExtensionService;
26import org.onosproject.ui.UiMessageHandlerFactory;
27import org.onosproject.ui.UiView;
28import org.slf4j.Logger;
29import org.slf4j.LoggerFactory;
30
31import java.util.List;
32
33/**
Thomas Vachuska72667382016-02-22 14:27:48 -080034 * Registers driver matrix view.
Thomas Vachuskabbf10502015-12-09 13:41:58 -080035 */
36@Component(immediate = true)
Thomas Vachuska72667382016-02-22 14:27:48 -080037public class DriverViewComponent {
Thomas Vachuskabbf10502015-12-09 13:41:58 -080038
39 private static final String VIEW_ID = "driverMatrix";
40 private static final String VIEW_TEXT = "Driver Matrix";
Simon Hunt24d0c5c2016-03-03 00:05:08 -080041 private static final String NAV_ICON = "nav_drivers";
Thomas Vachuskabbf10502015-12-09 13:41:58 -080042
43 private final Logger log = LoggerFactory.getLogger(getClass());
44
45 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
46 protected UiExtensionService uiExtensionService;
47
48 // List of application views
49 private final List<UiView> uiViews = ImmutableList.of(
Simon Hunt24d0c5c2016-03-03 00:05:08 -080050 new UiView(UiView.Category.PLATFORM, VIEW_ID, VIEW_TEXT, NAV_ICON)
Thomas Vachuskabbf10502015-12-09 13:41:58 -080051 );
52
53 // Factory for UI message handlers
54 private final UiMessageHandlerFactory messageHandlerFactory =
55 () -> ImmutableList.of(
Thomas Vachuska72667382016-02-22 14:27:48 -080056 new DriverViewMessageHandler()
Thomas Vachuskabbf10502015-12-09 13:41:58 -080057 );
58
59 // Application UI extension
60 protected UiExtension extension =
61 new UiExtension.Builder(getClass().getClassLoader(), uiViews)
62 .resourcePath(VIEW_ID)
63 .messageHandlerFactory(messageHandlerFactory)
64 .build();
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}