source: trunk/www/views/experiments/bioassaysets/list_bioassaysets.jsp @ 4889

Last change on this file since 4889 was 4889, checked in by Nicklas Nordborg, 14 years ago

References #1290: Change source files to UTF-8

Changed 'Hakkinen' to 'Häkkinen'.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 8.4 KB
Line 
1<%-- $Id: list_bioassaysets.jsp 4889 2009-04-06 12:52:39Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
4  Copyright (C) 2007 Nicklas Nordborg
5
6  This file is part of BASE - BioArray Software Environment.
7  Available at http://base.thep.lu.se/
8
9  BASE is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License
11  as published by the Free Software Foundation; either version 3
12  of the License, or (at your option) any later version.
13
14  BASE is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with BASE. If not, see <http://www.gnu.org/licenses/>.
21  ------------------------------------------------------------------
22
23  @author Nicklas
24  @version 2.0
25--%>
26<%@ page session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.Item"
30  import="net.sf.basedb.core.ItemContext"
31  import="net.sf.basedb.core.BasicItem"
32  import="net.sf.basedb.core.Experiment"
33  import="net.sf.basedb.core.BioAssaySet"
34  import="net.sf.basedb.core.Transformation"
35  import="net.sf.basedb.core.ItemQuery"
36  import="net.sf.basedb.core.Nameable"
37  import="net.sf.basedb.core.ItemResultIterator"
38  import="net.sf.basedb.core.ItemResultList"
39  import="net.sf.basedb.core.Permission"
40  import="net.sf.basedb.core.PluginDefinition"
41  import="net.sf.basedb.core.PermissionDeniedException"
42  import="net.sf.basedb.core.query.Restrictions"
43  import="net.sf.basedb.core.query.Expressions"
44  import="net.sf.basedb.core.query.Orders"
45  import="net.sf.basedb.core.query.Hql"
46  import="net.sf.basedb.core.query.Restrictions"
47  import="net.sf.basedb.core.plugin.GuiContext"
48  import="net.sf.basedb.core.plugin.Plugin"
49  import="net.sf.basedb.util.Tree"
50  import="net.sf.basedb.clients.web.Base"
51  import="net.sf.basedb.clients.web.ModeInfo"
52  import="net.sf.basedb.clients.web.util.HTML"
53  import="net.sf.basedb.util.Values"
54  import="java.util.List"
55  import="java.util.ArrayList"
56  import="java.util.LinkedList"
57  import="java.util.Map"
58  import="java.util.HashMap"
59  import="java.util.Iterator"
60  import="java.util.Collection"
61%>
62<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
63<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
64<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
65<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
66<%!
67  private static final Item itemType = Item.BIOASSAYSET;
68  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
69%>
70<%!
71
72private static void addToTree(Tree<BasicItem> tree, BioAssaySet bas)
73{
74  if (!tree.contains(bas))
75  {
76    Transformation transformation = bas.getTransformation();
77    Tree.Entry<BasicItem> parent = tree.getEntry(transformation);
78    if (parent == null) 
79    {
80      addToTree(tree, transformation);
81      parent = tree.getEntry(transformation);
82    }
83    parent.addChild(bas);
84  }
85}
86
87private static void addToTree(Tree<BasicItem> tree, Transformation transformation)
88{
89  if (!tree.contains(transformation))
90  {
91    BioAssaySet source = transformation.getSource();
92    Tree.Entry<BasicItem> parent = tree.getEntry(source);
93    if (parent == null) 
94    {
95      addToTree(tree, source);
96      parent = tree.getEntry(source);
97    }
98    parent.addChild(transformation);
99  }
100}
101
102private static Tree<BasicItem> getAnalysisTree(DbControl dc, ItemQuery<BioAssaySet> bioAssaySetQuery, ItemQuery<Transformation> transformationQuery)
103{
104  Tree<BasicItem> tree = new Tree<BasicItem>(null);
105  ItemResultList<BioAssaySet> allBioAssaySets = bioAssaySetQuery.list(dc);
106  List<Integer> ids = new ArrayList<Integer>(allBioAssaySets.size());
107 
108  for (BioAssaySet bas : allBioAssaySets)
109  {
110    addToTree(tree, bas);
111    ids.add(bas.getId());
112  }
113 
114  transformationQuery.restrict(
115    Restrictions.in(
116      Hql.property("source.id"), 
117      Expressions.parameter("bioAssaySets", ids)
118    )
119  );
120  ItemResultList<Transformation> allTransformations = transformationQuery.list(dc);
121  for (Transformation t: allTransformations)
122  {
123    addToTree(tree, t);
124  }
125  return tree;
126}
127String generateTree(Tree<BasicItem> tree, BasicItem root, Collection<String> closed)
128{
129  StringBuilder sb = new StringBuilder();
130  Tree.Entry<BasicItem> rootEntry = tree.getEntry(root);
131  if (rootEntry == null) return "";
132 
133  List<Tree.Entry<BasicItem>> children = rootEntry.getChildren();
134  if (children != null)
135  {
136    for (Tree.Entry<BasicItem> child : children)
137    {
138      BasicItem node = child.getNode();
139      int id = node.getId();
140      String var = node.getType().name() + "_" + id;
141      String name = ((Nameable)node).getName();
142     
143      String folderIcon = node.getType() == Item.BIOASSAYSET ?
144        "BioAssaySet" : "Transformation";
145      sb.append("var ").append(var);
146      if (root == null)
147      {
148        sb.append(" = JoustMenu.addMenuItem(-1");
149      }
150      else
151      {
152        String rootVar = root.getType().name() + "_" + root.getId();
153        sb.append(" = JoustMenu.addChildItem(").append(rootVar); 
154      }
155      sb.append(",'").append(folderIcon).append("'");
156      sb.append(",'").append(HTML.javaScriptEncode(name)).append("'");
157      sb.append(", null, '', '").append(var).append("');\n");
158      if ((closed == null || !closed.contains(var)) && child.getNumChildren() > 0)
159      {
160        sb.append("JoustMenu.menuItems[").append(var).append("].isOpen = true;\n");
161      }
162      sb.append(generateTree(tree, node, closed));
163    }
164  }
165  return sb.toString();
166}
167%>
168<%
169final int experimentId = Values.getInt(request.getParameter("experiment_id"));
170final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
171final String ID = sc.getId();
172final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
173final ItemContext tc = sc.getCurrentContext(Item.TRANSFORMATION);
174
175final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
176final String callback = request.getParameter("callback");
177final String title = mode.generateTitle("bioassay set", "bioassay sets");
178final DbControl dc = sc.newDbControl();
179Tree<BasicItem> analysisTree = null;
180try
181{
182  final Experiment experiment = Experiment.getById(dc, experimentId);
183  final boolean createPermission = experiment.hasPermission(Permission.WRITE);
184  final boolean deletePermission = createPermission;
185  final boolean writePermission = createPermission;
186
187  final ItemQuery<BioAssaySet> query = Base.getConfiguredQuery(cc, true, experiment.getBioAssaySets(), mode);
188  final ItemQuery<Transformation> transformationQuery = experiment.getTransformations();
189  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
190  try
191  {
192    analysisTree = getAnalysisTree(dc, query, transformationQuery);
193  }
194  catch (Throwable t)
195  {
196    cc.setMessage(t.getMessage());
197  }
198  // Contains the ID:s of the bioassaysets that are closed in the tree
199  Collection<String> closed = (Collection<String>)cc.getObject("closed");
200  int numListed = 0;
201  %>
202  <base:page title="<%=title%>" type="<%=mode.getPageType()%>">
203  <base:head scripts="table.js,tabcontrol.js,newjoust.js" styles="table.css,headertabcontrol.css,path.css,newjoust.css">
204    <script language="JavaScript">
205    function switchTab(tabControlId, tabId)
206    {
207      if (tabId == 'properties' || tabId == 'overview')
208      {
209        location.href = '../index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id=<%=experimentId%>&tab='+tabId;
210      }
211      else
212      {
213        TabControl.setActiveTab(tabControlId, tabId);
214      }
215    }
216    </script>
217  </base:head>
218 
219  <base:body >
220    <p>
221    <p:path>
222      <p:pathelement title="Experiments" href="<%="../index.jsp?ID="+ID%>" />
223      <p:pathelement title="<%=HTML.encodeTags(experiment.getName())%>" />
224    </p:path>
225
226    <t:tabcontrol id="main" active="bioassaysets" switch="switchTab">
227    <t:tab id="properties" title="Properties" />
228   
229    <t:tab id="bioassaysets" title="Bioassay sets">
230   
231      <jsp:include page="analysis_tree.jsp">
232        <jsp:param name="ID" value="<%=ID%>" />
233        <jsp:param name="experiment_id" value="<%=experimentId%>" />
234      </jsp:include>
235   
236    <base:buttongroup align="center">
237      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
238      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
239      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
240    </base:buttongroup>
241    </t:tab>
242    <t:tab id="overview" title="Overview" 
243      tooltip="Display a tree overview of related items" />
244    </t:tabcontrol>
245
246  </base:body>
247  </base:page>
248  <%
249}
250finally
251{
252  if (dc != null) dc.close();
253}
254%>
Note: See TracBrowser for help on using the repository browser.