blob: 26ec73cd63c9edca309891a7c3c4424c8417dc6f [file] [log] [blame]
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -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.ui;
17
18import com.google.common.base.MoreObjects;
19
20import java.util.Objects;
21
22/**
Simon Hunt8add9ee2016-09-20 17:05:07 -070023 * Represents a user interface view addition.
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080024 */
25public class UiView {
26
chengfan386620e2016-11-09 17:02:40 +080027 private static final String DEFAULT_HELP_PAGE_URL =
28 "https://wiki.onosproject.org/display/ONOS/The+ONOS+Web+GUI";
29
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070030 /**
Simon Hunt8add9ee2016-09-20 17:05:07 -070031 * Designates the navigation menu category.
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070032 */
33 public enum Category {
Simon Hunt23f9c7b2017-07-10 20:00:30 -070034 // NOTE: human readable strings for the categories are now applied
35 // externally, with the appropriate localization bundle.
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070036 /**
37 * Represents platform related views.
38 */
Simon Hunt23f9c7b2017-07-10 20:00:30 -070039 PLATFORM,
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070040
41 /**
42 * Represents network-control related views.
43 */
Simon Hunt23f9c7b2017-07-10 20:00:30 -070044 NETWORK,
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070045
46 /**
47 * Represents miscellaneous views.
48 */
Simon Hunt23f9c7b2017-07-10 20:00:30 -070049 OTHER,
Simon Hunt38c2b6a2015-04-24 13:02:05 -070050
51 /**
52 * Represents views that do not show in the navigation menu.
53 * This category should not be specified directly; rather, use
54 * the {@link UiViewHidden} constructor instead of {@link UiView}.
55 */
Simon Hunt23f9c7b2017-07-10 20:00:30 -070056 HIDDEN
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070057 }
58
Simon Hunt20e16792015-04-24 14:29:39 -070059 private final Category category;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080060 private final String id;
61 private final String label;
Simon Hunt20e16792015-04-24 14:29:39 -070062 private final String iconId;
chengfan386620e2016-11-09 17:02:40 +080063 private final String helpPageUrl;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080064
65 /**
Simon Hunt38c2b6a2015-04-24 13:02:05 -070066 * Creates a new user interface view descriptor. The navigation item
67 * will appear in the navigation menu under the specified category.
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080068 *
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070069 * @param category view category
70 * @param id view identifier
71 * @param label view label
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080072 */
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070073 public UiView(Category category, String id, String label) {
chengfan386620e2016-11-09 17:02:40 +080074 this(category, id, label, null, null);
Simon Hunt20e16792015-04-24 14:29:39 -070075 }
76
77 /**
78 * Creates a new user interface view descriptor. The navigation item
79 * will appear in the navigation menu under the specified category,
80 * with the specified icon adornment.
Simon Hunt8add9ee2016-09-20 17:05:07 -070081 * <p>
82 * Note: see the {@code glyphMapping} structure in {@code icon.js} for
83 * valid icon identifiers.
Simon Hunt20e16792015-04-24 14:29:39 -070084 *
85 * @param category view category
86 * @param id view identifier
87 * @param label view label
88 * @param iconId icon id
89 */
90 public UiView(Category category, String id, String label, String iconId) {
chengfan386620e2016-11-09 17:02:40 +080091 this(category, id, label, iconId, null);
92 }
93
94 /**
95 * Creates a new user interface view descriptor. The navigation item
96 * will appear in the navigation menu under the specified category,
97 * with the specified icon adornment and specified help page.
98 * <p>
99 * Note: see the {@code glyphMapping} structure in {@code icon.js} for
100 * valid icon identifiers.
101 *
102 * @param category view category
103 * @param id view identifier
104 * @param label view label
105 * @param iconId icon id
106 * @param helpPageUrl help page URL
107 */
108 public UiView(Category category, String id, String label, String iconId,
109 String helpPageUrl) {
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -0700110 this.category = category;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800111 this.id = id;
112 this.label = label;
Simon Hunt20e16792015-04-24 14:29:39 -0700113 this.iconId = iconId;
chengfan386620e2016-11-09 17:02:40 +0800114 this.helpPageUrl = (helpPageUrl == null) ?
115 DEFAULT_HELP_PAGE_URL : helpPageUrl;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800116 }
117
118 /**
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -0700119 * Returns the navigation category.
120 *
121 * @return navigation category
122 */
123 public Category category() {
124 return category;
125 }
126
127 /**
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800128 * Returns the view identifier.
129 *
Simon Hunt8add9ee2016-09-20 17:05:07 -0700130 * @return view ID
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800131 */
132 public String id() {
133 return id;
134 }
135
136 /**
137 * Returns the view label.
138 *
139 * @return view label
140 */
141 public String label() {
142 return label;
143 }
144
Simon Hunt20e16792015-04-24 14:29:39 -0700145 /**
Simon Hunt8add9ee2016-09-20 17:05:07 -0700146 * Returns the icon identifier.
Simon Hunt20e16792015-04-24 14:29:39 -0700147 *
148 * @return icon ID
149 */
150 public String iconId() {
151 return iconId;
152 }
153
chengfan386620e2016-11-09 17:02:40 +0800154 /**
155 * Returns the help page URL for a specific view.
156 *
157 * @return help page URL
158 */
159 public String helpPageUrl() {
160 return helpPageUrl;
161 }
162
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800163 @Override
164 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -0700165 return id.hashCode();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800166 }
167
168 @Override
169 public boolean equals(Object obj) {
170 if (this == obj) {
171 return true;
172 }
173 if (obj == null || getClass() != obj.getClass()) {
174 return false;
175 }
Simon Hunt8add9ee2016-09-20 17:05:07 -0700176 UiView other = (UiView) obj;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800177 return Objects.equals(this.id, other.id);
178 }
179
180 @Override
181 public String toString() {
182 return MoreObjects.toStringHelper(this)
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -0700183 .add("category", category)
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800184 .add("id", id)
185 .add("label", label)
Simon Hunt20e16792015-04-24 14:29:39 -0700186 .add("iconId", iconId)
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800187 .toString();
188 }
189}