source: trunk/www/common/annotations/list_annotations.jsp @ 5946

Last change on this file since 5946 was 5946, checked in by Nicklas Nordborg, 12 years ago

References #1655: GUI improvements

Replaces a lot of GIF images with PNG.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 13.6 KB
Line 
1<%-- $Id: list_annotations.jsp 5946 2012-02-03 13:18:47Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
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  @author Nicklas
23  @version 2.0
24--%>
25<%@ page pageEncoding="UTF-8" session="false"
26  import="net.sf.basedb.core.SessionControl"
27  import="net.sf.basedb.core.DbControl"
28  import="net.sf.basedb.core.Item"
29  import="net.sf.basedb.core.Permission"
30  import="net.sf.basedb.core.AnnotationType"
31  import="net.sf.basedb.core.Protocol"
32  import="net.sf.basedb.core.AnnotationSet"
33  import="net.sf.basedb.core.Annotation"
34  import="net.sf.basedb.core.Annotatable"
35  import="net.sf.basedb.core.AnnotatableProxy"
36  import="net.sf.basedb.core.Unit"
37  import="net.sf.basedb.core.Nameable"
38  import="net.sf.basedb.core.ItemQuery"
39  import="net.sf.basedb.core.ItemResultList"
40  import="net.sf.basedb.core.PermissionDeniedException"
41  import="net.sf.basedb.core.query.Orders"
42  import="net.sf.basedb.core.query.Hql"
43  import="net.sf.basedb.core.snapshot.AnnotationSetSnapshot"
44  import="net.sf.basedb.core.snapshot.AnnotationSnapshot"
45  import="net.sf.basedb.core.snapshot.SnapshotManager"
46  import="net.sf.basedb.clients.web.Base"
47  import="net.sf.basedb.clients.web.util.HTML"
48  import="net.sf.basedb.util.NameableComparator"
49  import="net.sf.basedb.util.formatter.Formatter"
50  import="net.sf.basedb.util.formatter.PrefixSuffixFormatter"
51  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
52  import="net.sf.basedb.util.Values"
53  import="java.util.ArrayList"
54  import="java.util.List"
55  import="java.util.Set"
56  import="java.util.HashSet"
57  import="java.util.TreeSet"
58  import="java.util.Map"
59  import="java.util.HashMap"
60%>
61<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
62<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
63
64<%
65final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
66final String ID = sc.getId();
67final Item itemType = Item.valueOf(request.getParameter("item_type"));
68final int itemId = Values.getInt(request.getParameter("item_id"));
69final float scale = Base.getScale(sc);
70final DbControl dc = sc.newDbControl();
71
72Set<AnnotationType> annotationTypes = null;
73Set<AnnotationType> protocolParameters = null;
74Map<AnnotationType, AnnotationSnapshot> existing = null;
75
76try
77{
78  final Annotatable item = (Annotatable)itemType.getById(dc, itemId);
79  final boolean writePermission = item.hasPermission(Permission.WRITE);
80  final SnapshotManager manager = new SnapshotManager();
81 
82  ItemQuery<AnnotationType> annotationTypeQuery = null;
83  String message = null;
84  boolean isProxy = item instanceof AnnotatableProxy;
85
86  // Load all annotation types that are possible for this item type
87  if (isProxy)
88  {
89    AnnotatableProxy proxy = (AnnotatableProxy)item;
90    annotationTypeQuery = Base.getAnnotationTypesQuery(proxy);
91    message = proxy.getAnnotationMessage();
92  }
93  else
94  {
95    annotationTypeQuery = Base.getAnnotationTypesQuery(itemType, false);
96  }
97  annotationTypes = new TreeSet<AnnotationType>(new NameableComparator(false));
98  annotationTypes.addAll(annotationTypeQuery.list(dc));
99
100  final AnnotationSetSnapshot snapshot = item.isAnnotated() ? 
101      manager.getSnapshot(dc, item.getAnnotationSet().getId()) : null;
102  List<AnnotationSnapshot> inheritedAnnotations = null;
103  if (snapshot != null)
104  {
105    // Load the existing primary and inherited annotations
106    existing = new HashMap<AnnotationType, AnnotationSnapshot>();
107    inheritedAnnotations = new ArrayList<AnnotationSnapshot>();
108    for (AnnotationSnapshot a : manager.findAnnotations(dc, snapshot, null, true))
109    {
110      try
111      {
112        AnnotationType at = a.getAnnotationType(dc);
113        if (!a.isInherited())
114        {
115          existing.put(a.getAnnotationType(dc), a);
116        }
117        else
118        {
119          inheritedAnnotations.add(a);
120        }
121      }
122      catch (PermissionDeniedException ex)
123      {}
124    }
125    annotationTypes.addAll(existing.keySet());
126  }
127 
128  // Load the possible protocol parameters
129  Protocol protocol = null;
130  boolean readProtocol = true;
131  try
132  {
133    protocol = item.getProtocol();
134  }
135  catch (PermissionDeniedException ex)
136  {
137    readProtocol = false;
138  }
139  ItemQuery<AnnotationType> parameterQuery = Base.getProtocolParametersQuery(protocol);
140  if (parameterQuery != null)
141  {
142    protocolParameters = new HashSet<AnnotationType>(parameterQuery.list(dc));
143    annotationTypes.removeAll(protocolParameters);
144  }
145  %>
146  <base:page type="include">
147  <base:body>
148    <script language="JavaScript">
149    function editAnnotation(annotationTypeId)
150    {
151      var url = getRoot() + 'common/annotations/annotate.jsp?ID=<%=ID%>';
152      url += '&item_type=<%=itemType.name()%>';
153      url += '&item_id=<%=itemId%>';
154      url += '&annotationtype_id='+annotationTypeId;
155      url += '&standalone=1';
156      Main.openPopup(url, 'EditAnnotation', 750, 500);
157    }
158    function editInheritedAnnotation(itemType, itemId, annotationTypeId)
159    {
160      var url = getRoot() + 'common/annotations/annotate.jsp?ID=<%=ID%>';
161      url += '&item_type='+itemType;
162      url += '&item_id='+itemId;
163      url += '&annotationtype_id='+annotationTypeId;
164      url += '&standalone=1';
165      Main.openPopup(url, 'EditAnnotation', 750, 500);
166    }
167    </script>
168    <%
169    if (message != null)
170    {
171      %>
172      <div class="messagecontainer note"><%=message%></div>
173      <%
174    }
175    %>
176    <base:section
177      id="primaryAnnotations"
178      title="<%="Primary annotations (" + annotationTypes.size() + ")"%>"
179      >
180      <%
181      if (annotationTypes.size() == 0)
182      {
183        %>
184        <div class="messagecontainer note">
185        No annotation types has been defined for this type of item
186        (or you don't have permission to view them).
187        </div>
188        <%
189      }
190      else
191      {
192        %>
193        <tbl:table
194          id="annotations"
195          columns="all"
196          >
197          <tbl:columndef 
198            id="annotation"
199            title="Annotation"
200          />
201          <tbl:columndef 
202            id="values"
203            title="Values"
204          />
205          <tbl:columndef 
206            id="description"
207            title="Description"
208          />
209          <tbl:data>
210            <tbl:headers>
211              <tbl:headerrow>
212                <tbl:columnheaders />
213              </tbl:headerrow>
214            </tbl:headers>
215            <tbl:rows>
216            <%
217            for (AnnotationType at : annotationTypes)
218            {
219              AnnotationSnapshot a = existing != null ? existing.get(at) : null;
220              List<?> values = null;
221              Formatter formatter = null;
222              if (a != null)
223              {
224                Annotation ann = a.getAnnotation(dc);
225                values = a.getValues(ann.getUnitConverter(null), ann.getValueType());
226                formatter = FormatterFactory.getAnnotationFormatter(sc, ann, null);
227              }
228              if (values != null || !at.isRemoved())
229              {
230              %>
231                <tbl:row>
232                  <tbl:cell column="annotation"><base:icon 
233                    image="deleted.png" 
234                    tooltip="This item has been scheduled for deletion" 
235                    visible="<%=at.isRemoved()%>"
236                  /><%=Base.getLinkedName(ID, at, false, true)%></tbl:cell>
237                  <tbl:cell column="values"><%=values == null || values.size() == 0 ? "<i>- no values -</i>" : Values.getString(values, ", ", true, formatter)%>
238                  <%
239                    if (writePermission)
240                    {
241                      %>: <base:icon image="edit.png" 
242                        onclick="<%="editAnnotation("+at.getId()+")"%>" 
243                        tooltip="Modify the values of this annotation" />
244                      <%
245                    }
246                    %>
247                  </tbl:cell>
248                  <tbl:cell column="description"><%=HTML.encodeTags(at.getDescription())%></tbl:cell>
249                </tbl:row>
250                <%
251              }
252            }
253            %>
254            </tbl:rows>
255          </tbl:data>
256        </tbl:table>
257        <%
258      }
259      %>
260    </base:section>
261
262    <%
263    if (protocolParameters != null)
264    {
265      %>
266      <base:section 
267        id="parameterSection" 
268        title="<%="Protocol parameters for " + HTML.encodeTags(protocol.getName()) + 
269          " (" + protocolParameters.size() + ")"%>"
270        >
271        <%
272        if (protocolParameters.size() == 0)
273        {
274          %>
275          <div class="messagecontainer note">
276          No protocol parameters has been defined for the protocol
277          <%=Base.getLinkedName(ID, protocol, !readProtocol, true)%> 
278          (or you don't have permission to view them).
279          </div>
280          <%
281        }
282        else
283        {
284          %>
285          <tbl:table
286            id="parameters"
287            columns="all"
288            >
289            <tbl:columndef 
290              id="parameter"
291              title="Parameter"
292            />
293            <tbl:columndef 
294              id="values"
295              title="Values"
296            />
297            <tbl:columndef 
298              id="description"
299              title="Description"
300            />
301            <tbl:data>
302              <tbl:headers>
303                <tbl:headerrow>
304                  <tbl:columnheaders />
305                </tbl:headerrow>
306              </tbl:headers>
307              <tbl:rows>
308              <%
309              for (AnnotationType at : protocolParameters)
310              {
311                AnnotationSnapshot a = existing != null ? existing.get(at) : null;
312                Formatter formatter = null;
313                List<?> values = null;
314                if (a != null)
315                {
316                  Annotation ann = a.getAnnotation(dc);
317                  values = a.getValues(ann.getUnitConverter(null), ann.getValueType());
318                  formatter = FormatterFactory.getAnnotationFormatter(sc, ann, null);
319                }
320                if (values != null || !at.isRemoved())
321                {
322                  %>
323                  <tbl:row>
324                    <tbl:cell column="parameter"><base:icon 
325                      image="deleted.png" 
326                      tooltip="This item has been scheduled for deletion" 
327                      visible="<%=at.isRemoved()%>"
328                    /><%=Base.getLinkedName(ID, at, false, true)%></tbl:cell>
329                    <tbl:cell column="values">
330                      <%=values == null || values.size() == 0 ? "<i>- no values -</i>" : Values.getString(values, ", ", true, formatter)%>
331                      <%
332                      if (writePermission)
333                      {
334                        %>: <base:icon image="edit.png" 
335                          onclick="<%="editAnnotation("+at.getId()+")"%>" 
336                          tooltip="Modify the values of this protocol parameter" />
337                        <%
338                      }
339                      %>
340                    </tbl:cell>
341                    <tbl:cell column="description"><%=HTML.encodeTags(at.getDescription())%></tbl:cell>
342                  </tbl:row>
343                  <%
344                }
345              }
346              %>
347              </tbl:rows>
348            </tbl:data>
349          </tbl:table>
350          <%
351        }
352        %>
353      </base:section>
354      <%
355    }
356    %>
357    <%
358    if (!isProxy)
359    {
360      int numInherited = inheritedAnnotations == null ? 0 : inheritedAnnotations.size();
361      %>
362      <base:section 
363        id="inherited"
364        title="<%="Inherited annotations and protocol parameters (" + numInherited + ")"%>"         
365        >
366        <%
367        if (numInherited == 0)
368        {
369          %>
370          <div class="messagecontainer note">
371          No annotations are inherited by this item.
372          (or you don't have permission to view them).
373          </div>
374          <%
375        }
376        else
377        {
378        %>
379        <tbl:table
380          id="inheritedAnnotations"
381          columns="all"
382          >
383          <tbl:columndef 
384            id="annotation"
385            title="Annotation"
386          />
387          <tbl:columndef 
388            id="item"
389            title="From item"
390          />
391          <tbl:columndef 
392            id="values"
393            title="Values"
394          />
395          <tbl:columndef 
396            id="description"
397            title="Description"
398          />
399          <tbl:data>
400            <tbl:headers>
401              <tbl:headerrow>
402                <tbl:columnheaders />
403              </tbl:headerrow>
404            </tbl:headers>
405            <tbl:rows>
406            <%
407            for (AnnotationSnapshot a : inheritedAnnotations)
408            {
409              Annotation ann = a.getAnnotation(dc);
410              AnnotationType at = a.getAnnotationType(dc);
411              String name = HTML.encodeTags(at.getName());
412              String description = HTML.encodeTags(at.getDescription());
413              boolean writeInherited = false;
414              String icon = "joust/annotation.gif";
415              if (at.isRemoved())
416              {
417                icon = "deleted.png";
418              }
419              else if (at.isProtocolParameter())
420              {
421                icon = "parameter.png";
422              }
423              List<?> values = a.getValues(ann.getUnitConverter(null), ann.getValueType());
424              Formatter formatter = FormatterFactory.getAnnotationFormatter(sc, ann, null);
425              Nameable aItem = null;
426              try
427              {
428                aItem = (Nameable)a.getItem(dc);
429                writeInherited = aItem.hasPermission(Permission.WRITE);
430              }
431              catch (PermissionDeniedException ex)
432              {}
433              %>
434              <tbl:row>
435                <tbl:cell column="annotation"><base:icon image="<%=icon%>" />&nbsp;<%=Base.getLinkedName(ID, at, at == null, true)%></tbl:cell>
436                <tbl:cell column="item"><%=Base.getLinkedName(ID, aItem, aItem == null, true)%><%=aItem != null ? " ["+aItem.getType()+"]" : ""%></tbl:cell>
437                <tbl:cell column="values">
438                  <%=values == null || values.size() == 0 ? 
439                    "<i>- no values -</i>" : Values.getString(values, ", ", true, formatter)%>
440                  <%
441                  if (writeInherited && aItem != null)
442                  {
443                    %>: <base:icon image="edit.png" 
444                      onclick="<%="editInheritedAnnotation('"+aItem.getType().name()+"', "+aItem.getId()+", "+at.getId()+")"%>" 
445                      tooltip="Modify the values of this annotation" />
446                    <%
447                  }
448                  %>
449                </tbl:cell>
450                <tbl:cell column="description"><%=description%></tbl:cell>
451              </tbl:row>
452              <%
453            }
454            %>
455            </tbl:rows>
456          </tbl:data>
457        </tbl:table>
458        <base:icon image="joust/annotation.gif" /> = Annotation,
459        <base:icon image="parameter.png" /> = Protocol parameter
460        <%
461      }
462      %>
463      </base:section>
464      <%
465    }
466    %>
467  </base:body>
468  </base:page>
469  <%
470}
471finally
472{
473  if (dc != null) dc.close();
474}
475
476%>
Note: See TracBrowser for help on using the repository browser.