1 | <%-- $Id: list_images.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 Johan Enell |
---|
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.Scan" |
---|
32 | import="net.sf.basedb.core.Image" |
---|
33 | import="net.sf.basedb.core.ItemQuery" |
---|
34 | import="net.sf.basedb.core.ItemResultIterator" |
---|
35 | import="net.sf.basedb.core.Permission" |
---|
36 | import="net.sf.basedb.core.PluginDefinition" |
---|
37 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
38 | import="net.sf.basedb.core.query.Restrictions" |
---|
39 | import="net.sf.basedb.core.query.Expressions" |
---|
40 | import="net.sf.basedb.core.query.Orders" |
---|
41 | import="net.sf.basedb.core.query.Hql" |
---|
42 | import="net.sf.basedb.core.plugin.GuiContext" |
---|
43 | import="net.sf.basedb.core.plugin.Plugin" |
---|
44 | import="net.sf.basedb.util.Enumeration" |
---|
45 | import="net.sf.basedb.clients.web.Base" |
---|
46 | import="net.sf.basedb.clients.web.ModeInfo" |
---|
47 | import="net.sf.basedb.clients.web.util.HTML" |
---|
48 | import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
---|
49 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
50 | import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer" |
---|
51 | import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil" |
---|
52 | import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
---|
53 | import="net.sf.basedb.util.Values" |
---|
54 | import="java.util.List" |
---|
55 | import="java.util.Map" |
---|
56 | %> |
---|
57 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
58 | <%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %> |
---|
59 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
60 | <%@ taglib prefix="p" uri="/WEB-INF/path.tld" %> |
---|
61 | <%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %> |
---|
62 | <%! |
---|
63 | private static final Item itemType = Item.IMAGE; |
---|
64 | private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST); |
---|
65 | %> |
---|
66 | <% |
---|
67 | final int scanId = Values.getInt(request.getParameter("scan_id")); |
---|
68 | final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType); |
---|
69 | final String ID = sc.getId(); |
---|
70 | final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null); |
---|
71 | |
---|
72 | final ModeInfo mode = ModeInfo.get(request.getParameter("mode")); |
---|
73 | final String callback = request.getParameter("callback"); |
---|
74 | final String title = mode.generateTitle("image", "images"); |
---|
75 | final DbControl dc = sc.newDbControl(); |
---|
76 | ItemResultIterator<Image> images = null; |
---|
77 | try |
---|
78 | { |
---|
79 | final Scan scan = Scan.getById(dc, scanId); |
---|
80 | final boolean createPermission = scan.hasPermission(Permission.WRITE); |
---|
81 | final boolean writePermission = createPermission; |
---|
82 | final boolean deletePermission = createPermission; |
---|
83 | |
---|
84 | final ItemQuery<Image> query = scan.getImages(); |
---|
85 | cc.configureQuery(query, true); |
---|
86 | |
---|
87 | Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext); |
---|
88 | try |
---|
89 | { |
---|
90 | images = query.iterate(dc); |
---|
91 | } |
---|
92 | catch (Throwable t) |
---|
93 | { |
---|
94 | cc.setMessage(t.getMessage()); |
---|
95 | } |
---|
96 | int numListed = 0; |
---|
97 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, scan); |
---|
98 | ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext); |
---|
99 | %> |
---|
100 | <base:page title="<%=title%>" type="<%=mode.getPageType()%>"> |
---|
101 | <base:head scripts="table.js,tabcontrol.js" styles="table.css,headertabcontrol.css,path.css"> |
---|
102 | <ext:scripts context="<%=jspContext%>" /> |
---|
103 | <ext:stylesheets context="<%=jspContext%>" /> |
---|
104 | <script language="JavaScript"> |
---|
105 | var submitPage = 'index.jsp'; |
---|
106 | var formId = 'images'; |
---|
107 | function newItem() |
---|
108 | { |
---|
109 | Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', 0, true, '&scan_id=<%=scanId%>'); |
---|
110 | // Main.openPopup('index.jsp?ID=<%=ID%>&cmd=NewItem&scan_id=<%=scanId%>', 'NewImage', 500, 340); |
---|
111 | } |
---|
112 | function editItem(itemId) |
---|
113 | { |
---|
114 | Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, true); |
---|
115 | // Main.openPopup('index.jsp?ID=<%=ID%>&cmd=EditItem&scan_id=<%=scanId%>&item_id='+itemId, 'EditImage', 500, 340); |
---|
116 | } |
---|
117 | function viewItem(itemId) |
---|
118 | { |
---|
119 | Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false); |
---|
120 | // location.href = 'index.jsp?ID=<%=ID%>&cmd=ViewItem&scan_id=<%=scanId%>&item_id='+itemId; |
---|
121 | } |
---|
122 | function itemOnClick(evt, itemId) |
---|
123 | { |
---|
124 | Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected); |
---|
125 | } |
---|
126 | function deleteItems() |
---|
127 | { |
---|
128 | var frm = document.forms[formId]; |
---|
129 | if (Forms.numChecked(frm) == 0) |
---|
130 | { |
---|
131 | alert('Please select at least one item in the list'); |
---|
132 | return; |
---|
133 | } |
---|
134 | frm.action = submitPage; |
---|
135 | frm.cmd.value = 'DeleteItems'; |
---|
136 | frm.submit(); |
---|
137 | } |
---|
138 | function restoreItems() |
---|
139 | { |
---|
140 | var frm = document.forms[formId]; |
---|
141 | if (Forms.numChecked(frm) == 0) |
---|
142 | { |
---|
143 | alert('Please select at least one item in the list'); |
---|
144 | return; |
---|
145 | } |
---|
146 | frm.action = submitPage; |
---|
147 | frm.cmd.value = 'RestoreItems'; |
---|
148 | frm.submit(); |
---|
149 | } |
---|
150 | function deleteItemPermanently(itemId) |
---|
151 | { |
---|
152 | Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', itemId); |
---|
153 | } |
---|
154 | function configureColumns() |
---|
155 | { |
---|
156 | Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>'); |
---|
157 | } |
---|
158 | function runPlugin(cmd) |
---|
159 | { |
---|
160 | Table.submitToPopup(formId, cmd, 540, 460); |
---|
161 | } |
---|
162 | function returnSelected() |
---|
163 | { |
---|
164 | Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>); |
---|
165 | window.close(); |
---|
166 | } |
---|
167 | function presetOnChange() |
---|
168 | { |
---|
169 | Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>'); |
---|
170 | } |
---|
171 | function switchTab(tabControlId, tabId) |
---|
172 | { |
---|
173 | if (tabId == 'properties' || tabId == 'annotations' || tabId == 'overview') |
---|
174 | { |
---|
175 | location.href = '../index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id=<%=scanId%>&tab='+tabId; |
---|
176 | } |
---|
177 | else |
---|
178 | { |
---|
179 | TabControl.setActiveTab(tabControlId, tabId); |
---|
180 | } |
---|
181 | } |
---|
182 | </script> |
---|
183 | </base:head> |
---|
184 | |
---|
185 | <base:body> |
---|
186 | <p> |
---|
187 | <p:path> |
---|
188 | <p:pathelement title="Scans" href="<%="../index.jsp?ID="+ID%>" /> |
---|
189 | <p:pathelement title="<%=HTML.encodeTags(scan.getName())%>" /> |
---|
190 | </p:path> |
---|
191 | |
---|
192 | <t:tabcontrol id="main" active="images" switch="switchTab"> |
---|
193 | <t:tab id="properties" title="Properties" /> |
---|
194 | <t:tab id="annotations" title="Annotations & parameters" |
---|
195 | tooltip="View annotation values and protocol parameters" /> |
---|
196 | |
---|
197 | <t:tab id="images" title="Images"> |
---|
198 | |
---|
199 | <% |
---|
200 | if (cc.getMessage() != null) |
---|
201 | { |
---|
202 | %> |
---|
203 | <div class="error"><%=cc.getMessage()%></div> |
---|
204 | <% |
---|
205 | cc.setMessage(null); |
---|
206 | } |
---|
207 | %> |
---|
208 | <tbl:table |
---|
209 | id="images" |
---|
210 | clazz="itemlist" |
---|
211 | columns="<%=cc.getSetting("columns")%>" |
---|
212 | sortby="<%=cc.getSortProperty()%>" |
---|
213 | direction="<%=cc.getSortDirection()%>" |
---|
214 | title="<%=title%>" |
---|
215 | action="index.jsp" |
---|
216 | sc="<%=sc%>" |
---|
217 | item="<%=itemType%>" |
---|
218 | > |
---|
219 | <tbl:hidden |
---|
220 | name="mode" |
---|
221 | value="<%=mode.getName()%>" |
---|
222 | /> |
---|
223 | <tbl:hidden |
---|
224 | name="scan_id" |
---|
225 | value="<%=String.valueOf(scanId)%>" |
---|
226 | /> |
---|
227 | <tbl:hidden |
---|
228 | name="callback" |
---|
229 | value="<%=callback%>" |
---|
230 | skip="<%=callback == null%>" |
---|
231 | /> |
---|
232 | <tbl:columndef |
---|
233 | id="name" |
---|
234 | property="name" |
---|
235 | datatype="string" |
---|
236 | title="Name" |
---|
237 | sortable="true" |
---|
238 | filterable="true" |
---|
239 | exportable="true" |
---|
240 | show="always" |
---|
241 | /> |
---|
242 | <tbl:columndef |
---|
243 | id="id" |
---|
244 | clazz="uniquecol" |
---|
245 | property="id" |
---|
246 | datatype="int" |
---|
247 | title="ID" |
---|
248 | sortable="true" |
---|
249 | filterable="true" |
---|
250 | exportable="true" |
---|
251 | /> |
---|
252 | <tbl:columndef |
---|
253 | id="file" |
---|
254 | property="file.name" |
---|
255 | datatype="string" |
---|
256 | title="File" |
---|
257 | sortable="true" |
---|
258 | filterable="true" |
---|
259 | exportable="true" |
---|
260 | /> |
---|
261 | <tbl:columndef |
---|
262 | id="preview" |
---|
263 | property="preview" |
---|
264 | datatype="boolean" |
---|
265 | title="Is preview" |
---|
266 | sortable="true" |
---|
267 | filterable="true" |
---|
268 | exportable="true" |
---|
269 | /> |
---|
270 | <% |
---|
271 | Enumeration<String, String> formats = new Enumeration<String, String>(); |
---|
272 | for (Image.Format f : Image.Format.values()) |
---|
273 | { |
---|
274 | formats.add(Integer.toString(f.getValue()), f.toString()); |
---|
275 | } |
---|
276 | %> |
---|
277 | <tbl:columndef |
---|
278 | id="format" |
---|
279 | property="format" |
---|
280 | datatype="int" |
---|
281 | enumeration="<%=formats%>" |
---|
282 | title="Format" |
---|
283 | sortable="true" |
---|
284 | filterable="true" |
---|
285 | exportable="true" |
---|
286 | /> |
---|
287 | <tbl:columndef |
---|
288 | id="description" |
---|
289 | property="description" |
---|
290 | datatype="string" |
---|
291 | title="Description" |
---|
292 | sortable="true" |
---|
293 | filterable="true" |
---|
294 | exportable="true" |
---|
295 | /> |
---|
296 | <tbl:toolbar |
---|
297 | visible="<%=mode.hasToolbar()%>" |
---|
298 | > |
---|
299 | <tbl:button |
---|
300 | disabled="<%=createPermission ? false : true%>" |
---|
301 | image="<%=createPermission ? "new.gif" : "new_disabled.gif"%>" |
---|
302 | onclick="newItem()" |
---|
303 | title="New…" |
---|
304 | tooltip="<%=createPermission ? "Create new image" : "You do not have permission to create images"%>" |
---|
305 | /> |
---|
306 | <tbl:button |
---|
307 | disabled="<%=deletePermission ? false : true%>" |
---|
308 | image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" |
---|
309 | title="Delete" |
---|
310 | onclick="deleteItems()" |
---|
311 | tooltip="<%=deletePermission ? "Delete the selected items" : "You do not have permission to delete images"%>" |
---|
312 | /> |
---|
313 | <tbl:button |
---|
314 | disabled="<%=writePermission ? false : true%>" |
---|
315 | image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" |
---|
316 | onclick="restoreItems()" |
---|
317 | title="Restore" |
---|
318 | tooltip="<%=writePermission ? "Restore the selected (deleted) items" : "You do not have permission to restore images"%>" |
---|
319 | /> |
---|
320 | <tbl:button |
---|
321 | image="columns.gif" |
---|
322 | onclick="configureColumns()" |
---|
323 | title="Columns…" |
---|
324 | tooltip="Show, hide and re-order columns" |
---|
325 | /> |
---|
326 | <tbl:button |
---|
327 | image="import.gif" |
---|
328 | onclick="runPlugin('ImportItems')" |
---|
329 | title="Import…" |
---|
330 | tooltip="Import data" |
---|
331 | visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>" |
---|
332 | /> |
---|
333 | <tbl:button |
---|
334 | image="export.gif" |
---|
335 | onclick="runPlugin('ExportItems')" |
---|
336 | title="Export…" |
---|
337 | tooltip="Export data" |
---|
338 | visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>" |
---|
339 | /> |
---|
340 | <tbl:button |
---|
341 | image="runplugin.gif" |
---|
342 | onclick="runPlugin('RunListPlugin')" |
---|
343 | title="Run plugin…" |
---|
344 | tooltip="Run a plugin" |
---|
345 | visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>" |
---|
346 | /> |
---|
347 | <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" |
---|
348 | wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/> |
---|
349 | </tbl:toolbar> |
---|
350 | <tbl:navigator |
---|
351 | page="<%=cc.getPage()%>" |
---|
352 | rowsperpage="<%=cc.getRowsPerPage()%>" |
---|
353 | totalrows="<%=images == null ? 0 : images.getTotalCount()%>" |
---|
354 | visible="<%=mode.hasNavigator()%>" |
---|
355 | /> |
---|
356 | <tbl:data> |
---|
357 | <tbl:columns> |
---|
358 | <tbl:presetselector |
---|
359 | clazz="columnheader" |
---|
360 | colspan="3" |
---|
361 | onchange="presetOnChange()" |
---|
362 | /> |
---|
363 | </tbl:columns> |
---|
364 | |
---|
365 | <tr> |
---|
366 | <tbl:header |
---|
367 | clazz="index" |
---|
368 | > </tbl:header> |
---|
369 | <tbl:header |
---|
370 | clazz="check" |
---|
371 | visible="<%=mode.hasCheck()%>" |
---|
372 | ><base:icon |
---|
373 | image="check_uncheck.gif" |
---|
374 | tooltip="Check/uncheck all" |
---|
375 | onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;" |
---|
376 | /></tbl:header> |
---|
377 | <tbl:header |
---|
378 | clazz="check" |
---|
379 | visible="<%=mode.hasRadio()%>" |
---|
380 | /> |
---|
381 | <tbl:header |
---|
382 | clazz="icons" |
---|
383 | visible="<%=mode.hasIcons()%>" |
---|
384 | > </tbl:header> |
---|
385 | <tbl:propertyfilter /> |
---|
386 | </tr> |
---|
387 | |
---|
388 | <tbl:rows> |
---|
389 | <% |
---|
390 | int index = cc.getPage()*cc.getRowsPerPage(); |
---|
391 | int selectedItemId = cc.getId(); |
---|
392 | if (images != null) |
---|
393 | { |
---|
394 | while (images.hasNext()) |
---|
395 | { |
---|
396 | Image item = images.next(); |
---|
397 | int itemId = item.getId(); |
---|
398 | String tooltip = mode.isSelectionMode() ? |
---|
399 | "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : ""); |
---|
400 | String deletePermanently = "deleteItemPermanently("+itemId+")"; |
---|
401 | String name = HTML.encodeTags(item.getName()); |
---|
402 | index++; |
---|
403 | numListed++; |
---|
404 | %> |
---|
405 | <tbl:row> |
---|
406 | <tbl:header |
---|
407 | clazz="index" |
---|
408 | ><%=index%></tbl:header> |
---|
409 | <tbl:header |
---|
410 | clazz="check" |
---|
411 | visible="<%=mode.hasCheck()%>" |
---|
412 | ><input |
---|
413 | type="checkbox" |
---|
414 | name="<%=itemId%>" |
---|
415 | value="<%=itemId%>" |
---|
416 | title="<%=name%>" |
---|
417 | <%=cc.getSelected().contains(itemId) ? "checked" : ""%> |
---|
418 | ></tbl:header> |
---|
419 | <tbl:header |
---|
420 | clazz="check" |
---|
421 | visible="<%=mode.hasRadio()%>" |
---|
422 | ><input |
---|
423 | type="radio" |
---|
424 | name="item_id" |
---|
425 | value="<%=itemId%>" |
---|
426 | title="<%=name%>" |
---|
427 | <%=selectedItemId == itemId ? "checked" : ""%> |
---|
428 | ></tbl:header> |
---|
429 | <tbl:header |
---|
430 | clazz="icons" |
---|
431 | visible="<%=mode.hasIcons()%>" |
---|
432 | ><base:icon |
---|
433 | image="<%=deletePermission ? "deleted.gif" : "deleted_disabled.gif"%>" |
---|
434 | onclick="<%=deletePermission ? deletePermanently : null%>" |
---|
435 | tooltip="This item has been scheduled for deletion" |
---|
436 | visible="<%=item.isRemoved()%>" |
---|
437 | /> </tbl:header> |
---|
438 | <tbl:cell column="name"><div class="link" |
---|
439 | onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" |
---|
440 | title="<%=tooltip%>"><%=name%></div></tbl:cell> |
---|
441 | <tbl:cell column="id"><%=item.getId()%></tbl:cell> |
---|
442 | <tbl:cell column="file" |
---|
443 | ><base:propertyvalue |
---|
444 | item="<%=item%>" |
---|
445 | property="file" |
---|
446 | enableEditLink="<%=mode.hasEditLink()%>" |
---|
447 | enablePropertyLink="<%=mode.hasPropertyLink()%>" |
---|
448 | /></tbl:cell> |
---|
449 | <tbl:cell column="preview"><%=item.isPreview()%></tbl:cell> |
---|
450 | <tbl:cell column="format"><%=item.getFormat()%></tbl:cell> |
---|
451 | <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell> |
---|
452 | </tbl:row> |
---|
453 | <% |
---|
454 | } |
---|
455 | } |
---|
456 | %> |
---|
457 | </tbl:rows> |
---|
458 | </tbl:data> |
---|
459 | <% |
---|
460 | if (numListed == 0) |
---|
461 | { |
---|
462 | %> |
---|
463 | <tbl:panel><%=images == null || images.getTotalCount() == 0 ? "No images were found" : "No images on this page. Please select another page!" %></tbl:panel> |
---|
464 | <% |
---|
465 | } |
---|
466 | else |
---|
467 | { |
---|
468 | %> |
---|
469 | <tbl:navigator |
---|
470 | page="<%=cc.getPage()%>" |
---|
471 | rowsperpage="<%=cc.getRowsPerPage()%>" |
---|
472 | totalrows="<%=images == null ? 0 : images.getTotalCount()%>" |
---|
473 | visible="<%=mode.hasNavigator()%>" |
---|
474 | locked="true" |
---|
475 | /> |
---|
476 | <% |
---|
477 | } |
---|
478 | %> |
---|
479 | </tbl:table> |
---|
480 | <base:buttongroup align="center"> |
---|
481 | <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" /> |
---|
482 | <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" /> |
---|
483 | <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" /> |
---|
484 | </base:buttongroup> |
---|
485 | |
---|
486 | </t:tab> |
---|
487 | <t:tab id="overview" title="Overview" |
---|
488 | tooltip="Display a tree overview of related items" /> |
---|
489 | </t:tabcontrol> |
---|
490 | |
---|
491 | |
---|
492 | </base:body> |
---|
493 | </base:page> |
---|
494 | <% |
---|
495 | } |
---|
496 | finally |
---|
497 | { |
---|
498 | if (images != null) images.close(); |
---|
499 | if (dc != null) dc.close(); |
---|
500 | } |
---|
501 | %> |
---|