Simon Hunt | f679c4e | 2016-04-01 17:02:24 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Simon Hunt | f679c4e | 2016-04-01 17:02:24 -0700 | [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 | |
| 17 | package org.onosproject.ui.model.topo; |
| 18 | |
| 19 | import org.onosproject.net.region.Region; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 20 | import org.onosproject.net.region.RegionId; |
Simon Hunt | f679c4e | 2016-04-01 17:02:24 -0700 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * Represents a specific "subset" of the UI model of the network topology |
| 24 | * that a user might wish to view. Backed by a {@link Region}. |
| 25 | */ |
| 26 | public class UiTopoLayout { |
| 27 | |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 28 | private final UiTopoLayoutId id; |
| 29 | private final Region region; |
Thomas Vachuska | 92b016b | 2016-05-20 11:37:57 -0700 | [diff] [blame] | 30 | private final UiTopoLayoutId parent; |
Simon Hunt | f679c4e | 2016-04-01 17:02:24 -0700 | [diff] [blame] | 31 | |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Created a new UI topology layout. |
| 34 | * |
| 35 | * @param id layout identifier |
| 36 | * @param region backing region |
Thomas Vachuska | 92b016b | 2016-05-20 11:37:57 -0700 | [diff] [blame] | 37 | * @param parent identifier of the parent layout |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 38 | */ |
Thomas Vachuska | 92b016b | 2016-05-20 11:37:57 -0700 | [diff] [blame] | 39 | public UiTopoLayout(UiTopoLayoutId id, Region region, UiTopoLayoutId parent) { |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 40 | this.id = id; |
| 41 | this.region = region; |
Simon Hunt | 9818919 | 2016-07-29 19:02:27 -0700 | [diff] [blame] | 42 | // NOTE: root layout is its own parent... |
| 43 | this.parent = parent != null ? parent : this.id; |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 46 | @Override |
| 47 | public String toString() { |
| 48 | return "{UiTopoLayout: " + id + "}"; |
| 49 | } |
| 50 | |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 51 | /** |
| 52 | * Returns the UI layout identifier. |
| 53 | * |
| 54 | * @return identifier of the layout |
| 55 | */ |
| 56 | public UiTopoLayoutId id() { |
| 57 | return id; |
| 58 | } |
| 59 | |
| 60 | /** |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 61 | * Returns the backing region with which this layout is associated. Note |
| 62 | * that this may be null (for the root layout). |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 63 | * |
| 64 | * @return backing region |
| 65 | */ |
| 66 | public Region region() { |
| 67 | return region; |
| 68 | } |
| 69 | |
Thomas Vachuska | 92b016b | 2016-05-20 11:37:57 -0700 | [diff] [blame] | 70 | /** |
Simon Hunt | 4f4ffc3 | 2016-08-03 18:30:47 -0700 | [diff] [blame] | 71 | * Returns the identifier of the backing region. If this is the default |
| 72 | * layout, the null-region ID will be returned, otherwise the ID of the |
| 73 | * backing region for this layout will be returned; null in the case that |
| 74 | * there is no backing region. |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 75 | * |
| 76 | * @return backing region identifier |
| 77 | */ |
| 78 | public RegionId regionId() { |
Simon Hunt | 4f4ffc3 | 2016-08-03 18:30:47 -0700 | [diff] [blame] | 79 | return isRoot() ? UiRegion.NULL_ID |
| 80 | : (region == null ? null : region.id()); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | /** |
Thomas Vachuska | 92b016b | 2016-05-20 11:37:57 -0700 | [diff] [blame] | 84 | * Returns the parent layout identifier. |
| 85 | * |
| 86 | * @return parent layout identifier |
| 87 | */ |
| 88 | public UiTopoLayoutId parent() { |
| 89 | return parent; |
| 90 | } |
| 91 | |
Simon Hunt | 9818919 | 2016-07-29 19:02:27 -0700 | [diff] [blame] | 92 | /** |
| 93 | * Returns true if this layout instance is at the top of the |
| 94 | * hierarchy tree. |
| 95 | * |
| 96 | * @return true if this is the root layout |
| 97 | */ |
| 98 | public boolean isRoot() { |
| 99 | return id.equals(parent); |
| 100 | } |
Simon Hunt | f679c4e | 2016-04-01 17:02:24 -0700 | [diff] [blame] | 101 | } |