Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.ui; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | |
| 20 | import java.util.Objects; |
| 21 | |
| 22 | /** |
| 23 | * Represents user interface view addition. |
| 24 | */ |
| 25 | public class UiView { |
| 26 | |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 27 | /** |
| 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 Hunt | 38c2b6a | 2015-04-24 13:02:05 -0700 | [diff] [blame] | 44 | 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 Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 52 | |
| 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 Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 69 | private final Category category; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 70 | private final String id; |
| 71 | private final String label; |
Simon Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 72 | private final String iconId; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 73 | |
| 74 | /** |
Simon Hunt | 38c2b6a | 2015-04-24 13:02:05 -0700 | [diff] [blame] | 75 | * Creates a new user interface view descriptor. The navigation item |
| 76 | * will appear in the navigation menu under the specified category. |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 77 | * |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 78 | * @param category view category |
| 79 | * @param id view identifier |
| 80 | * @param label view label |
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 | public UiView(Category category, String id, String label) { |
Simon Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 83 | 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 Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 97 | this.category = category; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 98 | this.id = id; |
| 99 | this.label = label; |
Simon Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 100 | this.iconId = iconId; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /** |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 104 | * Returns the navigation category. |
| 105 | * |
| 106 | * @return navigation category |
| 107 | */ |
| 108 | public Category category() { |
| 109 | return category; |
| 110 | } |
| 111 | |
| 112 | /** |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 113 | * 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 Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 130 | /** |
| 131 | * Returns the icon ID. |
| 132 | * |
| 133 | * @return icon ID |
| 134 | */ |
| 135 | public String iconId() { |
| 136 | return iconId; |
| 137 | } |
| 138 | |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 139 | @Override |
| 140 | public int hashCode() { |
HIGUCHI Yuta | ca9cc8e | 2015-10-29 23:26:51 -0700 | [diff] [blame] | 141 | return id.hashCode(); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 142 | } |
| 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 Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 159 | .add("category", category) |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 160 | .add("id", id) |
| 161 | .add("label", label) |
Simon Hunt | 20e1679 | 2015-04-24 14:29:39 -0700 | [diff] [blame] | 162 | .add("iconId", iconId) |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 163 | .toString(); |
| 164 | } |
| 165 | } |