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

Last change on this file since 2978 was 2978, checked in by Nicklas Nordborg, 16 years ago

Added session="false" to all jsp pages so we no longer generate unneeded cookies

  • 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 2978 2006-11-30 07:27:42Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) Authors contributing to this file.
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 2
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 this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA  02111-1307, USA.
22  ------------------------------------------------------------------
23
24  @author Nicklas
25  @version 2.0
26--%>
27<%@ page session="false"
28  import="net.sf.basedb.core.SessionControl"
29  import="net.sf.basedb.core.DbControl"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.ItemContext"
32  import="net.sf.basedb.core.BasicItem"
33  import="net.sf.basedb.core.Experiment"
34  import="net.sf.basedb.core.BioAssaySet"
35  import="net.sf.basedb.core.Transformation"
36  import="net.sf.basedb.core.ItemQuery"
37  import="net.sf.basedb.core.Nameable"
38  import="net.sf.basedb.core.ItemResultIterator"
39  import="net.sf.basedb.core.ItemResultList"
40  import="net.sf.basedb.core.Permission"
41  import="net.sf.basedb.core.PluginDefinition"
42  import="net.sf.basedb.core.PermissionDeniedException"
43  import="net.sf.basedb.core.query.Restrictions"
44  import="net.sf.basedb.core.query.Expressions"
45  import="net.sf.basedb.core.query.Orders"
46  import="net.sf.basedb.core.query.Hql"
47  import="net.sf.basedb.core.query.Restrictions"
48  import="net.sf.basedb.core.plugin.GuiContext"
49  import="net.sf.basedb.core.plugin.Plugin"
50  import="net.sf.basedb.util.Tree"
51  import="net.sf.basedb.clients.web.Base"
52  import="net.sf.basedb.clients.web.ModeInfo"
53  import="net.sf.basedb.clients.web.util.HTML"
54  import="net.sf.basedb.util.Values"
55  import="java.util.List"
56  import="java.util.ArrayList"
57  import="java.util.LinkedList"
58  import="java.util.Map"
59  import="java.util.HashMap"
60  import="java.util.Iterator"
61  import="java.util.Collection"
62%>
63<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
64<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
65<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
66<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
67<%!
68  private static final Item itemType = Item.BIOASSAYSET;
69  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
70%>
71<%!
72
73private static void addToTree(Tree<BasicItem> tree, BioAssaySet bas)
74{
75  if (!tree.contains(bas))
76  {
77    Transformation transformation = bas.getTransformation();
78    Tree.Entry<BasicItem> parent = tree.getEntry(transformation);
79    if (parent == null) 
80    {
81      addToTree(tree, transformation);
82      parent = tree.getEntry(transformation);
83    }
84    parent.addChild(bas);
85  }
86}
87
88private static void addToTree(Tree<BasicItem> tree, Transformation transformation)
89{
90  if (!tree.contains(transformation))
91  {
92    BioAssaySet source = transformation.getSource();
93    Tree.Entry<BasicItem> parent = tree.getEntry(source);
94    if (parent == null) 
95    {
96      addToTree(tree, source);
97      parent = tree.getEntry(source);
98    }
99    parent.addChild(transformation);
100  }
101}
102
103private static Tree<BasicItem> getAnalysisTree(DbControl dc, ItemQuery<BioAssaySet> bioAssaySetQuery, ItemQuery<Transformation> transformationQuery)
104{
105  Tree<BasicItem> tree = new Tree<BasicItem>(null);
106  ItemResultList<BioAssaySet> allBioAssaySets = bioAssaySetQuery.list(dc);
107  List<Integer> ids = new ArrayList<Integer>(allBioAssaySets.size());
108 
109  for (BioAssaySet bas : allBioAssaySets)
110  {
111    addToTree(tree, bas);
112    ids.add(bas.getId());
113  }
114 
115  transformationQuery.restrict(
116    Restrictions.in(
117      Hql.property("source.id"), 
118      Expressions.parameter("bioAssaySets", ids)
119    )
120  );
121  ItemResultList<Transformation> allTransformations = transformationQuery.list(dc);
122  for (Transformation t: allTransformations)
123  {
124    addToTree(tree, t);
125  }
126  return tree;
127}
128String generateTree(Tree<BasicItem> tree, BasicItem root, Collection<String> closed)
129{
130  StringBuilder sb = new StringBuilder();
131  Tree.Entry<BasicItem> rootEntry = tree.getEntry(root);
132  if (rootEntry == null) return "";
133 
134  List<Tree.Entry<BasicItem>> children = rootEntry.getChildren();
135  if (children != null)
136  {
137    for (Tree.Entry<BasicItem> child : children)
138    {
139      BasicItem node = child.getNode();
140      int id = node.getId();
141      String var = node.getType().name() + "_" + id;
142      String name = ((Nameable)node).getName();
143     
144      String folderIcon = node.getType() == Item.BIOASSAYSET ?
145        "BioAssaySet" : "Transformation";
146      sb.append("var ").append(var);
147      if (root == null)
148      {
149        sb.append(" = JoustMenu.addMenuItem(-1");
150      }
151      else
152      {
153        String rootVar = root.getType().name() + "_" + root.getId();
154        sb.append(" = JoustMenu.addChildItem(").append(rootVar); 
155      }
156      sb.append(",'").append(folderIcon).append("'");
157      sb.append(",'").append(HTML.javaScriptEncode(name)).append("'");
158      sb.append(", null, '', '").append(var).append("');\n");
159      if ((closed == null || !closed.contains(var)) && child.getNumChildren() > 0)
160      {
161        sb.append("JoustMenu.menuItems[").append(var).append("].isOpen = true;\n");
162      }
163      sb.append(generateTree(tree, node, closed));
164    }
165  }
166  return sb.toString();
167}
168%>
169<%
170final int experimentId = Values.getInt(request.getParameter("experiment_id"));
171final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
172final String ID = sc.getId();
173final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
174final ItemContext tc = sc.getCurrentContext(Item.TRANSFORMATION);
175
176final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
177final String callback = request.getParameter("callback");
178final String title = mode.generateTitle("bioassay set", "bioassay sets");
179final DbControl dc = sc.newDbControl();
180Tree<BasicItem> analysisTree = null;
181try
182{
183  final Experiment experiment = Experiment.getById(dc, experimentId);
184  final boolean createPermission = experiment.hasPermission(Permission.WRITE);
185  final boolean deletePermission = createPermission;
186  final boolean writePermission = createPermission;
187
188  final ItemQuery<BioAssaySet> query = Base.getConfiguredQuery(cc, true, experiment.getBioAssaySets(), mode);
189  final ItemQuery<Transformation> transformationQuery = experiment.getTransformations();
190  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
191  try
192  {
193    analysisTree = getAnalysisTree(dc, query, transformationQuery);
194  }
195  catch (Throwable t)
196  {
197    cc.setMessage(t.getMessage());
198  }
199  // Contains the ID:s of the bioassaysets that are closed in the tree
200  Collection<String> closed = (Collection<String>)cc.getObject("closed");
201  int numListed = 0;
202  %>
203  <base:page title="<%=title%>" type="<%=mode.getPageType()%>">
204  <base:head scripts="table.js,tabcontrol.js,newjoust.js" styles="table.css,headertabcontrol.css,path.css,newjoust.css">
205    <script language="JavaScript">
206    function viewExperimentProperties()
207    {
208      location.href = '../index.jsp?ID=<%=ID%>&experiment_id=<%=experimentId%>&cmd=ViewItem';
209    }
210    function switchTab(tabControlId, tabId)
211    {
212      if (tabId == 'properties')
213      {
214        viewExperimentProperties();
215      }
216      else
217      {
218        TabControl.setActiveTab(tabControlId, tabId);
219      }
220    }
221    </script>
222  </base:head>
223 
224  <base:body >
225    <p>
226    <p:path>
227      <p:pathelement title="Experiments" href="<%="../index.jsp?ID="+ID%>" />
228      <p:pathelement title="<%=HTML.encodeTags(experiment.getName())%>" />
229    </p:path>
230
231    <t:tabcontrol id="main" active="bioassaysets" switch="switchTab">
232    <t:tab id="properties" title="Properties" />
233   
234    <t:tab id="bioassaysets" title="Bioassay sets">
235   
236      <jsp:include page="analysis_tree.jsp">
237        <jsp:param name="ID" value="<%=ID%>" />
238        <jsp:param name="experiment_id" value="<%=experimentId%>" />
239      </jsp:include>
240   
241    <base:buttongroup align="center">
242      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
243      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
244      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
245    </base:buttongroup>
246    </t:tab>
247    </t:tabcontrol>
248
249  </base:body>
250  </base:page>
251  <%
252}
253finally
254{
255  if (dc != null) dc.close();
256}
257%>
Note: See TracBrowser for help on using the repository browser.