1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.templating.editor.client.dom;
35
36 import info.magnolia.templating.editor.client.AbstractBarWidget;
37
38 import java.util.LinkedList;
39
40 import com.google.gwt.dom.client.Element;
41
42
43
44
45
46
47 public class CMSBoundary {
48
49 private AbstractBarWidget widget;
50 private CMSComment comment;
51 private CMSBoundary parentBoundary;
52 private boolean isArea = false;
53 private boolean isComponent = false;
54
55 private Coordinate maxCoordinate = new Coordinate();
56 private Coordinate minCoordinate = new Coordinate();
57
58 private Element firstElement;
59 public Element getFirstElement() {
60 return firstElement;
61 }
62
63 public void setFirstElement(Element firstElement) {
64 this.firstElement = firstElement;
65 }
66
67 public Coordinate getMaxCoordinate() {
68 return maxCoordinate;
69 }
70
71 public Coordinate getMinCoordinate() {
72 return minCoordinate;
73 }
74
75 private LinkedList<CMSBoundary> childBoundaries = new LinkedList<CMSBoundary>();
76 private boolean isEdit;
77
78 public static final String MARKER_AREA = "cms:area";
79 public static final String MARKER_COMPONENT = "cms:component";
80 public static final String MARKER_EDIT = "cms:edit";
81
82 public CMSBoundary(CMSComment comment, CMSBoundary parentBoundary) throws IllegalArgumentException {
83
84 if (!isCmsBoundary(comment.getTagName())) {
85 throw new IllegalArgumentException("The tagname must be one of the defined marker Strings.");
86 }
87
88 this.setComment(comment);
89 this.setParentBoundary(parentBoundary);
90 }
91
92 public String getContent() {
93 return this.getComment().getAttribute("cms:content");
94 }
95
96 public void setParentBoundary(CMSBoundary parentBoundary) {
97 this.parentBoundary = parentBoundary;
98 }
99
100 public CMSBoundary getParentBoundary() {
101 return parentBoundary;
102 }
103
104 public void setChildBoundaries(LinkedList<CMSBoundary> childBoundaries) {
105 this.childBoundaries = childBoundaries;
106 }
107
108 public LinkedList<CMSBoundary> getChildBoundaries() {
109 return childBoundaries;
110 }
111
112 public boolean hasChildBoundaries() {
113 return (getChildBoundaries().size() > 0);
114 }
115
116 public LinkedList<CMSBoundary> getDescendants() {
117
118 LinkedList<CMSBoundary> descendants = new LinkedList<CMSBoundary>();
119
120 for (CMSBoundary boundary : getChildBoundaries()) {
121 descendants.add(boundary);
122 descendants.addAll(boundary.getDescendants());
123 }
124 return descendants;
125 }
126
127 public LinkedList<CMSBoundary> getAscendants() {
128 LinkedList<CMSBoundary> ascendants = new LinkedList<CMSBoundary>();
129 CMSBoundary parent = this.parentBoundary;
130 while (parent != null) {
131 ascendants.add(parent);
132 parent = parent.getParentBoundary();
133 }
134 return ascendants;
135 }
136
137 public CMSBoundary getParentArea() {
138
139 if (isArea()) {
140 return this;
141 }
142 else if (getParentBoundary() != null) {
143 return getParentBoundary().getParentArea();
144 }
145
146 return getParentBoundary().getParentArea();
147
148
149 }
150
151 public boolean isCmsBoundary(String tagName) {
152 if (tagName.equals(MARKER_AREA)) {
153 this.isArea = true;
154 return true;
155 }
156 else if (tagName.equals(MARKER_COMPONENT)) {
157 this.isComponent = true;
158 return true;
159 }
160 else if (tagName.equals(MARKER_EDIT)) {
161 this.isEdit = true;
162 return true;
163 }
164
165 return false;
166 }
167 public boolean isArea() {
168 return isArea;
169 }
170 public boolean isEdit() {
171 return isEdit;
172 }
173
174 public boolean isComponent() {
175 return isComponent;
176 }
177 public void setComment(CMSComment comment) {
178 this.comment = comment;
179 }
180
181 public CMSComment getComment() {
182 return comment;
183 }
184
185 public void setWidget(AbstractBarWidget widget) {
186 this.widget = widget;
187 }
188
189 public AbstractBarWidget getWidget() {
190 return widget;
191 }
192
193
194
195
196 public class Coordinate {
197 private int left = 0;
198 private int top = 0;
199
200 public void setLeft(int left) {
201 this.left = left;
202 }
203 public int getLeft() {
204 return left;
205 }
206 public void setTop(int top) {
207 this.top = top;
208 }
209 public int getTop() {
210 return top;
211 }
212
213 }
214 }