blob: 12c9de6454489d9f0083d28ec5da9111405ec9cb [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 Huntd5b96732016-07-08 13:22:27 -070071 * Returns the identifier of the backing region. Will be null if the
72 * region is null.
73 *
74 * @return backing region identifier
75 */
76 public RegionId regionId() {
77 return region == null ? null : region.id();
78 }
79
80 /**
Thomas Vachuska92b016b2016-05-20 11:37:57 -070081 * Returns the parent layout identifier.
82 *
83 * @return parent layout identifier
84 */
85 public UiTopoLayoutId parent() {
86 return parent;
87 }
88
Simon Hunt98189192016-07-29 19:02:27 -070089 /**
90 * Returns true if this layout instance is at the top of the
91 * hierarchy tree.
92 *
93 * @return true if this is the root layout
94 */
95 public boolean isRoot() {
96 return id.equals(parent);
97 }
Simon Huntf679c4e2016-04-01 17:02:24 -070098}