1 | <%-- $Id: tree.jsp 4847 2009-03-26 08:07:28Z martin $ |
---|
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.Nameable" |
---|
29 | import="net.sf.basedb.core.ItemContext" |
---|
30 | import="net.sf.basedb.core.Permission" |
---|
31 | import="net.sf.basedb.clients.web.Base" |
---|
32 | import="net.sf.basedb.clients.web.util.HTML" |
---|
33 | import="net.sf.basedb.util.Values" |
---|
34 | import="net.sf.basedb.util.overview.GenericOverview" |
---|
35 | import="net.sf.basedb.util.overview.OverviewUtil" |
---|
36 | import="net.sf.basedb.util.overview.Node" |
---|
37 | import="net.sf.basedb.util.overview.ValidationOptions" |
---|
38 | import="java.util.List" |
---|
39 | %> |
---|
40 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
41 | <%! |
---|
42 | String generateSubTree(Node startNode, String ID, boolean showFailures) |
---|
43 | { |
---|
44 | StringBuilder sb = new StringBuilder(); |
---|
45 | List<Node> children = startNode.getChildren(); |
---|
46 | if (children == null) return ""; |
---|
47 | for (Node child : children) |
---|
48 | { |
---|
49 | int errors = child.getNumErrors(); |
---|
50 | int warnings = child.getNumWarnings(); |
---|
51 | int childErrors = child.getChildErrors(); |
---|
52 | int childWarnings = child.getChildWarnings(); |
---|
53 | |
---|
54 | String folderIcon = child.getNodeType() == Node.Type.FOLDER ? "Folder" : "Item"; |
---|
55 | String tooltip = ""; |
---|
56 | if (child.getItemType() == Item.ANNOTATIONTYPE && startNode.getItemType() == Item.PROTOCOL) |
---|
57 | { |
---|
58 | folderIcon = "ProtocolParameter"; |
---|
59 | } |
---|
60 | else if (child.getItemType() == Item.ANNOTATION) |
---|
61 | { |
---|
62 | folderIcon = "Annotation"; |
---|
63 | } |
---|
64 | |
---|
65 | if (showFailures) |
---|
66 | { |
---|
67 | if (errors > 0) |
---|
68 | { |
---|
69 | folderIcon += "Error"; |
---|
70 | } |
---|
71 | else if (warnings > 0) |
---|
72 | { |
---|
73 | folderIcon += "Warning"; |
---|
74 | } |
---|
75 | else if (childErrors > 0) |
---|
76 | { |
---|
77 | folderIcon += "ChildError"; |
---|
78 | } |
---|
79 | else if (childWarnings > 0) |
---|
80 | { |
---|
81 | folderIcon += "ChildWarning"; |
---|
82 | } |
---|
83 | if (warnings > 0 && errors > 0) |
---|
84 | { |
---|
85 | tooltip += errors + " error(s); " + warnings + " warning(s) on this item"; |
---|
86 | } |
---|
87 | else if (errors > 0) |
---|
88 | { |
---|
89 | tooltip += errors + " error(s) on this item"; |
---|
90 | } |
---|
91 | else if (warnings > 0) |
---|
92 | { |
---|
93 | tooltip += warnings + " warning(s) on this item"; |
---|
94 | } |
---|
95 | if (childErrors > 0 && childWarnings > 0) |
---|
96 | { |
---|
97 | if (tooltip.length() > 0) tooltip += "; "; |
---|
98 | tooltip += childErrors + " error(s); " + childWarnings + " warning(s) on child items"; |
---|
99 | } |
---|
100 | else if (childErrors > 0) |
---|
101 | { |
---|
102 | if (tooltip.length() > 0) tooltip += "; "; |
---|
103 | tooltip += childErrors + " error(s) on child items"; |
---|
104 | } |
---|
105 | else if (childWarnings > 0) |
---|
106 | { |
---|
107 | if (tooltip.length() > 0) tooltip += "; "; |
---|
108 | tooltip += childWarnings + " warning(s) on child items"; |
---|
109 | } |
---|
110 | } |
---|
111 | int numChildren = child.getChildren() == null ? |
---|
112 | 0 : child.getChildren().size(); |
---|
113 | if (!child.isChildrenLoaded()) |
---|
114 | { |
---|
115 | sb.append("var node").append(child.hashCode()).append(" = JoustMenu.addLazyChildItem(").append("node"+startNode.hashCode()); |
---|
116 | sb.append(",'").append(folderIcon).append("'"); |
---|
117 | sb.append(",'").append(HTML.javaScriptEncode(child.getTitle())); |
---|
118 | sb.append(child.getNodeType() == Node.Type.FOLDER ? " (" + numChildren + ")" : "").append("',"); |
---|
119 | sb.append("'showInfo(\"").append(child.getId()).append("\")','").append(HTML.javaScriptEncode(tooltip)).append("', '").append(child.getId()).append("',"); |
---|
120 | sb.append("'lazyInitSubNode(\"").append(child.getId()).append("\")')\n"); |
---|
121 | } |
---|
122 | else |
---|
123 | { |
---|
124 | sb.append("var node").append(child.hashCode()).append(" = JoustMenu.addChildItem(").append("node"+startNode.hashCode()); |
---|
125 | sb.append(",'").append(folderIcon).append("'"); |
---|
126 | sb.append(",'").append(HTML.javaScriptEncode(child.getTitle())); |
---|
127 | sb.append(child.getNodeType() == Node.Type.FOLDER ? " (" + numChildren + ")" : "").append("',"); |
---|
128 | sb.append("'showInfo(\"").append(child.getId()).append("\")','").append(HTML.javaScriptEncode(tooltip)).append("', '").append(child.getId()).append("')\n"); |
---|
129 | } |
---|
130 | sb.append(generateSubTree(child, ID, showFailures)); |
---|
131 | } |
---|
132 | return sb.toString(); |
---|
133 | } |
---|
134 | %> |
---|
135 | <% |
---|
136 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
137 | final String ID = sc.getId(); |
---|
138 | final float scale = Base.getScale(sc); |
---|
139 | final DbControl dc = null; |
---|
140 | try |
---|
141 | { |
---|
142 | GenericOverview overview = OverviewUtil.getCurrentOverview(sc); |
---|
143 | Boolean showFailures = Values.getBoolean(request.getParameter("show_failures"), false); |
---|
144 | Nameable rootItem = (Nameable)overview.getRootItem(); |
---|
145 | Node rootNode = overview.getRootNode(); |
---|
146 | String rootIcon = "Home"; |
---|
147 | if (showFailures) |
---|
148 | { |
---|
149 | if (rootNode.getNumErrors() > 0 || rootNode.getChildErrors() > 0) |
---|
150 | { |
---|
151 | rootIcon = "Error"; |
---|
152 | } |
---|
153 | else if (rootNode.getNumWarnings() > 0 || rootNode.getChildWarnings() > 0) |
---|
154 | { |
---|
155 | rootIcon = "Warning"; |
---|
156 | } |
---|
157 | } |
---|
158 | %> |
---|
159 | <base:page title="" type="popup"> |
---|
160 | <base:head scripts="newjoust.js,ajax.js" styles="newjoust.css"> |
---|
161 | <script language="JavaScript"> |
---|
162 | var isInitialised = false; |
---|
163 | function initialise() |
---|
164 | { |
---|
165 | if (parent && parent.parent && parent.parent.adjustIFrameSize) parent.parent.adjustIFrameSize(); |
---|
166 | IconStore.init(); |
---|
167 | var path = getRoot()+'images/joust/'; |
---|
168 | |
---|
169 | IconStore.addIcon('Warning', getRoot() + 'images/warning.gif', 16, 16); |
---|
170 | IconStore.addIcon('Error', getRoot() + 'images/error.gif', 16, 16); |
---|
171 | IconStore.addIcon('FolderWarning', path + 'folderwarning.gif', 18, 16); |
---|
172 | IconStore.addIcon('FolderWarningSelected', path + 'folderwarningselected.gif', 18, 16); |
---|
173 | IconStore.addIcon('FolderChildWarning', path + 'folderchildwarning.gif', 18, 16); |
---|
174 | IconStore.addIcon('FolderChildWarningSelected', path + 'folderchildwarningselected.gif', 18, 16); |
---|
175 | IconStore.addIcon('FolderError', path + 'foldererror.gif', 18, 16); |
---|
176 | IconStore.addIcon('FolderErrorSelected', path + 'foldererrorselected.gif', 18, 16); |
---|
177 | IconStore.addIcon('FolderChildError', path + 'folderchilderror.gif', 18, 16); |
---|
178 | IconStore.addIcon('FolderChildErrorSelected', path + 'folderchilderrorselected.gif', 18, 16); |
---|
179 | IconStore.addIcon('Item', path + 'item.gif', 18, 16); |
---|
180 | IconStore.addIcon('ItemSelected', path + 'itemselected.gif', 18, 16); |
---|
181 | IconStore.addIcon('ItemWarning', path + 'itemwarning.gif', 18, 16); |
---|
182 | IconStore.addIcon('ItemWarningSelected', path + 'itemwarningselected.gif', 18, 16); |
---|
183 | IconStore.addIcon('ItemChildWarning', path + 'itemchildwarning.gif', 18, 16); |
---|
184 | IconStore.addIcon('ItemChildWarningSelected', path + 'itemchildwarningselected.gif', 18, 16); |
---|
185 | IconStore.addIcon('ItemError', path + 'itemerror.gif', 18, 16); |
---|
186 | IconStore.addIcon('ItemErrorSelected', path + 'itemerrorselected.gif', 18, 16); |
---|
187 | IconStore.addIcon('ItemChildError', path + 'itemchilderror.gif', 18, 16); |
---|
188 | IconStore.addIcon('ItemChildErrorSelected', path + 'itemchilderrorselected.gif', 18, 16); |
---|
189 | IconStore.addIcon('ProtocolParameter', path + 'parameter.gif', 18, 16); |
---|
190 | IconStore.addIcon('ProtocolParameterSelected', path + 'parameterselected.gif', 18, 16); |
---|
191 | IconStore.addIcon('ProtocolParameterWarning', path + 'parameterwarning.gif', 18, 16); |
---|
192 | IconStore.addIcon('ProtocolParameterWarningSelected', path + 'parametererrorselected.gif', 18, 16); |
---|
193 | IconStore.addIcon('ProtocolParameterError', path + 'parameterwarning.gif', 18, 16); |
---|
194 | IconStore.addIcon('ProtocolParameterErrorSelected', path + 'parametererrorselected.gif', 18, 16); |
---|
195 | IconStore.addIcon('ProtocolParameterChildWarning', path + 'parameterchildwarning.gif', 18, 16); |
---|
196 | IconStore.addIcon('ProtocolParameterChildWarningSelected', path + 'parameterchilderrorselected.gif', 18, 16); |
---|
197 | IconStore.addIcon('ProtocolParameterChildError', path + 'parameterchildwarning.gif', 18, 16); |
---|
198 | IconStore.addIcon('ProtocolParameterChildErrorSelected', path + 'parameterchilderrorselected.gif', 18, 16); |
---|
199 | IconStore.addIcon('Annotation', path + 'annotation.gif', 18, 16); |
---|
200 | IconStore.addIcon('AnnotationSelected', path + 'annotationselected.gif', 18, 16); |
---|
201 | IconStore.addIcon('AnnotationWarning', path + 'annotationwarning.gif', 18, 16); |
---|
202 | IconStore.addIcon('AnnotationWarningSelected', path + 'annotationwarningselected.gif', 18, 16); |
---|
203 | IconStore.addIcon('AnnotationError', path + 'annotationerror.gif', 18, 16); |
---|
204 | IconStore.addIcon('AnnotationErrorSelected', path + 'annotationerrorselected.gif', 18, 16); |
---|
205 | IconStore.addIcon('AnnotationChildWarning', path + 'annotationchildwarning.gif', 18, 16); |
---|
206 | IconStore.addIcon('AnnotationChildWarningSelected', path + 'annotationchildwarningselected.gif', 18, 16); |
---|
207 | IconStore.addIcon('AnnotationChildError', path + 'annotationchilderror.gif', 18, 16); |
---|
208 | IconStore.addIcon('AnnotatioChildnErrorSelected', path + 'annotationchilderrorselected.gif', 18, 16); |
---|
209 | var node<%=rootNode.hashCode()%> = JoustMenu.addMenuItem(-1, '<%=rootIcon%>', '<%=HTML.javaScriptEncode(rootItem.getName())%>', 'showInfo("<%=rootNode.getId()%>")', '', '<%=rootNode.getId()%>'); |
---|
210 | <%=generateSubTree(rootNode, ID, showFailures)%> |
---|
211 | JoustMenu.menuItems[node<%=rootNode.hashCode()%>].isOpen = true; |
---|
212 | JoustMenu.draw('joust'); |
---|
213 | isInitialised = true; |
---|
214 | } |
---|
215 | |
---|
216 | function openAll() |
---|
217 | { |
---|
218 | JoustMenu.openAll(); |
---|
219 | } |
---|
220 | |
---|
221 | function closeAll() |
---|
222 | { |
---|
223 | JoustMenu.closeAll(); |
---|
224 | } |
---|
225 | |
---|
226 | function showInfo(nodeId) |
---|
227 | { |
---|
228 | parent.frames['info'].location.href = 'info.jsp?ID=<%=ID%>&nodeId='+nodeId+'&show_failures=<%=showFailures%>'; |
---|
229 | } |
---|
230 | |
---|
231 | function selectNode(nodeId) |
---|
232 | { |
---|
233 | var node = JoustMenu.menuItems[nodeId]; |
---|
234 | JoustMenu.select(node.index); |
---|
235 | } |
---|
236 | |
---|
237 | var loadedTime = new Date().getTime(); |
---|
238 | function refreshIfOutdated() |
---|
239 | { |
---|
240 | var currentTime = new Date().getTime(); |
---|
241 | if (currentTime - loadedTime > 2000) |
---|
242 | { |
---|
243 | location.reload(); |
---|
244 | } |
---|
245 | } |
---|
246 | |
---|
247 | function lazyInitSubNode(nodeId) |
---|
248 | { |
---|
249 | var parentMenu = JoustMenu.menuItems[nodeId]; |
---|
250 | JoustMenu.changeCursorOnMenuItem(parentMenu.index, 'progress'); |
---|
251 | var request = Ajax.getXmlHttpRequest(); |
---|
252 | var url = 'ajax.jsp?ID=<%=ID%>&cmd=GetSubNodes&node_id=' + nodeId; |
---|
253 | request.open("GET", url, false); |
---|
254 | request.send(null); |
---|
255 | var response = request.responseText.split('\n'); |
---|
256 | |
---|
257 | var kv = new Array(); |
---|
258 | var numAdded = 0; |
---|
259 | |
---|
260 | for (var i=0; i<response.length; i++) |
---|
261 | { |
---|
262 | var txt = Main.trimString(response[i]); |
---|
263 | if (txt == 'end') |
---|
264 | { |
---|
265 | var id = kv['id']; |
---|
266 | var folderIcon = kv['folderIcon']; |
---|
267 | numAdded++; |
---|
268 | var node = JoustMenu.addLazyChildItem( |
---|
269 | parentMenu.index, folderIcon, Main.trimString(kv['title']), 'showInfo(\''+id+'\')', |
---|
270 | '' , id, 'lazyInitSubNode(\''+id+'\')'); |
---|
271 | } |
---|
272 | else |
---|
273 | { |
---|
274 | var tmp = txt.split('\t', 2); |
---|
275 | kv[tmp[0]] = tmp[1]; |
---|
276 | } |
---|
277 | JoustMenu.updateIconsAndText(parentMenu.index, true); |
---|
278 | } |
---|
279 | JoustMenu.changeCursorOnMenuItem(parentMenu.index, 'pointer'); |
---|
280 | return numAdded > 0; |
---|
281 | } |
---|
282 | |
---|
283 | </script> |
---|
284 | </base:head> |
---|
285 | <base:body onload="initialise()"> |
---|
286 | <div id="main" class="joust" style="width:100%;"> |
---|
287 | <div id="joust" style="overflow: auto;"> |
---|
288 | </div> |
---|
289 | </div> |
---|
290 | </base:body> |
---|
291 | </base:page> |
---|
292 | <% |
---|
293 | } |
---|
294 | finally |
---|
295 | { |
---|
296 | if (dc != null) dc.close(); |
---|
297 | } |
---|
298 | %> |
---|