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

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

References #1240. Some adjustments on menuitems' tooltip- and cursor- behavior. The validate-toolbutton is decided to validate the whole tree and not only already loaded nodes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 12.1 KB
Line 
1<%-- $Id: tree.jsp 4830 2009-03-23 15:46:46Z 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)
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    if (child.getItemType() == Item.ANNOTATIONTYPE && startNode.getItemType() == Item.PROTOCOL)
56    {
57      folderIcon = "ProtocolParameter";
58    }
59    else if (child.getItemType() == Item.ANNOTATION)
60    {
61      folderIcon = "Annotation";
62    }
63    if (errors > 0)
64    {
65      folderIcon += "Error";
66    }
67    else if (warnings > 0)
68    {
69      folderIcon += "Warning";
70    }
71    else if (childErrors > 0)
72    {
73      folderIcon += "ChildError";
74    }
75    else if (childWarnings > 0)
76    {
77      folderIcon += "ChildWarning";
78    }
79    String tooltip = "";
80    if (warnings > 0 && errors > 0)
81    {
82      tooltip += errors + " error(s); " + warnings + " warning(s) on this item";
83    }
84    else if (errors > 0)
85    {
86      tooltip += errors + " error(s) on this item";
87    }
88    else if (warnings > 0)
89    {
90      tooltip += warnings + " warning(s) on this item";
91    }
92    if (childErrors > 0 && childWarnings > 0)
93    {
94      if (tooltip.length() > 0) tooltip += "; ";
95      tooltip += childErrors + " error(s); " + childWarnings + " warning(s) on child items";
96    }
97    else if (childErrors > 0)
98    {
99      if (tooltip.length() > 0) tooltip += "; ";
100      tooltip += childErrors + " error(s) on child items";
101    }
102    else if (childWarnings > 0)
103    {
104      if (tooltip.length() > 0) tooltip += "; ";
105      tooltip += childWarnings + " warning(s) on child items";
106    }
107    int numChildren = child.getChildren() == null ? 
108      0 : child.getChildren().size();
109    sb.append("var node").append(child.hashCode()).append(" = JoustMenu.addLazyChildItem(").append("node"+startNode.hashCode());
110    sb.append(",'").append(folderIcon).append("'");
111    sb.append(",'").append(HTML.javaScriptEncode(child.getTitle()));
112    sb.append(child.getNodeType() == Node.Type.FOLDER ? " (" + numChildren + ")" : "").append("',");
113    sb.append("'showInfo(\"").append(child.getId()).append("\")','").append(HTML.javaScriptEncode(tooltip)).append("', '").append(child.getId()).append("',");
114    sb.append("'lazyInitSubNode(").append(child.hashCode()).append(")')\n");
115    sb.append(generateSubTree(child, ID));
116  }
117  return sb.toString();
118}
119%>
120<%
121final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
122final String ID = sc.getId();
123final float scale = Base.getScale(sc);
124final DbControl dc = null;
125try
126{
127  GenericOverview overview = OverviewUtil.getCurrentOverview(sc);
128 
129  Nameable rootItem = (Nameable)overview.getRootItem();
130  Node rootNode = overview.getRootNode();
131  String rootIcon = "Home";
132  if (rootNode.getNumErrors() > 0 || rootNode.getChildErrors() > 0)
133  {
134    rootIcon = "Error";
135  }
136  else if (rootNode.getNumWarnings() > 0 || rootNode.getChildWarnings() > 0)
137  {
138    rootIcon = "Warning";
139  }
140  %>
141  <base:page title="" type="popup">
142  <base:head scripts="newjoust.js,ajax.js" styles="newjoust.css">
143  <script language="JavaScript">
144  var isInitialised = false;
145  function initialise()
146  {
147    if (parent && parent.parent && parent.parent.adjustIFrameSize) parent.parent.adjustIFrameSize();
148    IconStore.init();
149    var path = getRoot()+'images/joust/';
150   
151    IconStore.addIcon('Warning', getRoot() + 'images/warning.gif', 16, 16);
152    IconStore.addIcon('Error', getRoot() + 'images/error.gif', 16, 16);
153    IconStore.addIcon('FolderWarning', path + 'folderwarning.gif', 18, 16);
154    IconStore.addIcon('FolderWarningSelected', path + 'folderwarningselected.gif', 18, 16);
155    IconStore.addIcon('FolderChildWarning', path + 'folderchildwarning.gif', 18, 16);
156    IconStore.addIcon('FolderChildWarningSelected', path + 'folderchildwarningselected.gif', 18, 16);
157    IconStore.addIcon('FolderError', path + 'foldererror.gif', 18, 16);
158    IconStore.addIcon('FolderErrorSelected', path + 'foldererrorselected.gif', 18, 16);
159    IconStore.addIcon('FolderChildError', path + 'folderchilderror.gif', 18, 16);
160    IconStore.addIcon('FolderChildErrorSelected', path + 'folderchilderrorselected.gif', 18, 16);
161    IconStore.addIcon('Item', path + 'item.gif', 18, 16);
162    IconStore.addIcon('ItemSelected', path + 'itemselected.gif', 18, 16);
163    IconStore.addIcon('ItemWarning', path + 'itemwarning.gif', 18, 16);
164    IconStore.addIcon('ItemWarningSelected', path + 'itemwarningselected.gif', 18, 16);
165    IconStore.addIcon('ItemChildWarning', path + 'itemchildwarning.gif', 18, 16);
166    IconStore.addIcon('ItemChildWarningSelected', path + 'itemchildwarningselected.gif', 18, 16);
167    IconStore.addIcon('ItemError', path + 'itemerror.gif', 18, 16);
168    IconStore.addIcon('ItemErrorSelected', path + 'itemerrorselected.gif', 18, 16);
169    IconStore.addIcon('ItemChildError', path + 'itemchilderror.gif', 18, 16);
170    IconStore.addIcon('ItemChildErrorSelected', path + 'itemchilderrorselected.gif', 18, 16);
171    IconStore.addIcon('ProtocolParameter', path + 'parameter.gif', 18, 16);
172    IconStore.addIcon('ProtocolParameterSelected', path + 'parameterselected.gif', 18, 16);
173    IconStore.addIcon('ProtocolParameterWarning', path + 'parameterwarning.gif', 18, 16);
174    IconStore.addIcon('ProtocolParameterWarningSelected', path + 'parametererrorselected.gif', 18, 16);
175    IconStore.addIcon('ProtocolParameterError', path + 'parameterwarning.gif', 18, 16);
176    IconStore.addIcon('ProtocolParameterErrorSelected', path + 'parametererrorselected.gif', 18, 16);
177    IconStore.addIcon('ProtocolParameterChildWarning', path + 'parameterchildwarning.gif', 18, 16);
178    IconStore.addIcon('ProtocolParameterChildWarningSelected', path + 'parameterchilderrorselected.gif', 18, 16);
179    IconStore.addIcon('ProtocolParameterChildError', path + 'parameterchildwarning.gif', 18, 16);
180    IconStore.addIcon('ProtocolParameterChildErrorSelected', path + 'parameterchilderrorselected.gif', 18, 16);
181    IconStore.addIcon('Annotation', path + 'annotation.gif', 18, 16);
182    IconStore.addIcon('AnnotationSelected', path + 'annotationselected.gif', 18, 16);
183    IconStore.addIcon('AnnotationWarning', path + 'annotationwarning.gif', 18, 16);
184    IconStore.addIcon('AnnotationWarningSelected', path + 'annotationwarningselected.gif', 18, 16);
185    IconStore.addIcon('AnnotationError', path + 'annotationerror.gif', 18, 16);
186    IconStore.addIcon('AnnotationErrorSelected', path + 'annotationerrorselected.gif', 18, 16);
187    IconStore.addIcon('AnnotationChildWarning', path + 'annotationchildwarning.gif', 18, 16);
188    IconStore.addIcon('AnnotationChildWarningSelected', path + 'annotationchildwarningselected.gif', 18, 16);
189    IconStore.addIcon('AnnotationChildError', path + 'annotationchilderror.gif', 18, 16);
190    IconStore.addIcon('AnnotatioChildnErrorSelected', path + 'annotationchilderrorselected.gif', 18, 16);
191    var node<%=rootNode.hashCode()%> = JoustMenu.addMenuItem(-1, '<%=rootIcon%>', '<%=HTML.javaScriptEncode(rootItem.getName())%>', 'showInfo("<%=rootNode.getId()%>")', '', '<%=rootNode.getId()%>');
192    <%=generateSubTree(rootNode, ID)%>
193    JoustMenu.menuItems[node<%=rootNode.hashCode()%>].isOpen = true;
194    JoustMenu.draw('joust');
195    isInitialised = true;
196  }
197
198  function openAll()
199  {
200    JoustMenu.openAll();
201  }
202
203  function closeAll()
204  {
205    JoustMenu.closeAll();
206  }
207 
208  function showInfo(nodeId)
209  {
210    parent.frames['info'].location.href = 'info.jsp?ID=<%=ID%>&nodeId='+nodeId;
211  }
212 
213  function selectNode(nodeId)
214  {
215    var node = JoustMenu.menuItems[nodeId];
216    JoustMenu.select(node.index);
217  }
218 
219  var loadedTime = new Date().getTime();
220  function refreshIfOutdated()
221  {
222    var currentTime = new Date().getTime();
223    if (currentTime - loadedTime > 2000)
224    {
225      location.reload();
226    }
227  }
228
229  function lazyInitSubNode(nodeId)
230  {
231    var parentMenu = JoustMenu.menuItems['N' + nodeId];
232    JoustMenu.changeCursorOnMenuItem(parentMenu.index, 'progress');   
233    var request = Ajax.getXmlHttpRequest();
234    var url = 'ajax.jsp?ID=<%=ID%>&cmd=GetSubNodes&node_id=' + nodeId;
235    request.open("GET", url, false);
236    request.send(null);
237    var response = request.responseText.split('\n');
238
239    var kv = new Array();
240    var numAdded = 0;
241   
242    for (var i=0; i<response.length; i++)
243    {
244      var txt = Main.trimString(response[i]);     
245      if (txt == 'end')
246      {
247        var id = kv['id'];
248        var folderIcon = kv['folderIcon'];       
249        var parentIconSuffix = kv['parentIconSuffix'];
250        var tooltip = kv['tooltip'] ? kv['tooltip'] : ''; 
251        var parentTooltip = kv['parentTooltip'] ? kv['parentTooltip'] : '';                           
252        numAdded++;
253        var node = JoustMenu.addLazyChildItem(
254              parentMenu.index, folderIcon, kv['title'], 'showInfo(\''+id+'\')', 
255                tooltip , id, 'lazyInitSubNode('+kv['hashCode']+')');
256       
257        if (parentIconSuffix)
258        {
259          updateParentMenu(parentMenu, parentIconSuffix, parentTooltip);         
260          JoustMenu.menuItems['0'].iconName = parentIconSuffix;
261          reloadSiblingFrames();
262        }
263      }
264      else
265      {
266        var tmp = txt.split('\t', 2);
267        kv[tmp[0]] = tmp[1];
268      }
269      JoustMenu.updateIconsAndText(parentMenu.index, true);
270    }   
271    JoustMenu.changeCursorOnMenuItem(parentMenu.index, 'pointer');
272    return numAdded > 0;         
273  }
274
275  function reloadSiblingFrames()
276  {
277    parent.frames.failures.location.reload();
278    parent.frames.info.location.reload();
279  }
280
281  function updateParentMenu(menuItem, iconSuffix, tooltip)
282  {
283    menuItem.tooltip = tooltip;
284    var currentIcon = menuItem.iconName;   
285    if (currentIcon.indexOf('Error') < 0 && currentIcon.indexOf('Warning') < 0)
286    {
287      menuItem.iconName += iconSuffix;
288    }
289    else if (iconSuffix == 'Error')
290    { 
291      menuItem.iconName = currentIcon.replace(/ChildError/, iconSuffix);
292      menuItem.iconName = currentIcon.replace(/ChildWarning/, iconSuffix);
293      menuItem.iconName = currentIcon.replace(/Warning/, iconSuffix);
294    }
295    else if (iconSuffix == 'Warning')
296    {
297      menuItem.iconName = currentIcon.replace(/ChildError/, iconSuffix);
298      menuItem.iconName = currentIcon.replace(/ChildWarning/, iconSuffix);           
299    }
300    updateIconRecursively(menuItem.parentItemIndex, 'Child'+iconSuffix);
301  }
302
303  function updateIconRecursively(itemIndex, newIconSuffix)
304  {   
305    var item = JoustMenu.menuItems[itemIndex];
306    var currentIcon = item.iconName;
307    if (currentIcon.indexOf('Error') < 0 && currentIcon.indexOf('Warning') < 0)
308    {
309      item.iconName += newIconSuffix;
310    }
311    else if (newIconSuffix == 'ChildError')
312    {
313      item.iconName = currentIcon.replace(/ChildWarning/, newIconSuffix);
314    }
315    if (item.parentItemIndex > 0)
316    {
317      updateIconRecursively(item.parentItemIndex, newIconSuffix);
318    }
319  }
320 
321  </script>
322  </base:head>
323    <base:body onload="initialise()">
324    <div id="main" class="joust" style="width:100%;">
325      <div id="joust" style="overflow: auto;">
326      </div>
327    </div>
328    </base:body>
329  </base:page>
330  <%
331}
332finally
333{
334  if (dc != null) dc.close();
335}
336%>
Note: See TracBrowser for help on using the repository browser.