blob: 5056b716ca2d961d5fdb2e3c8068ae4381b9a9de [file] [log] [blame]
Jimmy Yanda878fc2016-09-02 16:32:01 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Jimmy Yanda878fc2016-09-02 16:32:01 -07003 *
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.roadm;
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.onosproject.ui.UiViewHidden;
29import org.slf4j.Logger;
30import org.slf4j.LoggerFactory;
31
32import java.util.List;
33
34/**
35 * ONOS UI for ROADM application.
36 */
37@Component(immediate = true)
38public class RoadmComponent {
39
40 private static final String DEVICE_VIEW_ID = "roadmDevice";
41 private static final String DEVICE_VIEW_TEXT = "ROADM";
42
43 private static final String RESOURCE_PATH = "webgui";
44
45 private final Logger log = LoggerFactory.getLogger(getClass());
46
47 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
48 protected UiExtensionService uiExtensionService;
49
50 // List of application views
51 private final List<UiView> deviceViews = ImmutableList.of(
52 new UiView(UiView.Category.OTHER, DEVICE_VIEW_ID, DEVICE_VIEW_TEXT),
53 new UiViewHidden("roadmPort"),
54 new UiViewHidden("roadmFlow")
55 );
56
57 // Factory for UI message handlers
58 private final UiMessageHandlerFactory messageHandlerFactory =
59 () -> ImmutableList.of(
60 new RoadmDeviceViewMessageHandler(),
61 new RoadmPortViewMessageHandler(),
62 new RoadmFlowViewMessageHandler()
63 );
64
65 // Device UI extension
66 protected UiExtension deviceExtension =
67 new UiExtension.Builder(getClass().getClassLoader(), deviceViews)
68 .resourcePath(RESOURCE_PATH)
69 .messageHandlerFactory(messageHandlerFactory)
70 .build();
71
72 @Activate
73 protected void activate() {
74 uiExtensionService.register(deviceExtension);
75 log.info("Started");
76 }
77
78 @Deactivate
79 protected void deactivate() {
80 uiExtensionService.unregister(deviceExtension);
81 log.info("Stopped");
82 }
83
84}