Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.ui; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | |
| 20 | import java.util.Objects; |
| 21 | |
| 22 | /** |
Simon Hunt | 8add9ee | 2016-09-20 17:05:07 -0700 | [diff] [blame] | 23 | * Represents a user interface view addition. |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 24 | */ |
| 25 | public class UiView { |
| 26 | |
chengfan | 386620e | 2016-11-09 17:02:40 +0800 | [diff] [blame] | 27 | private static final String DEFAULT_HELP_PAGE_URL = |
| 28 | "https://wiki.onosproject.org/display/ONOS/The+ONOS+Web+GUI"; |
| 29 | |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 30 | /** |
Simon Hunt | 8add9ee | 2016-09-20 17:05:07 -0700 | [diff] [blame] | 31 | * Designates the navigation menu category. |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 32 | */ |
| 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 Hunt | 38c2b6a | 2015-04-24 13:02:05 -0700 | [diff] [blame] | 47 | 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 Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 55 | |
| 56 | private final String label; |
| 57 | |
| 58 | Category(String label) { |
| 59 | this.label = label; |
| 60 | } |
| 61 | |
| 62 | /** |
Simon Hunt | 8add9ee | 2016-09-20 17:05:07 -0700 | [diff] [blame] | 63 | * Returns the display label for the category. |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 64 | * |
| 65 | * @return display label |
| 66 | */ |
| 67 | public String label() { |
| 68 | return label; |
| 69 | } |
| 70 | } |
| 71 | |
Simon Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 72 | private final Category category; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 73 | private final String id; |
| 74 | private final String label; |
Simon Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 75 | private final String iconId; |
chengfan | 386620e | 2016-11-09 17:02:40 +0800 | [diff] [blame] | 76 | private final String helpPageUrl; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 77 | |
| 78 | /** |
Simon Hunt | 38c2b6a | 2015-04-24 13:02:05 -0700 | [diff] [blame] | 79 | * Creates a new user interface view descriptor. The navigation item |
| 80 | * will appear in the navigation menu under the specified category. |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 81 | * |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 82 | * @param category view category |
| 83 | * @param id view identifier |
| 84 | * @param label view label |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 85 | */ |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 86 | public UiView(Category category, String id, String label) { |
chengfan | 386620e | 2016-11-09 17:02:40 +0800 | [diff] [blame] | 87 | this(category, id, label, null, null); |
Simon Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 88 | } |
| 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 Hunt | 8add9ee | 2016-09-20 17:05:07 -0700 | [diff] [blame] | 94 | * <p> |
| 95 | * Note: see the {@code glyphMapping} structure in {@code icon.js} for |
| 96 | * valid icon identifiers. |
Simon Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 97 | * |
| 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) { |
chengfan | 386620e | 2016-11-09 17:02:40 +0800 | [diff] [blame] | 104 | 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 Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 123 | this.category = category; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 124 | this.id = id; |
| 125 | this.label = label; |
Simon Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 126 | this.iconId = iconId; |
chengfan | 386620e | 2016-11-09 17:02:40 +0800 | [diff] [blame] | 127 | this.helpPageUrl = (helpPageUrl == null) ? |
| 128 | DEFAULT_HELP_PAGE_URL : helpPageUrl; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | /** |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 132 | * Returns the navigation category. |
| 133 | * |
| 134 | * @return navigation category |
| 135 | */ |
| 136 | public Category category() { |
| 137 | return category; |
| 138 | } |
| 139 | |
| 140 | /** |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 141 | * Returns the view identifier. |
| 142 | * |
Simon Hunt | 8add9ee | 2016-09-20 17:05:07 -0700 | [diff] [blame] | 143 | * @return view ID |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 144 | */ |
| 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 Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 158 | /** |
Simon Hunt | 8add9ee | 2016-09-20 17:05:07 -0700 | [diff] [blame] | 159 | * Returns the icon identifier. |
Simon Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 160 | * |
| 161 | * @return icon ID |
| 162 | */ |
| 163 | public String iconId() { |
| 164 | return iconId; |
| 165 | } |
| 166 | |
chengfan | 386620e | 2016-11-09 17:02:40 +0800 | [diff] [blame] | 167 | /** |
| 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 Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 176 | @Override |
| 177 | public int hashCode() { |
HIGUCHI Yuta | ca9cc8e | 2015-10-29 23:26:51 -0700 | [diff] [blame] | 178 | return id.hashCode(); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 179 | } |
| 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 Hunt | 8add9ee | 2016-09-20 17:05:07 -0700 | [diff] [blame] | 189 | UiView other = (UiView) obj; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 190 | return Objects.equals(this.id, other.id); |
| 191 | } |
| 192 | |
| 193 | @Override |
| 194 | public String toString() { |
| 195 | return MoreObjects.toStringHelper(this) |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 196 | .add("category", category) |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 197 | .add("id", id) |
| 198 | .add("label", label) |
Simon Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 199 | .add("iconId", iconId) |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 200 | .toString(); |
| 201 | } |
| 202 | } |