source: trunk/www/common/overview/tree.jsp @ 4840

Last change on this file since 4840 was 4840, checked in by Martin Svensson, 14 years ago

References #1240. The functionallity in the webclient is done. The documentation is not completely updated yet.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 10.7 KB
Line 
1<%-- $Id: tree.jsp 4840 2009-03-24 14:55:03Z 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<%!
42String 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    sb.append("var node").append(child.hashCode()).append(" = JoustMenu.addLazyChildItem(").append("node"+startNode.hashCode());
114    sb.append(",'").append(folderIcon).append("'");
115    sb.append(",'").append(HTML.javaScriptEncode(child.getTitle()));
116    sb.append(child.getNodeType() == Node.Type.FOLDER ? " (" + numChildren + ")" : "").append("',");
117    sb.append("'showInfo(\"").append(child.getId()).append("\")','").append(HTML.javaScriptEncode(tooltip)).append("', '").append(child.getId()).append("',");
118    sb.append("'lazyInitSubNode(\"").append(child.getId()).append("\")')\n");
119    sb.append(generateSubTree(child, ID, showFailures));
120  }
121  return sb.toString();
122}
123%>
124<%
125final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
126final String ID = sc.getId();
127final float scale = Base.getScale(sc);
128final DbControl dc = null;
129try
130{
131  GenericOverview overview = OverviewUtil.getCurrentOverview(sc);
132  Boolean showFailures = Values.getBoolean(request.getParameter("show_failures"), false);
133  Nameable rootItem = (Nameable)overview.getRootItem();
134  Node rootNode = overview.getRootNode();
135  String rootIcon = "Home";
136  if (showFailures)
137  {
138    if (rootNode.getNumErrors() > 0 || rootNode.getChildErrors() > 0)
139    {
140      rootIcon = "Error";
141    }
142    else if (rootNode.getNumWarnings() > 0 || rootNode.getChildWarnings() > 0)
143    {
144      rootIcon = "Warning";
145    }
146  }
147  %>
148  <base:page title="" type="popup">
149  <base:head scripts="newjoust.js,ajax.js" styles="newjoust.css">
150  <script language="JavaScript">
151  var isInitialised = false;
152  function initialise()
153  {
154    if (parent && parent.parent && parent.parent.adjustIFrameSize) parent.parent.adjustIFrameSize();
155    IconStore.init();
156    var path = getRoot()+'images/joust/';
157   
158    IconStore.addIcon('Warning', getRoot() + 'images/warning.gif', 16, 16);
159    IconStore.addIcon('Error', getRoot() + 'images/error.gif', 16, 16);
160    IconStore.addIcon('FolderWarning', path + 'folderwarning.gif', 18, 16);
161    IconStore.addIcon('FolderWarningSelected', path + 'folderwarningselected.gif', 18, 16);
162    IconStore.addIcon('FolderChildWarning', path + 'folderchildwarning.gif', 18, 16);
163    IconStore.addIcon('FolderChildWarningSelected', path + 'folderchildwarningselected.gif', 18, 16);
164    IconStore.addIcon('FolderError', path + 'foldererror.gif', 18, 16);
165    IconStore.addIcon('FolderErrorSelected', path + 'foldererrorselected.gif', 18, 16);
166    IconStore.addIcon('FolderChildError', path + 'folderchilderror.gif', 18, 16);
167    IconStore.addIcon('FolderChildErrorSelected', path + 'folderchilderrorselected.gif', 18, 16);
168    IconStore.addIcon('Item', path + 'item.gif', 18, 16);
169    IconStore.addIcon('ItemSelected', path + 'itemselected.gif', 18, 16);
170    IconStore.addIcon('ItemWarning', path + 'itemwarning.gif', 18, 16);
171    IconStore.addIcon('ItemWarningSelected', path + 'itemwarningselected.gif', 18, 16);
172    IconStore.addIcon('ItemChildWarning', path + 'itemchildwarning.gif', 18, 16);
173    IconStore.addIcon('ItemChildWarningSelected', path + 'itemchildwarningselected.gif', 18, 16);
174    IconStore.addIcon('ItemError', path + 'itemerror.gif', 18, 16);
175    IconStore.addIcon('ItemErrorSelected', path + 'itemerrorselected.gif', 18, 16);
176    IconStore.addIcon('ItemChildError', path + 'itemchilderror.gif', 18, 16);
177    IconStore.addIcon('ItemChildErrorSelected', path + 'itemchilderrorselected.gif', 18, 16);
178    IconStore.addIcon('ProtocolParameter', path + 'parameter.gif', 18, 16);
179    IconStore.addIcon('ProtocolParameterSelected', path + 'parameterselected.gif', 18, 16);
180    IconStore.addIcon('ProtocolParameterWarning', path + 'parameterwarning.gif', 18, 16);
181    IconStore.addIcon('ProtocolParameterWarningSelected', path + 'parametererrorselected.gif', 18, 16);
182    IconStore.addIcon('ProtocolParameterError', path + 'parameterwarning.gif', 18, 16);
183    IconStore.addIcon('ProtocolParameterErrorSelected', path + 'parametererrorselected.gif', 18, 16);
184    IconStore.addIcon('ProtocolParameterChildWarning', path + 'parameterchildwarning.gif', 18, 16);
185    IconStore.addIcon('ProtocolParameterChildWarningSelected', path + 'parameterchilderrorselected.gif', 18, 16);
186    IconStore.addIcon('ProtocolParameterChildError', path + 'parameterchildwarning.gif', 18, 16);
187    IconStore.addIcon('ProtocolParameterChildErrorSelected', path + 'parameterchilderrorselected.gif', 18, 16);
188    IconStore.addIcon('Annotation', path + 'annotation.gif', 18, 16);
189    IconStore.addIcon('AnnotationSelected', path + 'annotationselected.gif', 18, 16);
190    IconStore.addIcon('AnnotationWarning', path + 'annotationwarning.gif', 18, 16);
191    IconStore.addIcon('AnnotationWarningSelected', path + 'annotationwarningselected.gif', 18, 16);
192    IconStore.addIcon('AnnotationError', path + 'annotationerror.gif', 18, 16);
193    IconStore.addIcon('AnnotationErrorSelected', path + 'annotationerrorselected.gif', 18, 16);
194    IconStore.addIcon('AnnotationChildWarning', path + 'annotationchildwarning.gif', 18, 16);
195    IconStore.addIcon('AnnotationChildWarningSelected', path + 'annotationchildwarningselected.gif', 18, 16);
196    IconStore.addIcon('AnnotationChildError', path + 'annotationchilderror.gif', 18, 16);
197    IconStore.addIcon('AnnotatioChildnErrorSelected', path + 'annotationchilderrorselected.gif', 18, 16);
198    var node<%=rootNode.hashCode()%> = JoustMenu.addMenuItem(-1, '<%=rootIcon%>', '<%=HTML.javaScriptEncode(rootItem.getName())%>', 'showInfo("<%=rootNode.getId()%>")', '', '<%=rootNode.getId()%>');
199    <%=generateSubTree(rootNode, ID, showFailures)%>
200    JoustMenu.menuItems[node<%=rootNode.hashCode()%>].isOpen = true;
201    JoustMenu.draw('joust');
202    isInitialised = true;
203  }
204
205  function openAll()
206  {
207    JoustMenu.openAll();
208  }
209
210  function closeAll()
211  {
212    JoustMenu.closeAll();
213  }
214 
215  function showInfo(nodeId)
216  {
217    parent.frames['info'].location.href = 'info.jsp?ID=<%=ID%>&nodeId='+nodeId+'&show_failures=<%=showFailures%>';
218  }
219 
220  function selectNode(nodeId)
221  {
222    var node = JoustMenu.menuItems[nodeId];
223    JoustMenu.select(node.index);
224  }
225 
226  var loadedTime = new Date().getTime();
227  function refreshIfOutdated()
228  {
229    var currentTime = new Date().getTime();
230    if (currentTime - loadedTime > 2000)
231    {
232      location.reload();
233    }
234  }
235
236  function lazyInitSubNode(nodeId)
237  {
238    var parentMenu = JoustMenu.menuItems[nodeId];
239    JoustMenu.changeCursorOnMenuItem(parentMenu.index, 'progress');   
240    var request = Ajax.getXmlHttpRequest();
241    var url = 'ajax.jsp?ID=<%=ID%>&cmd=GetSubNodes&node_id=' + nodeId;
242    request.open("GET", url, false);
243    request.send(null);
244    var response = request.responseText.split('\n');
245
246    var kv = new Array();
247    var numAdded = 0;
248   
249    for (var i=0; i<response.length; i++)
250    {
251      var txt = Main.trimString(response[i]);     
252      if (txt == 'end')
253      {
254        var id = kv['id'];
255        var folderIcon = kv['folderIcon'];                               
256        numAdded++;
257        var node = JoustMenu.addLazyChildItem(
258              parentMenu.index, folderIcon, Main.trimString(kv['title']), 'showInfo(\''+id+'\')', 
259                '' , id, 'lazyInitSubNode(\''+id+'\')');
260      }
261      else
262      {
263        var tmp = txt.split('\t', 2);
264        kv[tmp[0]] = tmp[1];
265      }
266      JoustMenu.updateIconsAndText(parentMenu.index, true);
267    }   
268    JoustMenu.changeCursorOnMenuItem(parentMenu.index, 'pointer');
269    return numAdded > 0;         
270  }
271 
272  </script>
273  </base:head>
274    <base:body onload="initialise()">
275    <div id="main" class="joust" style="width:100%;">
276      <div id="joust" style="overflow: auto;">
277      </div>
278    </div>
279    </base:body>
280  </base:page>
281  <%
282}
283finally
284{
285  if (dc != null) dc.close();
286}
287%>
Note: See TracBrowser for help on using the repository browser.