1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.contrib.tree.components; |
16 |
| |
17 |
| import org.apache.commons.logging.Log; |
18 |
| import org.apache.commons.logging.LogFactory; |
19 |
| import org.apache.tapestry.BaseComponent; |
20 |
| import org.apache.tapestry.IBinding; |
21 |
| import org.apache.tapestry.IMarkupWriter; |
22 |
| import org.apache.tapestry.IRequestCycle; |
23 |
| import org.apache.tapestry.Tapestry; |
24 |
| import org.apache.tapestry.contrib.tree.model.ISessionStoreManager; |
25 |
| import org.apache.tapestry.contrib.tree.model.ITreeModel; |
26 |
| import org.apache.tapestry.contrib.tree.model.ITreeModelSource; |
27 |
| import org.apache.tapestry.contrib.tree.model.ITreeSessionStateManager; |
28 |
| import org.apache.tapestry.contrib.tree.model.ITreeStateListener; |
29 |
| import org.apache.tapestry.contrib.tree.simple.FullTreeSessionStateManager; |
30 |
| import org.apache.tapestry.event.PageBeginRenderListener; |
31 |
| import org.apache.tapestry.event.PageDetachListener; |
32 |
| import org.apache.tapestry.event.PageEvent; |
33 |
| import org.apache.tapestry.util.ComponentAddress; |
34 |
| |
35 |
| |
36 |
| |
37 |
| public abstract class TreeView extends BaseComponent implements PageDetachListener, |
38 |
| PageBeginRenderListener, ITreeModelSource |
39 |
| { |
40 |
| |
41 |
| private static final Log LOG = LogFactory.getLog(TreeView.class); |
42 |
| |
43 |
| private IBinding m_objSessionStoreManagerBinding; |
44 |
| |
45 |
| private IBinding m_objTreeModelBinding; |
46 |
| |
47 |
| private IBinding m_objSessionStateManagerBinding; |
48 |
| |
49 |
| private ITreeModel m_objTreeModel; |
50 |
| |
51 |
| private ITreeSessionStateManager m_objTreeSessionStateManager; |
52 |
| |
53 |
| private ISessionStoreManager m_objSessionStoreManager; |
54 |
| |
55 |
| private Object m_objTreeSessionState; |
56 |
| |
57 |
| private ComponentAddress m_objComponentAddress; |
58 |
| |
59 |
0
| public TreeView()
|
60 |
| { |
61 |
0
| super();
|
62 |
0
| initialize();
|
63 |
| } |
64 |
| |
65 |
0
| private void initialize()
|
66 |
| { |
67 |
0
| m_objTreeModel = null;
|
68 |
0
| m_objTreeSessionStateManager = null;
|
69 |
0
| m_objSessionStoreManager = null;
|
70 |
0
| m_objTreeSessionState = null;
|
71 |
0
| m_objComponentAddress = null;
|
72 |
| } |
73 |
| |
74 |
| |
75 |
| |
76 |
| |
77 |
| |
78 |
| |
79 |
| |
80 |
| |
81 |
0
| public void pageDetached(PageEvent arg0)
|
82 |
| { |
83 |
0
| initialize();
|
84 |
| } |
85 |
| |
86 |
| |
87 |
| |
88 |
| |
89 |
0
| public void pageBeginRender(PageEvent arg0)
|
90 |
| { |
91 |
0
| if (arg0.getRequestCycle().isRewinding())
|
92 |
| { |
93 |
0
| return;
|
94 |
| } |
95 |
0
| storeSesion();
|
96 |
| } |
97 |
| |
98 |
| |
99 |
| |
100 |
| |
101 |
| |
102 |
| |
103 |
0
| public IBinding getTreeModelBinding()
|
104 |
| { |
105 |
0
| return m_objTreeModelBinding;
|
106 |
| } |
107 |
| |
108 |
| |
109 |
| |
110 |
| |
111 |
| |
112 |
| |
113 |
| |
114 |
0
| public void setTreeModelBinding(IBinding treeModelBinding)
|
115 |
| { |
116 |
0
| m_objTreeModelBinding = treeModelBinding;
|
117 |
| } |
118 |
| |
119 |
| |
120 |
| |
121 |
| |
122 |
| |
123 |
| |
124 |
0
| public IBinding getSessionStoreManagerBinding()
|
125 |
| { |
126 |
0
| return m_objSessionStoreManagerBinding;
|
127 |
| } |
128 |
| |
129 |
| |
130 |
| |
131 |
| |
132 |
| |
133 |
| |
134 |
0
| public IBinding getSessionStateManagerBinding()
|
135 |
| { |
136 |
0
| return m_objSessionStateManagerBinding;
|
137 |
| } |
138 |
| |
139 |
| |
140 |
| |
141 |
| |
142 |
| |
143 |
| |
144 |
| |
145 |
0
| public void setSessionStoreManagerBinding(IBinding sessionStoreManagerBinding)
|
146 |
| { |
147 |
0
| m_objSessionStoreManagerBinding = sessionStoreManagerBinding;
|
148 |
| } |
149 |
| |
150 |
| |
151 |
| |
152 |
| |
153 |
| |
154 |
| |
155 |
| |
156 |
0
| public void setSessionStateManagerBinding(IBinding sessionStateManagerBinding)
|
157 |
| { |
158 |
0
| m_objSessionStateManagerBinding = sessionStateManagerBinding;
|
159 |
| } |
160 |
| |
161 |
0
| private void extractTreeModel()
|
162 |
| { |
163 |
0
| if (LOG.isDebugEnabled())
|
164 |
| { |
165 |
0
| LOG.debug("TreeView.extractTreeModel()");
|
166 |
| } |
167 |
| |
168 |
0
| ISessionStoreManager objHolder = getSessionStoreManager();
|
169 |
0
| ITreeSessionStateManager objSessionManager = getTreeSessionStateMgr();
|
170 |
0
| Object objSessionState;
|
171 |
0
| if (objHolder == null)
|
172 |
| { |
173 |
0
| objSessionState = getTreeSessionState();
|
174 |
| } |
175 |
| else |
176 |
| { |
177 |
0
| objSessionState = objHolder.getSessionState(this.getPage(), "treeSessionState");
|
178 |
| } |
179 |
| |
180 |
0
| if (objSessionState != null)
|
181 |
| { |
182 |
0
| m_objTreeModel = objSessionManager.getModel(objSessionState);
|
183 |
| } |
184 |
| else |
185 |
| { |
186 |
0
| if (LOG.isDebugEnabled())
|
187 |
| { |
188 |
0
| LOG.debug("TreeView.extractTreeModel() from BINDING");
|
189 |
| } |
190 |
| |
191 |
0
| m_objTreeModel = (ITreeModel) getTreeModelBinding().getObject();
|
192 |
| } |
193 |
| |
194 |
| } |
195 |
| |
196 |
0
| private void storeSesion()
|
197 |
| { |
198 |
0
| if (LOG.isDebugEnabled())
|
199 |
| { |
200 |
0
| LOG.debug("TreeView.storeSesion()");
|
201 |
| } |
202 |
| |
203 |
0
| ITreeSessionStateManager objSessionManager = getTreeSessionStateMgr();
|
204 |
0
| Object objSessionState = objSessionManager.getSessionState(getTreeModel());
|
205 |
| |
206 |
0
| store(objSessionState);
|
207 |
| } |
208 |
| |
209 |
0
| private void store(Object objSessionState)
|
210 |
| { |
211 |
0
| ISessionStoreManager objHolder = getSessionStoreManager();
|
212 |
| |
213 |
0
| if (objHolder == null)
|
214 |
| { |
215 |
0
| Tapestry.fireObservedChange(this, "treeSessionState", objSessionState);
|
216 |
| } |
217 |
| else |
218 |
| { |
219 |
| |
220 |
0
| String strPath = getExtendedId();
|
221 |
0
| if (LOG.isDebugEnabled())
|
222 |
0
| LOG.debug("store(): setting state with: " + strPath);
|
223 |
0
| objHolder.setSessionState(this.getPage(), strPath, objSessionState);
|
224 |
| } |
225 |
| } |
226 |
| |
227 |
| |
228 |
| |
229 |
| |
230 |
0
| public void resetState()
|
231 |
| { |
232 |
0
| if (LOG.isDebugEnabled())
|
233 |
| { |
234 |
0
| LOG.debug("TreeView.resetState()");
|
235 |
| } |
236 |
0
| initialize();
|
237 |
0
| store(null);
|
238 |
| } |
239 |
| |
240 |
| |
241 |
| |
242 |
| |
243 |
| |
244 |
| |
245 |
0
| public ISessionStoreManager getSessionStoreManager()
|
246 |
| { |
247 |
0
| if (m_objSessionStoreManager == null && getSessionStoreManagerBinding() != null)
|
248 |
| { |
249 |
0
| m_objSessionStoreManager = (ISessionStoreManager) getSessionStoreManagerBinding()
|
250 |
| .getObject(); |
251 |
| } |
252 |
| |
253 |
0
| return m_objSessionStoreManager;
|
254 |
| } |
255 |
| |
256 |
| |
257 |
| |
258 |
| |
259 |
| |
260 |
| |
261 |
0
| public ITreeSessionStateManager getTreeSessionStateMgr()
|
262 |
| { |
263 |
0
| if (m_objTreeSessionStateManager == null)
|
264 |
| { |
265 |
0
| IBinding objBinding = getSessionStateManagerBinding();
|
266 |
0
| if (objBinding != null)
|
267 |
| { |
268 |
0
| Object objManager = objBinding.getObject();
|
269 |
0
| m_objTreeSessionStateManager = (ITreeSessionStateManager) objManager;
|
270 |
| } |
271 |
| else |
272 |
| { |
273 |
0
| m_objTreeSessionStateManager = new FullTreeSessionStateManager();
|
274 |
| } |
275 |
| } |
276 |
0
| return m_objTreeSessionStateManager;
|
277 |
| } |
278 |
| |
279 |
0
| public ComponentAddress getComponentPath()
|
280 |
| { |
281 |
0
| if (m_objComponentAddress == null)
|
282 |
| { |
283 |
0
| m_objComponentAddress = new ComponentAddress(this);
|
284 |
| } |
285 |
0
| return m_objComponentAddress;
|
286 |
| } |
287 |
| |
288 |
| |
289 |
| |
290 |
| |
291 |
| |
292 |
| |
293 |
0
| public ITreeModel getTreeModel()
|
294 |
| { |
295 |
0
| if (m_objTreeModel == null)
|
296 |
| { |
297 |
0
| extractTreeModel();
|
298 |
| } |
299 |
0
| return m_objTreeModel;
|
300 |
| } |
301 |
| |
302 |
| |
303 |
| |
304 |
| |
305 |
| |
306 |
| |
307 |
| |
308 |
0
| public void setTreeModel(ITreeModel treeModel)
|
309 |
| { |
310 |
0
| m_objTreeModel = treeModel;
|
311 |
| } |
312 |
| |
313 |
| |
314 |
| |
315 |
| |
316 |
| |
317 |
| |
318 |
0
| public Object getTreeSessionState()
|
319 |
| { |
320 |
0
| return m_objTreeSessionState;
|
321 |
| } |
322 |
| |
323 |
| |
324 |
| |
325 |
| |
326 |
| |
327 |
| |
328 |
| |
329 |
0
| public void setTreeSessionState(Object treeSessionState)
|
330 |
| { |
331 |
0
| m_objTreeSessionState = treeSessionState;
|
332 |
| } |
333 |
| |
334 |
0
| public String getSelectedNodeStyleID()
|
335 |
| { |
336 |
0
| return getId() + ":selected";
|
337 |
| } |
338 |
| |
339 |
| |
340 |
| |
341 |
| |
342 |
| |
343 |
0
| protected void renderComponent(IMarkupWriter arg0, IRequestCycle arg1)
|
344 |
| { |
345 |
0
| Object objExistedTreeModelSource = arg1
|
346 |
| .getAttribute(ITreeModelSource.TREE_MODEL_SOURCE_ATTRIBUTE); |
347 |
0
| arg1.setAttribute(ITreeModelSource.TREE_MODEL_SOURCE_ATTRIBUTE, this);
|
348 |
| |
349 |
0
| super.renderComponent(arg0, arg1);
|
350 |
0
| arg1.setAttribute(ITreeModelSource.TREE_MODEL_SOURCE_ATTRIBUTE, objExistedTreeModelSource);
|
351 |
| } |
352 |
| |
353 |
| |
354 |
| |
355 |
| |
356 |
0
| public ITreeStateListener getTreeStateListener()
|
357 |
| { |
358 |
0
| ITreeStateListener objListener = null;
|
359 |
0
| IBinding objBinding = getBinding("treeStateListener");
|
360 |
0
| if (objBinding != null)
|
361 |
| { |
362 |
0
| objListener = (ITreeStateListener) objBinding.getObject();
|
363 |
| } |
364 |
0
| return objListener;
|
365 |
| } |
366 |
| |
367 |
| } |