blob: b92f2406c2669af295360527a07e37e4a7f6734d [file] [log] [blame]
Jimmy Yanda878fc2016-09-02 16:32:01 -07001/*
Boyuan Yan6b23b382019-06-04 11:59:35 -07002 * Copyright 2019-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;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070019import org.osgi.service.component.annotations.Activate;
20import org.osgi.service.component.annotations.Component;
21import org.osgi.service.component.annotations.Deactivate;
22import org.osgi.service.component.annotations.Reference;
23import org.osgi.service.component.annotations.ReferenceCardinality;
Jimmy Yanda878fc2016-09-02 16:32:01 -070024import 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/**
Boyuan Yan6b23b382019-06-04 11:59:35 -070035 * Skeletal ONOS UI Custom-View application component.
Jimmy Yanda878fc2016-09-02 16:32:01 -070036 */
37@Component(immediate = true)
Boyuan Yan6b23b382019-06-04 11:59:35 -070038public class RoadmUiComponent {
Jimmy Yanda878fc2016-09-02 16:32:01 -070039
Boyuan Yan6b23b382019-06-04 11:59:35 -070040 private static final String VIEW_ID = "roadm-gui";
41 private static final String VIEW_TEXT = "Roadm UI";
Jimmy Yanda878fc2016-09-02 16:32:01 -070042
43 private final Logger log = LoggerFactory.getLogger(getClass());
44
Ray Milkeyd84f89b2018-08-17 14:54:17 -070045 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Jimmy Yanda878fc2016-09-02 16:32:01 -070046 protected UiExtensionService uiExtensionService;
47
48 // List of application views
Boyuan Yan6b23b382019-06-04 11:59:35 -070049 private final List<UiView> uiViews = ImmutableList.of(
50 new UiView(UiView.Category.OTHER, VIEW_ID, VIEW_TEXT),
51 new UiViewHidden("roadm-port-gui"),
Jimmy Yanda878fc2016-09-02 16:32:01 -070052 new UiViewHidden("roadmFlow")
53 );
54
55 // Factory for UI message handlers
56 private final UiMessageHandlerFactory messageHandlerFactory =
57 () -> ImmutableList.of(
58 new RoadmDeviceViewMessageHandler(),
59 new RoadmPortViewMessageHandler(),
60 new RoadmFlowViewMessageHandler()
61 );
62
Boyuan Yan6b23b382019-06-04 11:59:35 -070063 // Roadm UI extension
64 protected UiExtension extension =
65 new UiExtension.Builder(getClass().getClassLoader(), uiViews)
66 .resourcePath(VIEW_ID)
Jimmy Yanda878fc2016-09-02 16:32:01 -070067 .messageHandlerFactory(messageHandlerFactory)
Boyuan Yan6b23b382019-06-04 11:59:35 -070068 .ui2()
Jimmy Yanda878fc2016-09-02 16:32:01 -070069 .build();
70
71 @Activate
72 protected void activate() {
Boyuan Yan6b23b382019-06-04 11:59:35 -070073 uiExtensionService.register(extension);
Jimmy Yanda878fc2016-09-02 16:32:01 -070074 log.info("Started");
75 }
76
77 @Deactivate
78 protected void deactivate() {
Boyuan Yan6b23b382019-06-04 11:59:35 -070079 uiExtensionService.unregister(extension);
Jimmy Yanda878fc2016-09-02 16:32:01 -070080 log.info("Stopped");
81 }
82
83}