1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.uruma.context.impl;
17
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.HashSet;
21 import java.util.List;
22 import java.util.Set;
23
24 import org.seasar.uruma.binding.enables.EnablesDependingDef;
25 import org.seasar.uruma.context.ApplicationContext;
26 import org.seasar.uruma.context.PartContext;
27 import org.seasar.uruma.context.WidgetHandle;
28 import org.seasar.uruma.context.WindowContext;
29 import org.seasar.uruma.desc.FormDesc;
30 import org.seasar.uruma.desc.PartActionDesc;
31 import org.seasar.uruma.exception.DuplicateComponentIdException;
32 import org.seasar.uruma.util.AssertionUtil;
33
34
35
36
37
38
39 public class WindowContextImpl extends AbstractWidgetHolder implements
40 WindowContext {
41
42 private String windowName;
43
44 private List<PartContext> partContextList = new ArrayList<PartContext>();
45
46 private ApplicationContextImpl parent;
47
48 private List<EnablesDependingDef> enablesDependingDefList = new ArrayList<EnablesDependingDef>();
49
50 private Object partActionObj;
51
52 private PartActionDesc partActionDesc;
53
54
55
56
57
58
59
60
61
62 public WindowContextImpl(final String windowName,
63 final ApplicationContext parent) {
64 super();
65
66 this.windowName = windowName;
67 this.parent = (ApplicationContextImpl) parent;
68 }
69
70
71
72
73 public String getName() {
74 return this.windowName;
75 }
76
77
78
79
80 public PartContext getPartContext() {
81 if ((partContextList != null) && (partContextList.size() > 0)) {
82 return partContextList.get(0);
83 } else {
84 return null;
85 }
86 }
87
88
89
90
91 public PartContext getPartContext(final String partName) {
92 for (PartContext context : partContextList) {
93 if (context.getName().equals(partName)) {
94 return context;
95 }
96 }
97 return null;
98 }
99
100
101
102
103 public List<PartContext> getPartContextList() {
104 return Collections.unmodifiableList(partContextList);
105 }
106
107
108
109
110 public ApplicationContext getApplicationContext() {
111 return parent;
112 }
113
114
115
116
117
118
119
120
121
122 public void addPartContext(final PartContext context) {
123 if (getPartContext(context.getName()) == null) {
124 partContextList.add(context);
125 } else {
126 throw new DuplicateComponentIdException(context.getName());
127 }
128 }
129
130
131
132
133
134
135
136 public void disposePartContext(final String partName) {
137 PartContext partContext = getPartContext(partName);
138 if (partContext != null) {
139 partContextList.remove(partContext);
140 }
141 }
142
143
144
145
146 public void dispose() {
147 for (PartContext part : partContextList) {
148 disposePartContext(part.getName());
149 }
150 parent.disposeWindowContext(windowName);
151 parent = null;
152 }
153
154
155
156
157 public Set<WidgetHandle> findWidgetHandles(final String handleId) {
158 Set<WidgetHandle> results = new HashSet<WidgetHandle>();
159
160 WidgetHandle handle = getWidgetHandle(handleId);
161 if (handle != null) {
162 results.add(handle);
163 }
164
165 for (PartContext part : getPartContextList()) {
166 handle = part.getWidgetHandle(handleId);
167 if (handle != null) {
168 results.add(handle);
169 }
170 }
171 return results;
172 }
173
174
175
176
177 public Set<WidgetHandle> getAllWidgetHandles(final Class<?> clazz) {
178 Set<WidgetHandle> handles = new HashSet<WidgetHandle>();
179 handles.addAll(getWidgetHandles(clazz));
180
181 for (PartContext part : getPartContextList()) {
182 handles.addAll(part.getWidgetHandles(clazz));
183 }
184
185 return handles;
186 }
187
188
189
190
191
192 public void addEnablesDependingDef(
193 final EnablesDependingDef enablesDependingDef) {
194 AssertionUtil.assertNotNull("enablesDependingDef", enablesDependingDef);
195 enablesDependingDefList.add(enablesDependingDef);
196 }
197
198
199
200
201 public List<EnablesDependingDef> getEnablesDependingDefList() {
202 return Collections.unmodifiableList(enablesDependingDefList);
203 }
204
205
206
207
208 public Object getPartActionObject() {
209 return this.partActionObj;
210 }
211
212
213
214
215 public void setPartActionDesc(final PartActionDesc desc) {
216 this.partActionDesc = desc;
217 }
218
219
220
221
222
223 public void setPartActionObject(final Object partActionObj) {
224 this.partActionObj = partActionObj;
225 }
226
227
228
229
230 public PartActionDesc getPartActionDesc() {
231 return this.partActionDesc;
232 }
233
234
235
236
237 public WindowContext getWindowContext() {
238 return this;
239 }
240
241
242
243
244 public FormDesc getFormDesc() {
245
246 return null;
247 }
248
249
250
251
252 public Object getFormObject() {
253
254 return null;
255 }
256
257
258
259
260 public void setFormDesc(final FormDesc desc) {
261
262 }
263
264
265
266
267 public void setFormObject(final Object object) {
268
269 }
270
271 }