Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
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 { |
Simon Hunt | 23f9c7b | 2017-07-10 20:00:30 -0700 | [diff] [blame] | 34 | // NOTE: human readable strings for the categories are now applied |
| 35 | // externally, with the appropriate localization bundle. |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 36 | /** |
| 37 | * Represents platform related views. |
| 38 | */ |
Simon Hunt | 23f9c7b | 2017-07-10 20:00:30 -0700 | [diff] [blame] | 39 | PLATFORM, |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Represents network-control related views. |
| 43 | */ |
Simon Hunt | 23f9c7b | 2017-07-10 20:00:30 -0700 | [diff] [blame] | 44 | NETWORK, |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * Represents miscellaneous views. |
| 48 | */ |
Simon Hunt | 23f9c7b | 2017-07-10 20:00:30 -0700 | [diff] [blame] | 49 | OTHER, |
Simon Hunt | 38c2b6a | 2015-04-24 13:02:05 -0700 | [diff] [blame] | 50 | |
| 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 Hunt | 23f9c7b | 2017-07-10 20:00:30 -0700 | [diff] [blame] | 56 | HIDDEN |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Simon Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 59 | private final Category category; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 60 | private final String id; |
| 61 | private final String label; |
Simon Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 62 | private final String iconId; |
chengfan | 386620e | 2016-11-09 17:02:40 +0800 | [diff] [blame] | 63 | private final String helpPageUrl; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 64 | |
| 65 | /** |
Simon Hunt | 38c2b6a | 2015-04-24 13:02:05 -0700 | [diff] [blame] | 66 | * Creates a new user interface view descriptor. The navigation item |
| 67 | * will appear in the navigation menu under the specified category. |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 68 | * |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 69 | * @param category view category |
| 70 | * @param id view identifier |
| 71 | * @param label view label |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 72 | */ |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 73 | public UiView(Category category, String id, String label) { |
chengfan | 386620e | 2016-11-09 17:02:40 +0800 | [diff] [blame] | 74 | this(category, id, label, null, null); |
Simon Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 75 | } |
| 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 Hunt | 8add9ee | 2016-09-20 17:05:07 -0700 | [diff] [blame] | 81 | * <p> |
| 82 | * Note: see the {@code glyphMapping} structure in {@code icon.js} for |
| 83 | * valid icon identifiers. |
Simon Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 84 | * |
| 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) { |
chengfan | 386620e | 2016-11-09 17:02:40 +0800 | [diff] [blame] | 91 | 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 Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 110 | this.category = category; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 111 | this.id = id; |
| 112 | this.label = label; |
Simon Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 113 | this.iconId = iconId; |
chengfan | 386620e | 2016-11-09 17:02:40 +0800 | [diff] [blame] | 114 | this.helpPageUrl = (helpPageUrl == null) ? |
| 115 | DEFAULT_HELP_PAGE_URL : helpPageUrl; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /** |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 119 | * Returns the navigation category. |
| 120 | * |
| 121 | * @return navigation category |
| 122 | */ |
| 123 | public Category category() { |
| 124 | return category; |
| 125 | } |
| 126 | |
| 127 | /** |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 128 | * Returns the view identifier. |
| 129 | * |
Simon Hunt | 8add9ee | 2016-09-20 17:05:07 -0700 | [diff] [blame] | 130 | * @return view ID |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 131 | */ |
| 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 Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 145 | /** |
Simon Hunt | 8add9ee | 2016-09-20 17:05:07 -0700 | [diff] [blame] | 146 | * Returns the icon identifier. |
Simon Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 147 | * |
| 148 | * @return icon ID |
| 149 | */ |
| 150 | public String iconId() { |
| 151 | return iconId; |
| 152 | } |
| 153 | |
chengfan | 386620e | 2016-11-09 17:02:40 +0800 | [diff] [blame] | 154 | /** |
| 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 Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 163 | @Override |
| 164 | public int hashCode() { |
HIGUCHI Yuta | ca9cc8e | 2015-10-29 23:26:51 -0700 | [diff] [blame] | 165 | return id.hashCode(); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 166 | } |
| 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 Hunt | 8add9ee | 2016-09-20 17:05:07 -0700 | [diff] [blame] | 176 | UiView other = (UiView) obj; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 177 | return Objects.equals(this.id, other.id); |
| 178 | } |
| 179 | |
| 180 | @Override |
| 181 | public String toString() { |
| 182 | return MoreObjects.toStringHelper(this) |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 183 | .add("category", category) |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 184 | .add("id", id) |
| 185 | .add("label", label) |
Simon Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 186 | .add("iconId", iconId) |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 187 | .toString(); |
| 188 | } |
| 189 | } |