blob: 4234e982e612eb2c1ebc5f2ebbb84ed6f87c51b4 [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 {
34 /**
35 * Represents platform related views.
36 */
37 PLATFORM("Platform"),
38
39 /**
40 * Represents network-control related views.
41 */
42 NETWORK("Network"),
43
44 /**
45 * Represents miscellaneous views.
46 */
Simon Hunt38c2b6a2015-04-24 13:02:05 -070047 OTHER("Other"),
48
49 /**
50 * Represents views that do not show in the navigation menu.
51 * This category should not be specified directly; rather, use
52 * the {@link UiViewHidden} constructor instead of {@link UiView}.
53 */
54 HIDDEN("(hidden)");
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070055
56 private final String label;
57
58 Category(String label) {
59 this.label = label;
60 }
61
62 /**
Simon Hunt8add9ee2016-09-20 17:05:07 -070063 * Returns the display label for the category.
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070064 *
65 * @return display label
66 */
67 public String label() {
68 return label;
69 }
70 }
71
Simon Hunt20e16792015-04-24 14:29:39 -070072 private final Category category;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080073 private final String id;
74 private final String label;
Simon Hunt20e16792015-04-24 14:29:39 -070075 private final String iconId;
chengfan386620e2016-11-09 17:02:40 +080076 private final String helpPageUrl;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080077
78 /**
Simon Hunt38c2b6a2015-04-24 13:02:05 -070079 * Creates a new user interface view descriptor. The navigation item
80 * will appear in the navigation menu under the specified category.
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080081 *
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070082 * @param category view category
83 * @param id view identifier
84 * @param label view label
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080085 */
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070086 public UiView(Category category, String id, String label) {
chengfan386620e2016-11-09 17:02:40 +080087 this(category, id, label, null, null);
Simon Hunt20e16792015-04-24 14:29:39 -070088 }
89
90 /**
91 * Creates a new user interface view descriptor. The navigation item
92 * will appear in the navigation menu under the specified category,
93 * with the specified icon adornment.
Simon Hunt8add9ee2016-09-20 17:05:07 -070094 * <p>
95 * Note: see the {@code glyphMapping} structure in {@code icon.js} for
96 * valid icon identifiers.
Simon Hunt20e16792015-04-24 14:29:39 -070097 *
98 * @param category view category
99 * @param id view identifier
100 * @param label view label
101 * @param iconId icon id
102 */
103 public UiView(Category category, String id, String label, String iconId) {
chengfan386620e2016-11-09 17:02:40 +0800104 this(category, id, label, iconId, null);
105 }
106
107 /**
108 * Creates a new user interface view descriptor. The navigation item
109 * will appear in the navigation menu under the specified category,
110 * with the specified icon adornment and specified help page.
111 * <p>
112 * Note: see the {@code glyphMapping} structure in {@code icon.js} for
113 * valid icon identifiers.
114 *
115 * @param category view category
116 * @param id view identifier
117 * @param label view label
118 * @param iconId icon id
119 * @param helpPageUrl help page URL
120 */
121 public UiView(Category category, String id, String label, String iconId,
122 String helpPageUrl) {
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -0700123 this.category = category;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800124 this.id = id;
125 this.label = label;
Simon Hunt20e16792015-04-24 14:29:39 -0700126 this.iconId = iconId;
chengfan386620e2016-11-09 17:02:40 +0800127 this.helpPageUrl = (helpPageUrl == null) ?
128 DEFAULT_HELP_PAGE_URL : helpPageUrl;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800129 }
130
131 /**
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -0700132 * Returns the navigation category.
133 *
134 * @return navigation category
135 */
136 public Category category() {
137 return category;
138 }
139
140 /**
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800141 * Returns the view identifier.
142 *
Simon Hunt8add9ee2016-09-20 17:05:07 -0700143 * @return view ID
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800144 */
145 public String id() {
146 return id;
147 }
148
149 /**
150 * Returns the view label.
151 *
152 * @return view label
153 */
154 public String label() {
155 return label;
156 }
157
Simon Hunt20e16792015-04-24 14:29:39 -0700158 /**
Simon Hunt8add9ee2016-09-20 17:05:07 -0700159 * Returns the icon identifier.
Simon Hunt20e16792015-04-24 14:29:39 -0700160 *
161 * @return icon ID
162 */
163 public String iconId() {
164 return iconId;
165 }
166
chengfan386620e2016-11-09 17:02:40 +0800167 /**
168 * Returns the help page URL for a specific view.
169 *
170 * @return help page URL
171 */
172 public String helpPageUrl() {
173 return helpPageUrl;
174 }
175
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800176 @Override
177 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -0700178 return id.hashCode();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800179 }
180
181 @Override
182 public boolean equals(Object obj) {
183 if (this == obj) {
184 return true;
185 }
186 if (obj == null || getClass() != obj.getClass()) {
187 return false;
188 }
Simon Hunt8add9ee2016-09-20 17:05:07 -0700189 UiView other = (UiView) obj;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800190 return Objects.equals(this.id, other.id);
191 }
192
193 @Override
194 public String toString() {
195 return MoreObjects.toStringHelper(this)
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -0700196 .add("category", category)
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800197 .add("id", id)
198 .add("label", label)
Simon Hunt20e16792015-04-24 14:29:39 -0700199 .add("iconId", iconId)
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800200 .toString();
201 }
202}