blob: 63cd4687359ee5d32e051ded07467b928f824d8f [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
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070027 /**
Simon Hunt8add9ee2016-09-20 17:05:07 -070028 * Designates the navigation menu category.
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070029 */
30 public enum Category {
31 /**
32 * Represents platform related views.
33 */
34 PLATFORM("Platform"),
35
36 /**
37 * Represents network-control related views.
38 */
39 NETWORK("Network"),
40
41 /**
42 * Represents miscellaneous views.
43 */
Simon Hunt38c2b6a2015-04-24 13:02:05 -070044 OTHER("Other"),
45
46 /**
47 * Represents views that do not show in the navigation menu.
48 * This category should not be specified directly; rather, use
49 * the {@link UiViewHidden} constructor instead of {@link UiView}.
50 */
51 HIDDEN("(hidden)");
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070052
53 private final String label;
54
55 Category(String label) {
56 this.label = label;
57 }
58
59 /**
Simon Hunt8add9ee2016-09-20 17:05:07 -070060 * Returns the display label for the category.
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070061 *
62 * @return display label
63 */
64 public String label() {
65 return label;
66 }
67 }
68
Simon Hunt20e16792015-04-24 14:29:39 -070069 private final Category category;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080070 private final String id;
71 private final String label;
Simon Hunt20e16792015-04-24 14:29:39 -070072 private final String iconId;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080073
74 /**
Simon Hunt38c2b6a2015-04-24 13:02:05 -070075 * Creates a new user interface view descriptor. The navigation item
76 * will appear in the navigation menu under the specified category.
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080077 *
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070078 * @param category view category
79 * @param id view identifier
80 * @param label view label
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080081 */
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070082 public UiView(Category category, String id, String label) {
Simon Hunt20e16792015-04-24 14:29:39 -070083 this(category, id, label, null);
84 }
85
86 /**
87 * Creates a new user interface view descriptor. The navigation item
88 * will appear in the navigation menu under the specified category,
89 * with the specified icon adornment.
Simon Hunt8add9ee2016-09-20 17:05:07 -070090 * <p>
91 * Note: see the {@code glyphMapping} structure in {@code icon.js} for
92 * valid icon identifiers.
Simon Hunt20e16792015-04-24 14:29:39 -070093 *
94 * @param category view category
95 * @param id view identifier
96 * @param label view label
97 * @param iconId icon id
98 */
99 public UiView(Category category, String id, String label, String iconId) {
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -0700100 this.category = category;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800101 this.id = id;
102 this.label = label;
Simon Hunt20e16792015-04-24 14:29:39 -0700103 this.iconId = iconId;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800104 }
105
106 /**
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -0700107 * Returns the navigation category.
108 *
109 * @return navigation category
110 */
111 public Category category() {
112 return category;
113 }
114
115 /**
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800116 * Returns the view identifier.
117 *
Simon Hunt8add9ee2016-09-20 17:05:07 -0700118 * @return view ID
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800119 */
120 public String id() {
121 return id;
122 }
123
124 /**
125 * Returns the view label.
126 *
127 * @return view label
128 */
129 public String label() {
130 return label;
131 }
132
Simon Hunt20e16792015-04-24 14:29:39 -0700133 /**
Simon Hunt8add9ee2016-09-20 17:05:07 -0700134 * Returns the icon identifier.
Simon Hunt20e16792015-04-24 14:29:39 -0700135 *
136 * @return icon ID
137 */
138 public String iconId() {
139 return iconId;
140 }
141
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800142 @Override
143 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -0700144 return id.hashCode();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800145 }
146
147 @Override
148 public boolean equals(Object obj) {
149 if (this == obj) {
150 return true;
151 }
152 if (obj == null || getClass() != obj.getClass()) {
153 return false;
154 }
Simon Hunt8add9ee2016-09-20 17:05:07 -0700155 UiView other = (UiView) obj;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800156 return Objects.equals(this.id, other.id);
157 }
158
159 @Override
160 public String toString() {
161 return MoreObjects.toStringHelper(this)
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -0700162 .add("category", category)
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800163 .add("id", id)
164 .add("label", label)
Simon Hunt20e16792015-04-24 14:29:39 -0700165 .add("iconId", iconId)
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800166 .toString();
167 }
168}