1 | <%-- $Id: tree.jsp 5145 2009-10-20 06:50:49Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2009 Nicklas Nordborg |
---|
4 | |
---|
5 | This file is part of BASE - BioArray Software Environment. |
---|
6 | Available at http://base.thep.lu.se/ |
---|
7 | |
---|
8 | BASE is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU General Public License |
---|
10 | as published by the Free Software Foundation; either version 3 |
---|
11 | of the License, or (at your option) any later version. |
---|
12 | |
---|
13 | BASE is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | GNU General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with BASE. If not, see <http://www.gnu.org/licenses/>. |
---|
20 | ------------------------------------------------------------------ |
---|
21 | --%> |
---|
22 | <%@ page session="false" |
---|
23 | import="net.sf.basedb.core.SessionControl" |
---|
24 | import="net.sf.basedb.core.DbControl" |
---|
25 | import="net.sf.basedb.core.Project" |
---|
26 | import="net.sf.basedb.core.Item" |
---|
27 | import="net.sf.basedb.core.BasicItem" |
---|
28 | import="net.sf.basedb.core.Annotation" |
---|
29 | import="net.sf.basedb.core.AnnotationType" |
---|
30 | import="net.sf.basedb.core.Nameable" |
---|
31 | import="net.sf.basedb.core.ItemContext" |
---|
32 | import="net.sf.basedb.core.Permission" |
---|
33 | import="net.sf.basedb.clients.web.Base" |
---|
34 | import="net.sf.basedb.clients.web.util.HTML" |
---|
35 | import="net.sf.basedb.util.Values" |
---|
36 | import="net.sf.basedb.util.overview.GenericOverview" |
---|
37 | import="net.sf.basedb.util.overview.OverviewUtil" |
---|
38 | import="net.sf.basedb.util.overview.Node" |
---|
39 | import="net.sf.basedb.util.overview.ValidationOptions" |
---|
40 | import="java.util.List" |
---|
41 | %> |
---|
42 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
43 | <%! |
---|
44 | String generateSubTree(DbControl dc, Node startNode, String ID, boolean showFailures) |
---|
45 | { |
---|
46 | StringBuilder sb = new StringBuilder(); |
---|
47 | List<Node> children = startNode.getChildren(); |
---|
48 | if (children == null) return ""; |
---|
49 | for (Node child : children) |
---|
50 | { |
---|
51 | int errors = child.getNumErrors(); |
---|
52 | int warnings = child.getNumWarnings(); |
---|
53 | int childErrors = child.getChildErrors(); |
---|
54 | int childWarnings = child.getChildWarnings(); |
---|
55 | |
---|
56 | String folderIcon = child.getNodeType() == Node.Type.FOLDER ? "Folder" : "Item"; |
---|
57 | String tooltip = ""; |
---|
58 | if (child.getItemType() == Item.ANNOTATIONTYPE) |
---|
59 | { |
---|
60 | if (startNode.getItemType() == Item.PROTOCOL) |
---|
61 | { |
---|
62 | folderIcon = "ProtocolParameter"; |
---|
63 | } |
---|
64 | else |
---|
65 | { |
---|
66 | try |
---|
67 | { |
---|
68 | AnnotationType at = (AnnotationType)child.getItem(dc); |
---|
69 | if (at.isProtocolParameter()) folderIcon = "ProtocolParameter"; |
---|
70 | } |
---|
71 | catch (Throwable t) |
---|
72 | {} |
---|
73 | } |
---|
74 | } |
---|
75 | else if (child.getItemType() == Item.ANNOTATION) |
---|
76 | { |
---|
77 | folderIcon = "Annotation"; |
---|
78 | try |
---|
79 | { |
---|
80 | AnnotationType at = ((Annotation)child.getItem(dc)).getAnnotationType(); |
---|
81 | if (at.isProtocolParameter()) folderIcon = "ProtocolParameter"; |
---|
82 | } |
---|
83 | catch (Throwable t) |
---|
84 | {} |
---|
85 | } |
---|
86 | |
---|
87 | if (showFailures) |
---|
88 | { |
---|
89 | if (errors > 0) |
---|
90 | { |
---|
91 | folderIcon += "Error"; |
---|
92 | } |
---|
93 | else if (warnings > 0) |
---|
94 | { |
---|
95 | folderIcon += "Warning"; |
---|
96 | } |
---|
97 | else if (childErrors > 0) |
---|
98 | { |
---|
99 | folderIcon += "ChildError"; |
---|
100 | } |
---|
101 | else if (childWarnings > 0) |
---|
102 | { |
---|
103 | folderIcon += "ChildWarning"; |
---|
104 | } |
---|
105 | if (warnings > 0 && errors > 0) |
---|
106 | { |
---|
107 | tooltip += errors + " error(s); " + warnings + " warning(s) on this item"; |
---|
108 | } |
---|
109 | else if (errors > 0) |
---|
110 | { |
---|
111 | tooltip += errors + " error(s) on this item"; |
---|
112 | } |
---|
113 | else if (warnings > 0) |
---|
114 | { |
---|
115 | tooltip += warnings + " warning(s) on this item"; |
---|
116 | } |
---|
117 | if (childErrors > 0 && childWarnings > 0) |
---|
118 | { |
---|
119 | if (tooltip.length() > 0) tooltip += "; "; |
---|
120 | tooltip += childErrors + " error(s); " + childWarnings + " warning(s) on child items"; |
---|
121 | } |
---|
122 | else if (childErrors > 0) |
---|
123 | { |
---|
124 | if (tooltip.length() > 0) tooltip += "; "; |
---|
125 | tooltip += childErrors + " error(s) on child items"; |
---|
126 | } |
---|
127 | else if (childWarnings > 0) |
---|
128 | { |
---|
129 | if (tooltip.length() > 0) tooltip += "; "; |
---|
130 | tooltip += childWarnings + " warning(s) on child items"; |
---|
131 | } |
---|
132 | } |
---|
133 | int numChildren = child.getChildren() == null ? |
---|
134 | 0 : child.getChildren().size(); |
---|
135 | if (!child.isChildrenLoaded()) |
---|
136 | { |
---|
137 | sb.append("var node").append(child.hashCode()).append(" = JoustMenu.addLazyChildItem(").append("node"+startNode.hashCode()); |
---|
138 | sb.append(",'").append(folderIcon).append("'"); |
---|
139 | sb.append(",'").append(HTML.javaScriptEncode(child.getTitle())); |
---|
140 | sb.append(child.getNodeType() == Node.Type.FOLDER ? " (" + numChildren + ")" : "").append("',"); |
---|
141 | sb.append("'showInfo(\"").append(child.getId()).append("\")','").append(HTML.javaScriptEncode(tooltip)).append("', '").append(child.getId()).append("',"); |
---|
142 | sb.append("'lazyInitSubNode(\"").append(child.getId()).append("\")')\n"); |
---|
143 | } |
---|
144 | else |
---|
145 | { |
---|
146 | sb.append("var node").append(child.hashCode()).append(" = JoustMenu.addChildItem(").append("node"+startNode.hashCode()); |
---|
147 | sb.append(",'").append(folderIcon).append("'"); |
---|
148 | sb.append(",'").append(HTML.javaScriptEncode(child.getTitle())); |
---|
149 | sb.append(child.getNodeType() == Node.Type.FOLDER ? " (" + numChildren + ")" : "").append("',"); |
---|
150 | sb.append("'showInfo(\"").append(child.getId()).append("\")','").append(HTML.javaScriptEncode(tooltip)).append("', '").append(child.getId()).append("')\n"); |
---|
151 | } |
---|
152 | sb.append(generateSubTree(dc, child, ID, showFailures)); |
---|
153 | } |
---|
154 | return sb.toString(); |
---|
155 | } |
---|
156 | %> |
---|
157 | <% |
---|
158 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
159 | final String ID = sc.getId(); |
---|
160 | final float scale = Base.getScale(sc); |
---|
161 | final DbControl dc = sc.newDbControl(); |
---|
162 | try |
---|
163 | { |
---|
164 | GenericOverview overview = OverviewUtil.getCurrentOverview(sc); |
---|
165 | Boolean showFailures = Values.getBoolean(request.getParameter("show_failures"), false); |
---|
166 | Nameable rootItem = (Nameable)overview.getRootItem(); |
---|
167 | Node rootNode = overview.getRootNode(); |
---|
168 | String rootIcon = "Home"; |
---|
169 | if (showFailures) |
---|
170 | { |
---|
171 | if (rootNode.getNumErrors() > 0 || rootNode.getChildErrors() > 0) |
---|
172 | { |
---|
173 | rootIcon = "Error"; |
---|
174 | } |
---|
175 | else if (rootNode.getNumWarnings() > 0 || rootNode.getChildWarnings() > 0) |
---|
176 | { |
---|
177 | rootIcon = "Warning"; |
---|
178 | } |
---|
179 | } |
---|
180 | %> |
---|
181 | <base:page title="" type="popup"> |
---|
182 | <base:head scripts="newjoust.js,ajax.js" styles="newjoust.css"> |
---|
183 | <script language="JavaScript"> |
---|
184 | var isInitialised = false; |
---|
185 | function initialise() |
---|
186 | { |
---|
187 | if (parent && parent.parent && parent.parent.adjustIFrameSize) parent.parent.adjustIFrameSize(); |
---|
188 | IconStore.init(); |
---|
189 | var path = getRoot()+'images/joust/'; |
---|
190 | |
---|
191 | IconStore.addIcon('Warning', getRoot() + 'images/warning.gif', 16, 16); |
---|
192 | IconStore.addIcon('Error', getRoot() + 'images/error.gif', 16, 16); |
---|
193 | IconStore.addIcon('FolderWarning', path + 'folderwarning.gif', 18, 16); |
---|
194 | IconStore.addIcon('FolderWarningSelected', path + 'folderwarningselected.gif', 18, 16); |
---|
195 | IconStore.addIcon('FolderChildWarning', path + 'folderchildwarning.gif', 18, 16); |
---|
196 | IconStore.addIcon('FolderChildWarningSelected', path + 'folderchildwarningselected.gif', 18, 16); |
---|
197 | IconStore.addIcon('FolderError', path + 'foldererror.gif', 18, 16); |
---|
198 | IconStore.addIcon('FolderErrorSelected', path + 'foldererrorselected.gif', 18, 16); |
---|
199 | IconStore.addIcon('FolderChildError', path + 'folderchilderror.gif', 18, 16); |
---|
200 | IconStore.addIcon('FolderChildErrorSelected', path + 'folderchilderrorselected.gif', 18, 16); |
---|
201 | IconStore.addIcon('Item', path + 'item.gif', 18, 16); |
---|
202 | IconStore.addIcon('ItemSelected', path + 'itemselected.gif', 18, 16); |
---|
203 | IconStore.addIcon('ItemWarning', path + 'itemwarning.gif', 18, 16); |
---|
204 | IconStore.addIcon('ItemWarningSelected', path + 'itemwarningselected.gif', 18, 16); |
---|
205 | IconStore.addIcon('ItemChildWarning', path + 'itemchildwarning.gif', 18, 16); |
---|
206 | IconStore.addIcon('ItemChildWarningSelected', path + 'itemchildwarningselected.gif', 18, 16); |
---|
207 | IconStore.addIcon('ItemError', path + 'itemerror.gif', 18, 16); |
---|
208 | IconStore.addIcon('ItemErrorSelected', path + 'itemerrorselected.gif', 18, 16); |
---|
209 | IconStore.addIcon('ItemChildError', path + 'itemchilderror.gif', 18, 16); |
---|
210 | IconStore.addIcon('ItemChildErrorSelected', path + 'itemchilderrorselected.gif', 18, 16); |
---|
211 | IconStore.addIcon('ProtocolParameter', path + 'parameter.gif', 18, 16); |
---|
212 | IconStore.addIcon('ProtocolParameterSelected', path + 'parameterselected.gif', 18, 16); |
---|
213 | IconStore.addIcon('ProtocolParameterWarning', path + 'parameterwarning.gif', 18, 16); |
---|
214 | IconStore.addIcon('ProtocolParameterWarningSelected', path + 'parametererrorselected.gif', 18, 16); |
---|
215 | IconStore.addIcon('ProtocolParameterError', path + 'parameterwarning.gif', 18, 16); |
---|
216 | IconStore.addIcon('ProtocolParameterErrorSelected', path + 'parametererrorselected.gif', 18, 16); |
---|
217 | IconStore.addIcon('ProtocolParameterChildWarning', path + 'parameterchildwarning.gif', 18, 16); |
---|
218 | IconStore.addIcon('ProtocolParameterChildWarningSelected', path + 'parameterchilderrorselected.gif', 18, 16); |
---|
219 | IconStore.addIcon('ProtocolParameterChildError', path + 'parameterchildwarning.gif', 18, 16); |
---|
220 | IconStore.addIcon('ProtocolParameterChildErrorSelected', path + 'parameterchilderrorselected.gif', 18, 16); |
---|
221 | IconStore.addIcon('Annotation', path + 'annotation.gif', 18, 16); |
---|
222 | IconStore.addIcon('AnnotationSelected', path + 'annotationselected.gif', 18, 16); |
---|
223 | IconStore.addIcon('AnnotationWarning', path + 'annotationwarning.gif', 18, 16); |
---|
224 | IconStore.addIcon('AnnotationWarningSelected', path + 'annotationwarningselected.gif', 18, 16); |
---|
225 | IconStore.addIcon('AnnotationError', path + 'annotationerror.gif', 18, 16); |
---|
226 | IconStore.addIcon('AnnotationErrorSelected', path + 'annotationerrorselected.gif', 18, 16); |
---|
227 | IconStore.addIcon('AnnotationChildWarning', path + 'annotationchildwarning.gif', 18, 16); |
---|
228 | IconStore.addIcon('AnnotationChildWarningSelected', path + 'annotationchildwarningselected.gif', 18, 16); |
---|
229 | IconStore.addIcon('AnnotationChildError', path + 'annotationchilderror.gif', 18, 16); |
---|
230 | IconStore.addIcon('AnnotatioChildnErrorSelected', path + 'annotationchilderrorselected.gif', 18, 16); |
---|
231 | var node<%=rootNode.hashCode()%> = JoustMenu.addMenuItem(-1, '<%=rootIcon%>', '<%=HTML.javaScriptEncode(rootItem.getName())%>', 'showInfo("<%=rootNode.getId()%>")', '', '<%=rootNode.getId()%>'); |
---|
232 | <%=generateSubTree(dc, rootNode, ID, showFailures)%> |
---|
233 | JoustMenu.menuItems[node<%=rootNode.hashCode()%>].isOpen = true; |
---|
234 | JoustMenu.draw('joust'); |
---|
235 | isInitialised = true; |
---|
236 | } |
---|
237 | |
---|
238 | function openAll() |
---|
239 | { |
---|
240 | JoustMenu.openAll(); |
---|
241 | } |
---|
242 | |
---|
243 | function closeAll() |
---|
244 | { |
---|
245 | JoustMenu.closeAll(); |
---|
246 | } |
---|
247 | |
---|
248 | function showInfo(nodeId) |
---|
249 | { |
---|
250 | parent.frames['info'].location.href = 'info.jsp?ID=<%=ID%>&nodeId='+nodeId+'&show_failures=<%=showFailures%>'; |
---|
251 | } |
---|
252 | |
---|
253 | function selectNode(nodeId) |
---|
254 | { |
---|
255 | var node = JoustMenu.menuItems[nodeId]; |
---|
256 | JoustMenu.select(node.index); |
---|
257 | } |
---|
258 | |
---|
259 | var loadedTime = new Date().getTime(); |
---|
260 | function refreshIfOutdated() |
---|
261 | { |
---|
262 | var currentTime = new Date().getTime(); |
---|
263 | if (currentTime - loadedTime > 2000) |
---|
264 | { |
---|
265 | location.reload(); |
---|
266 | } |
---|
267 | } |
---|
268 | |
---|
269 | function lazyInitSubNode(nodeId) |
---|
270 | { |
---|
271 | var parentMenu = JoustMenu.menuItems[nodeId]; |
---|
272 | JoustMenu.changeCursorOnMenuItem(parentMenu.index, 'progress'); |
---|
273 | var request = Ajax.getXmlHttpRequest(); |
---|
274 | var url = 'ajax.jsp?ID=<%=ID%>&cmd=GetSubNodes&node_id=' + nodeId; |
---|
275 | request.open("GET", url, false); |
---|
276 | request.send(null); |
---|
277 | var response = request.responseText.split('\n'); |
---|
278 | |
---|
279 | var kv = new Array(); |
---|
280 | var numAdded = 0; |
---|
281 | |
---|
282 | for (var i=0; i<response.length; i++) |
---|
283 | { |
---|
284 | var txt = Main.trimString(response[i]); |
---|
285 | if (txt == 'end') |
---|
286 | { |
---|
287 | var id = kv['id']; |
---|
288 | var folderIcon = kv['folderIcon']; |
---|
289 | var numChildren = kv['numChildren']; |
---|
290 | numAdded++; |
---|
291 | var node = JoustMenu.addLazyChildItem( |
---|
292 | parentMenu.index, folderIcon, Main.trimString(kv['title']), 'showInfo(\''+id+'\')', |
---|
293 | '' , id, numChildren == '0' ? '' : 'lazyInitSubNode(\''+id+'\')'); |
---|
294 | } |
---|
295 | else |
---|
296 | { |
---|
297 | var tmp = txt.split('\t', 2); |
---|
298 | kv[tmp[0]] = tmp[1]; |
---|
299 | } |
---|
300 | JoustMenu.updateIconsAndText(parentMenu.index, true); |
---|
301 | } |
---|
302 | JoustMenu.changeCursorOnMenuItem(parentMenu.index, 'pointer'); |
---|
303 | return numAdded > 0; |
---|
304 | } |
---|
305 | |
---|
306 | </script> |
---|
307 | </base:head> |
---|
308 | <base:body onload="initialise()"> |
---|
309 | <div id="main" class="joust" style="width:100%;"> |
---|
310 | <div id="joust" style="overflow: auto;"> |
---|
311 | </div> |
---|
312 | </div> |
---|
313 | </base:body> |
---|
314 | </base:page> |
---|
315 | <% |
---|
316 | } |
---|
317 | finally |
---|
318 | { |
---|
319 | if (dc != null) dc.close(); |
---|
320 | } |
---|
321 | %> |
---|