1 | <%-- $Id: inherit.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 | This page is used to display and modify the attributes of |
---|
25 | the of a news item |
---|
26 | |
---|
27 | @author Nicklas |
---|
28 | @version 2.0 |
---|
29 | --%> |
---|
30 | <%@ page session="false" |
---|
31 | import="net.sf.basedb.core.SessionControl" |
---|
32 | import="net.sf.basedb.core.DbControl" |
---|
33 | import="net.sf.basedb.core.Item" |
---|
34 | import="net.sf.basedb.core.Type" |
---|
35 | import="net.sf.basedb.core.BasicItem" |
---|
36 | import="net.sf.basedb.core.Permission" |
---|
37 | import="net.sf.basedb.core.Annotatable" |
---|
38 | import="net.sf.basedb.core.AnnotationSet" |
---|
39 | import="net.sf.basedb.core.Annotation" |
---|
40 | import="net.sf.basedb.core.ItemQuery" |
---|
41 | import="net.sf.basedb.core.Include" |
---|
42 | import="net.sf.basedb.core.Nameable" |
---|
43 | import="net.sf.basedb.core.ItemResultList" |
---|
44 | import="net.sf.basedb.core.AnnotationType" |
---|
45 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
46 | import="net.sf.basedb.core.query.Orders" |
---|
47 | import="net.sf.basedb.core.query.Hql" |
---|
48 | import="net.sf.basedb.util.Tree" |
---|
49 | import="net.sf.basedb.clients.web.Base" |
---|
50 | import="net.sf.basedb.clients.web.WebException" |
---|
51 | import="net.sf.basedb.clients.web.util.HTML" |
---|
52 | import="net.sf.basedb.util.Values" |
---|
53 | import="net.sf.basedb.util.formatter.Formatter" |
---|
54 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
55 | import="java.util.List" |
---|
56 | import="java.util.Set" |
---|
57 | import="java.util.HashSet" |
---|
58 | import="java.util.Map" |
---|
59 | import="java.util.HashMap" |
---|
60 | %> |
---|
61 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
62 | <%! |
---|
63 | private void loadParents(Set<AnnotationSet> parentAnnotations, Set<Annotatable> parentItems, Annotatable item) |
---|
64 | { |
---|
65 | Set<Annotatable> parents = item.getAnnotatableParents(); |
---|
66 | if (parents == null) return; |
---|
67 | for (Annotatable parent : parents) |
---|
68 | { |
---|
69 | if (parent != null && parentItems.add(parent)) |
---|
70 | { |
---|
71 | if (parent.hasPermission(Permission.USE) && parent.isAnnotated()) |
---|
72 | { |
---|
73 | parentAnnotations.add(parent.getAnnotationSet()); |
---|
74 | } |
---|
75 | loadParents(parentAnnotations, parentItems, parent); |
---|
76 | } |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | private String generateJoustTree(Set<AnnotationSet> parentAnnotations, Set<Annotation> inheritedAnnotations, Set<AnnotationSet> inheritedSets) |
---|
81 | { |
---|
82 | StringBuilder sb = new StringBuilder(); |
---|
83 | String itemIcon = "Annotatable"; |
---|
84 | String annotationIcon = "Annotation"; |
---|
85 | String parameterIcon = "Parameter"; |
---|
86 | |
---|
87 | for (AnnotationSet as : parentAnnotations) |
---|
88 | { |
---|
89 | Annotatable item = null; |
---|
90 | try |
---|
91 | { |
---|
92 | item = as.getItem(); |
---|
93 | } |
---|
94 | catch (PermissionDeniedException ex) |
---|
95 | {} |
---|
96 | |
---|
97 | boolean setInherited = inheritedSets != null && inheritedSets.contains(as); |
---|
98 | |
---|
99 | String input = "<input type=\"checkbox\""+ |
---|
100 | " name=\"AS"+as.getId()+"\""+ |
---|
101 | (setInherited ? " checked" : "")+ |
---|
102 | " onclick=\"itemOnToggle(event, "+as.getId()+")\""+ |
---|
103 | ">"; |
---|
104 | String name = item == null ? "<i>- denied -</i>" : |
---|
105 | HTML.javaScriptEncode(((Nameable)item).getName()) + " (" + item.getType() + ")"; |
---|
106 | sb.append("var item").append(as.getId()); |
---|
107 | sb.append(" = JoustMenu.addMenuItem(-1"); |
---|
108 | sb.append(",'").append(itemIcon).append("'"); |
---|
109 | sb.append(",'").append(input).append(name).append("'"); |
---|
110 | sb.append(", 'itemOnClick(event, ").append(as.getId()).append(")'"); |
---|
111 | sb.append(", '', 'AS").append(as.getId()).append("', true);\n"); |
---|
112 | |
---|
113 | List<Annotation> annotations = as.getAnnotations().list(as.getDbControl()); |
---|
114 | SessionControl sc = as.getSessionControl(); |
---|
115 | for (Annotation a : annotations) |
---|
116 | { |
---|
117 | Formatter formatter = FormatterFactory.getTypeFormatter(sc, a.getValueType()); |
---|
118 | boolean inherited = inheritedAnnotations != null && inheritedAnnotations.contains(a); |
---|
119 | AnnotationType at = null; |
---|
120 | String annotationName = "<i>- denied -</i>"; |
---|
121 | boolean isParameter = false; |
---|
122 | try |
---|
123 | { |
---|
124 | at = a.getAnnotationType(); |
---|
125 | annotationName = at.getName(); |
---|
126 | isParameter = at.isProtocolParameter(); |
---|
127 | } |
---|
128 | catch (PermissionDeniedException ex) |
---|
129 | {} |
---|
130 | String values = Values.getString(a.getValues(), ", ", true, formatter); |
---|
131 | name = HTML.javaScriptEncode(annotationName + |
---|
132 | " [" + Values.trimString(values, 20)+"]"); |
---|
133 | input = "<input type=\"checkbox\""+ |
---|
134 | " name=\"A"+a.getId()+"\""+ |
---|
135 | (inherited || setInherited ? " checked" : "")+ |
---|
136 | (setInherited ? " disabled" : "")+ |
---|
137 | " onclick=\"annotationOnToggle(event, "+a.getId()+")\""+ |
---|
138 | ">"; |
---|
139 | sb.append("JoustMenu.addChildItem(item" + as.getId()); |
---|
140 | sb.append(",'").append(isParameter ? parameterIcon : annotationIcon).append("'"); |
---|
141 | sb.append(",'").append(input).append(name).append("'"); |
---|
142 | sb.append(", 'annotationOnClick(event, ").append(a.getId()).append(")'"); |
---|
143 | sb.append(", '', 'A").append(a.getId()).append("');\n"); |
---|
144 | sb.append("annotationValues['A").append(a.getId()).append("'] = "); |
---|
145 | sb.append("'").append(HTML.javaScriptEncode(values)).append("';\n"); |
---|
146 | } |
---|
147 | } |
---|
148 | return sb.toString(); |
---|
149 | } |
---|
150 | %> |
---|
151 | <% |
---|
152 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
153 | final String ID = sc.getId(); |
---|
154 | final float scale = Base.getScale(sc); |
---|
155 | final Item itemType = Item.valueOf(request.getParameter("item_type")); |
---|
156 | final int itemId = Values.getInt(request.getParameter("item_id")); |
---|
157 | |
---|
158 | final DbControl dc = sc.newDbControl(); |
---|
159 | ItemResultList<AnnotationType> annotationTypes = null; |
---|
160 | try |
---|
161 | { |
---|
162 | final Annotatable item = itemId == 0 ? null : (Annotatable)itemType.getById(dc, itemId); |
---|
163 | Set<AnnotationSet> parentAnnotations = new HashSet<AnnotationSet>(); |
---|
164 | Set<Annotatable> parentItems = new HashSet<Annotatable>(); |
---|
165 | |
---|
166 | if (item != null) |
---|
167 | { |
---|
168 | // Get all annotated parents and their annotation sets |
---|
169 | loadParents(parentAnnotations, parentItems, item); |
---|
170 | } |
---|
171 | |
---|
172 | // Parent items may have been submitted by caller |
---|
173 | String[] parents = request.getParameterValues("parents"); |
---|
174 | // Each parameter is ITEMTYPE:ID:ID:... |
---|
175 | if (parents != null) |
---|
176 | { |
---|
177 | for (String parent : parents) |
---|
178 | { |
---|
179 | String[] temp = parent.split(":"); |
---|
180 | Item parentType = Item.valueOf(temp[0]); |
---|
181 | for (int i = 1; i < temp.length; ++i) |
---|
182 | { |
---|
183 | int parentId = Values.getInt(temp[i], -1); |
---|
184 | if (parentId != -1) |
---|
185 | { |
---|
186 | Annotatable parentItem = (Annotatable)parentType.getById(dc, parentId); |
---|
187 | if (parentItems.add(parentItem)) |
---|
188 | { |
---|
189 | // This is a new parent |
---|
190 | if (parentItem.hasPermission(Permission.USE) && parentItem.isAnnotated()) |
---|
191 | { |
---|
192 | parentAnnotations.add(parentItem.getAnnotationSet()); |
---|
193 | } |
---|
194 | loadParents(parentAnnotations, parentItems, parentItem); |
---|
195 | } |
---|
196 | } |
---|
197 | } |
---|
198 | } |
---|
199 | } |
---|
200 | |
---|
201 | // Get the currently inherited annotations |
---|
202 | final AnnotationSet as = item != null && item.isAnnotated() ? item.getAnnotationSet() : null; |
---|
203 | Set<Annotation> inheritedAnnotations = null; |
---|
204 | Set<AnnotationSet> inheritedSets = null; |
---|
205 | if (as != null) |
---|
206 | { |
---|
207 | ItemQuery<Annotation> inheritedQuery = as.getInheritedAnnotations(); |
---|
208 | inheritedQuery.order(Orders.asc(Hql.property("annotationSet"))); |
---|
209 | inheritedQuery.order(Orders.asc(Hql.property("annotationType.name"))); |
---|
210 | inheritedAnnotations = new HashSet<Annotation>(inheritedQuery.list(dc)); |
---|
211 | for (Annotation a : inheritedAnnotations) |
---|
212 | { |
---|
213 | AnnotationSet from = a.getAnnotationSet(); |
---|
214 | if (!parentAnnotations.contains(from) && from.hasPermission(Permission.USE)) |
---|
215 | { |
---|
216 | parentAnnotations.add(from); |
---|
217 | } |
---|
218 | } |
---|
219 | |
---|
220 | ItemQuery<AnnotationSet> setQuery = as.getInheritedAnnotationSets(); |
---|
221 | inheritedSets = new HashSet<AnnotationSet>(setQuery.list(dc)); |
---|
222 | for (AnnotationSet ias : inheritedSets) |
---|
223 | { |
---|
224 | if (!parentAnnotations.contains(ias) && ias.hasPermission(Permission.USE)) |
---|
225 | { |
---|
226 | parentAnnotations.add(ias); |
---|
227 | } |
---|
228 | } |
---|
229 | } |
---|
230 | %> |
---|
231 | <base:page type="popup" title="Inherit annotations"> |
---|
232 | <base:head scripts="annotations.js,parameters.js,newjoust.js,linkitems.js" styles="parameters.css,newjoust.css"> |
---|
233 | <script language="JavaScript"> |
---|
234 | var annotationValues = new Array(); |
---|
235 | function init() |
---|
236 | { |
---|
237 | <% |
---|
238 | if (parentAnnotations.size() > 0) |
---|
239 | { |
---|
240 | %> |
---|
241 | IconStore.init(); |
---|
242 | var path = getRoot() + 'images/joust/'; |
---|
243 | IconStore.addIcon('Annotatable', path + 'annotatable.gif', 18, 16); |
---|
244 | IconStore.addIcon('Annotation', path + 'annotation.gif', 18, 16); |
---|
245 | IconStore.addIcon('Parameter', path + 'parameter.gif', 18, 16); |
---|
246 | <%=generateJoustTree(parentAnnotations, inheritedAnnotations, inheritedSets)%> |
---|
247 | JoustMenu.alwaysSendOnClickToSelected = true; |
---|
248 | JoustMenu.draw('joust'); |
---|
249 | <% |
---|
250 | } |
---|
251 | %> |
---|
252 | } |
---|
253 | function itemOnClick(event, annotationSetId) |
---|
254 | { |
---|
255 | var frm = document.forms['annotations']; |
---|
256 | frm['AS'+annotationSetId].checked = !frm['AS'+annotationSetId].checked; |
---|
257 | itemOnToggle(event, annotationSetId); |
---|
258 | } |
---|
259 | |
---|
260 | function itemOnToggle(event, annotationSetId) |
---|
261 | { |
---|
262 | //alert('itemOnClick: '+annotationSetId); |
---|
263 | var frm = document.forms['annotations']; |
---|
264 | |
---|
265 | var linkedItem = Link.getItem('AS', annotationSetId); |
---|
266 | if (!linkedItem) |
---|
267 | { |
---|
268 | linkedItem = new Item('AS', annotationSetId); |
---|
269 | } |
---|
270 | var checked = frm['AS'+annotationSetId].checked; |
---|
271 | linkedItem.action += checked ? 1 : -1; |
---|
272 | |
---|
273 | frm['AS'+annotationSetId].checked = checked; |
---|
274 | var menuItem = JoustMenu.menuItems['AS'+annotationSetId]; |
---|
275 | var childIndex = menuItem.firstChildIndex; |
---|
276 | while (childIndex != -1) |
---|
277 | { |
---|
278 | var childMenuItem = JoustMenu.menuItems[childIndex]; |
---|
279 | frm[childMenuItem.externalId].checked = checked; |
---|
280 | frm[childMenuItem.externalId].disabled = checked; |
---|
281 | childIndex = childMenuItem.nextItemIndex; |
---|
282 | |
---|
283 | var annotationId = childMenuItem.externalId.substr(1); |
---|
284 | annotationItem = Link.getItem('A', annotationId); |
---|
285 | if (!annotationItem) annotationItem = new Item('A', annotationId); |
---|
286 | annotationItem.action = -1; |
---|
287 | } |
---|
288 | event.cancelBubble = true; |
---|
289 | } |
---|
290 | |
---|
291 | function annotationOnClick(event, annotationId) |
---|
292 | { |
---|
293 | var frm = document.forms['annotations']; |
---|
294 | var annotation = frm['A'+annotationId]; |
---|
295 | if (!annotation.disabled) |
---|
296 | { |
---|
297 | annotation.checked = !annotation.checked; |
---|
298 | annotationOnToggle(event, annotationId); |
---|
299 | } |
---|
300 | document.getElementById('annotationValues').innerHTML = annotationValues['A'+annotationId]; |
---|
301 | } |
---|
302 | |
---|
303 | function annotationOnToggle(event, annotationId) |
---|
304 | { |
---|
305 | //alert('itemOnClick: '+annotationSetId); |
---|
306 | var frm = document.forms['annotations']; |
---|
307 | |
---|
308 | var linkedItem = Link.getItem('A', annotationId); |
---|
309 | if (!linkedItem) |
---|
310 | { |
---|
311 | linkedItem = new Item('A', annotationId); |
---|
312 | } |
---|
313 | var checked = frm['A'+annotationId].checked; |
---|
314 | linkedItem.action = checked ? 1 : -1; |
---|
315 | |
---|
316 | frm['A'+annotationId].checked = checked; |
---|
317 | event.cancelBubble = true; |
---|
318 | } |
---|
319 | |
---|
320 | </script> |
---|
321 | </base:head> |
---|
322 | <base:body onload="init()" style="background: #E0E0E0;"> |
---|
323 | |
---|
324 | <form name="annotations"> |
---|
325 | <table class="form" cellspacing="2" border="0" cellpadding="0" width="100%"> |
---|
326 | <tr valign="top"> |
---|
327 | <td width="50%"> |
---|
328 | <div id="joust" class="joust parameterlist" |
---|
329 | style="height: <%=(int)(scale*320)%>px;"> |
---|
330 | <% |
---|
331 | if (parentAnnotations.size() == 0) |
---|
332 | { |
---|
333 | %> |
---|
334 | <div class="error">There are no parent items with annotations.</div> |
---|
335 | <% |
---|
336 | } |
---|
337 | %> |
---|
338 | </div> |
---|
339 | <base:icon image="joust/annotation.gif" /> = Annotation |
---|
340 | <base:icon image="joust/parameter.gif" /> = Protocol parameter |
---|
341 | </td> |
---|
342 | <td width="50%"> |
---|
343 | <b>Annotation/parameter values</b> |
---|
344 | <div id="annotationValues"> |
---|
345 | </div> |
---|
346 | </td> |
---|
347 | </tr> |
---|
348 | </table> |
---|
349 | |
---|
350 | </form> |
---|
351 | </base:body> |
---|
352 | </base:page> |
---|
353 | <% |
---|
354 | } |
---|
355 | finally |
---|
356 | { |
---|
357 | if (dc != null) dc.close(); |
---|
358 | } |
---|
359 | %> |
---|
360 | |
---|