blob: c86711594887bacc452cea16086717c887e066de [file] [log] [blame]
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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/**
23 * Represents user interface view addition.
24 */
25public class UiView {
26
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070027 /**
28 * Designates navigation menu category.
29 */
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 /**
60 * Returns display label for the category.
61 *
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.
90 *
91 * @param category view category
92 * @param id view identifier
93 * @param label view label
94 * @param iconId icon id
95 */
96 public UiView(Category category, String id, String label, String iconId) {
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070097 this.category = category;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080098 this.id = id;
99 this.label = label;
Simon Hunt20e16792015-04-24 14:29:39 -0700100 this.iconId = iconId;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800101 }
102
103 /**
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -0700104 * Returns the navigation category.
105 *
106 * @return navigation category
107 */
108 public Category category() {
109 return category;
110 }
111
112 /**
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800113 * Returns the view identifier.
114 *
115 * @return view id
116 */
117 public String id() {
118 return id;
119 }
120
121 /**
122 * Returns the view label.
123 *
124 * @return view label
125 */
126 public String label() {
127 return label;
128 }
129
Simon Hunt20e16792015-04-24 14:29:39 -0700130 /**
131 * Returns the icon ID.
132 *
133 * @return icon ID
134 */
135 public String iconId() {
136 return iconId;
137 }
138
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800139 @Override
140 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -0700141 return id.hashCode();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800142 }
143
144 @Override
145 public boolean equals(Object obj) {
146 if (this == obj) {
147 return true;
148 }
149 if (obj == null || getClass() != obj.getClass()) {
150 return false;
151 }
152 final UiView other = (UiView) obj;
153 return Objects.equals(this.id, other.id);
154 }
155
156 @Override
157 public String toString() {
158 return MoreObjects.toStringHelper(this)
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -0700159 .add("category", category)
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800160 .add("id", id)
161 .add("label", label)
Simon Hunt20e16792015-04-24 14:29:39 -0700162 .add("iconId", iconId)
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800163 .toString();
164 }
165}