|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
TreeView.java | 0% | 0% | 0% | 0% |
|
1 |
// Copyright 2004, 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
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 |
* @see org.apache.tapestry.AbstractComponent#renderComponent(IMarkupWriter, IRequestCycle)
|
|
76 |
*/
|
|
77 |
|
|
78 |
/**
|
|
79 |
* @see org.apache.tapestry.event.PageDetachListener#pageDetached(PageEvent)
|
|
80 |
*/
|
|
81 | 0 |
public void pageDetached(PageEvent arg0) |
82 |
{ |
|
83 | 0 |
initialize(); |
84 |
} |
|
85 |
|
|
86 |
/**
|
|
87 |
* @see org.apache.tapestry.event.PageRenderListener#pageBeginRender(PageEvent)
|
|
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 |
* Returns the treeModelBinding.
|
|
100 |
*
|
|
101 |
* @return IBinding
|
|
102 |
*/
|
|
103 | 0 |
public IBinding getTreeModelBinding()
|
104 |
{ |
|
105 | 0 |
return m_objTreeModelBinding;
|
106 |
} |
|
107 |
|
|
108 |
/**
|
|
109 |
* Sets the treeModelBinding.
|
|
110 |
*
|
|
111 |
* @param treeModelBinding
|
|
112 |
* The treeModelBinding to set
|
|
113 |
*/
|
|
114 | 0 |
public void setTreeModelBinding(IBinding treeModelBinding) |
115 |
{ |
|
116 | 0 |
m_objTreeModelBinding = treeModelBinding; |
117 |
} |
|
118 |
|
|
119 |
/**
|
|
120 |
* Returns the SessionStoreManagerBinding.
|
|
121 |
*
|
|
122 |
* @return IBinding
|
|
123 |
*/
|
|
124 | 0 |
public IBinding getSessionStoreManagerBinding()
|
125 |
{ |
|
126 | 0 |
return m_objSessionStoreManagerBinding;
|
127 |
} |
|
128 |
|
|
129 |
/**
|
|
130 |
* Returns the sessionStateManagerBinding.
|
|
131 |
*
|
|
132 |
* @return IBinding
|
|
133 |
*/
|
|
134 | 0 |
public IBinding getSessionStateManagerBinding()
|
135 |
{ |
|
136 | 0 |
return m_objSessionStateManagerBinding;
|
137 |
} |
|
138 |
|
|
139 |
/**
|
|
140 |
* Sets the SessionStoreManagerBinding.
|
|
141 |
*
|
|
142 |
* @param sessionStoreManagerBinding
|
|
143 |
* The SessionStoreManagerBinding to set
|
|
144 |
*/
|
|
145 | 0 |
public void setSessionStoreManagerBinding(IBinding sessionStoreManagerBinding) |
146 |
{ |
|
147 | 0 |
m_objSessionStoreManagerBinding = sessionStoreManagerBinding; |
148 |
} |
|
149 |
|
|
150 |
/**
|
|
151 |
* Sets the sessionStateManagerBinding.
|
|
152 |
*
|
|
153 |
* @param sessionStateManagerBinding
|
|
154 |
* The sessionStateManagerBinding to set
|
|
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 |
//String strPath = "treeSessionState";
|
|
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 |
* @see ITreeComponent#resetState()
|
|
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 |
* Returns the SessionStoreManager.
|
|
242 |
*
|
|
243 |
* @return ISessionStoreManager
|
|
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 |
* Returns the wizardSessionStateMgr.
|
|
258 |
*
|
|
259 |
* @return IWizardSessionStateManager
|
|
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 |
* Returns the treeModel.
|
|
290 |
*
|
|
291 |
* @return ITreeModel
|
|
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 |
* Sets the treeModel.
|
|
304 |
*
|
|
305 |
* @param treeModel
|
|
306 |
* The treeModel to set
|
|
307 |
*/
|
|
308 | 0 |
public void setTreeModel(ITreeModel treeModel) |
309 |
{ |
|
310 | 0 |
m_objTreeModel = treeModel; |
311 |
} |
|
312 |
|
|
313 |
/**
|
|
314 |
* Returns the treeSessionState.
|
|
315 |
*
|
|
316 |
* @return Object
|
|
317 |
*/
|
|
318 | 0 |
public Object getTreeSessionState()
|
319 |
{ |
|
320 | 0 |
return m_objTreeSessionState;
|
321 |
} |
|
322 |
|
|
323 |
/**
|
|
324 |
* Sets the treeSessionState.
|
|
325 |
*
|
|
326 |
* @param treeSessionState
|
|
327 |
* The treeSessionState to set
|
|
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 |
* @see org.apache.tapestry.BaseComponent#renderComponent(org.apache.tapestry.IMarkupWriter,
|
|
341 |
* org.apache.tapestry.IRequestCycle)
|
|
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 |
* @see org.apache.tapestry.contrib.tree.model.ITreeModelSource#getTreeStateListener()
|
|
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 |
} |
|