blob: 5f4f918eb989192aadc4e118cf5f5470b4647025 [file] [log] [blame]
Thomas Vachuskabbf10502015-12-09 13:41:58 -08001/*
2 * Copyright 2014,2015 Open Networking Laboratory
3 *
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";
41
42 private final Logger log = LoggerFactory.getLogger(getClass());
43
44 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
45 protected UiExtensionService uiExtensionService;
46
47 // List of application views
48 private final List<UiView> uiViews = ImmutableList.of(
Thomas Vachuska72667382016-02-22 14:27:48 -080049 new UiView(UiView.Category.PLATFORM, VIEW_ID, VIEW_TEXT)
Thomas Vachuskabbf10502015-12-09 13:41:58 -080050 );
51
52 // Factory for UI message handlers
53 private final UiMessageHandlerFactory messageHandlerFactory =
54 () -> ImmutableList.of(
Thomas Vachuska72667382016-02-22 14:27:48 -080055 new DriverViewMessageHandler()
Thomas Vachuskabbf10502015-12-09 13:41:58 -080056 );
57
58 // Application UI extension
59 protected UiExtension extension =
60 new UiExtension.Builder(getClass().getClassLoader(), uiViews)
61 .resourcePath(VIEW_ID)
62 .messageHandlerFactory(messageHandlerFactory)
63 .build();
64
65 @Activate
66 protected void activate() {
67 uiExtensionService.register(extension);
68 log.info("Started");
69 }
70
71 @Deactivate
72 protected void deactivate() {
73 uiExtensionService.unregister(extension);
74 log.info("Stopped");
75 }
76
77}