blob: ade86e14d9ffb914894d3c1b53299ead102adeee [file] [log] [blame]
Simon Huntf679c4e2016-04-01 17:02:24 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Simon Huntf679c4e2016-04-01 17:02:24 -07003 *
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
17package org.onosproject.ui.model.topo;
18
19import org.onosproject.net.region.Region;
Simon Huntd5b96732016-07-08 13:22:27 -070020import org.onosproject.net.region.RegionId;
Simon Huntf679c4e2016-04-01 17:02:24 -070021
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 */
26public class UiTopoLayout {
27
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070028 private final UiTopoLayoutId id;
29 private final Region region;
Thomas Vachuska92b016b2016-05-20 11:37:57 -070030 private final UiTopoLayoutId parent;
Simon Huntf679c4e2016-04-01 17:02:24 -070031
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070032 /**
33 * Created a new UI topology layout.
34 *
35 * @param id layout identifier
36 * @param region backing region
Thomas Vachuska92b016b2016-05-20 11:37:57 -070037 * @param parent identifier of the parent layout
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070038 */
Thomas Vachuska92b016b2016-05-20 11:37:57 -070039 public UiTopoLayout(UiTopoLayoutId id, Region region, UiTopoLayoutId parent) {
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070040 this.id = id;
41 this.region = region;
Simon Hunt98189192016-07-29 19:02:27 -070042 // NOTE: root layout is its own parent...
43 this.parent = parent != null ? parent : this.id;
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070044 }
45
Simon Huntd5b96732016-07-08 13:22:27 -070046 @Override
47 public String toString() {
48 return "{UiTopoLayout: " + id + "}";
49 }
50
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070051 /**
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 Huntd5b96732016-07-08 13:22:27 -070061 * Returns the backing region with which this layout is associated. Note
62 * that this may be null (for the root layout).
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070063 *
64 * @return backing region
65 */
66 public Region region() {
67 return region;
68 }
69
Thomas Vachuska92b016b2016-05-20 11:37:57 -070070 /**
Simon Hunt4f4ffc32016-08-03 18:30:47 -070071 * 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 Huntd5b96732016-07-08 13:22:27 -070075 *
76 * @return backing region identifier
77 */
78 public RegionId regionId() {
Simon Hunt4f4ffc32016-08-03 18:30:47 -070079 return isRoot() ? UiRegion.NULL_ID
80 : (region == null ? null : region.id());
Simon Huntd5b96732016-07-08 13:22:27 -070081 }
82
83 /**
Thomas Vachuska92b016b2016-05-20 11:37:57 -070084 * Returns the parent layout identifier.
85 *
86 * @return parent layout identifier
87 */
88 public UiTopoLayoutId parent() {
89 return parent;
90 }
91
Simon Hunt98189192016-07-29 19:02:27 -070092 /**
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 Huntf679c4e2016-04-01 17:02:24 -0700101}