source: trunk/www/admin/pluginconfigurations/view_configuration.jsp @ 5040

Last change on this file since 5040 was 5040, checked in by Martin Svensson, 14 years ago

References #360 Updating rest of the view pages in BASE, starting with plug-in related.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 18.0 KB
Line 
1<%-- $Id: view_configuration.jsp 5040 2009-08-10 14:31:20Z martin $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Hkkinen, Nicklas Nordborg, Martin Svensson
4  Copyright (C) 2007 Martin Svensson
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.SystemItems"
30  import="net.sf.basedb.core.Group"
31  import="net.sf.basedb.core.Item"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.ItemResultIterator"
34  import="net.sf.basedb.core.Permission"
35  import="net.sf.basedb.core.PluginDefinition"
36  import="net.sf.basedb.core.PluginConfiguration"
37  import="net.sf.basedb.core.ParameterInfo"
38  import="net.sf.basedb.core.User"
39  import="net.sf.basedb.core.BasicItem"
40  import="net.sf.basedb.core.File"
41  import="net.sf.basedb.core.MultiPermissions"
42  import="net.sf.basedb.core.Nameable"
43  import="net.sf.basedb.core.PermissionDeniedException"
44  import="net.sf.basedb.core.PluginDefinition"
45  import="net.sf.basedb.core.plugin.GuiContext"
46  import="net.sf.basedb.core.plugin.Plugin"
47  import="net.sf.basedb.core.Project"
48  import="net.sf.basedb.util.JarClassLoader"
49  import="net.sf.basedb.util.ToStringComparator"
50  import="net.sf.basedb.clients.web.Base"
51  import="net.sf.basedb.clients.web.PermissionUtil"
52  import="net.sf.basedb.clients.web.util.HTML"
53  import="net.sf.basedb.util.Values"
54  import="net.sf.basedb.clients.web.util.NameablePluginAdaptor"
55  import="net.sf.basedb.util.formatter.Formatter"
56  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
57  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
58  import="net.sf.basedb.clients.web.extensions.JspContext"
59  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
60  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
61  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
62  import="java.util.Map"
63  import="java.util.Set"
64  import="java.util.TreeSet"
65  import="java.util.List"
66  import="java.util.Collections"
67  import="java.util.Date"
68%>
69<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
70<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
71<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
72<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
73<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
74<%!
75  private static final Item itemType = Item.PLUGINCONFIGURATION;
76  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
77%>
78<%
79final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
80final String ID = sc.getId();
81final String root = request.getContextPath() + "/";
82final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
83final int itemId = cc.getId();
84final float scale = Base.getScale(sc);
85final DbControl dc = sc.newDbControl();
86try
87{
88  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
89  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
90
91  String title = null;
92  PluginConfiguration configuration = PluginConfiguration.getById(dc, itemId);
93 
94  final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
95  final boolean writePermission = configuration.hasPermission(Permission.WRITE);
96  final boolean deletePermission = configuration.hasPermission(Permission.DELETE);
97  final boolean sharePermission = configuration.hasPermission(Permission.SET_PERMISSION);
98  final boolean setOwnerPermission = configuration.hasPermission(Permission.SET_OWNER);
99  final boolean isRemoved = configuration.isRemoved();
100  final boolean isUsed = isRemoved && configuration.isUsed();
101  final boolean deletePermanentlyPermission = deletePermission && !isUsed;
102  final boolean isOwner = configuration.isOwner();
103
104  final Set<GuiContext> contexts = new TreeSet<GuiContext>(new ToStringComparator<GuiContext>(false));
105  PluginDefinition plugin = null;
106  Nameable nameableProxy = null;
107  boolean readPlugin = true;
108  boolean configurable = false;
109  try
110  {
111    plugin = configuration.getPluginDefinition();
112    nameableProxy = new NameablePluginAdaptor(plugin);
113    contexts.addAll(plugin.getGuiContexts());
114    configurable = plugin.isInteractive() && plugin.supportsConfigurations();
115  }
116  catch (PermissionDeniedException ex)
117  {
118    readPlugin = false;
119  }
120  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, configuration);
121  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
122  %>
123  <base:page title="<%=title%>">
124  <base:head scripts="table.js,tabcontrol.js" styles="table.css,toolbar.css,headertabcontrol.css,path.css">
125    <ext:scripts context="<%=jspContext%>" />
126    <ext:stylesheets context="<%=jspContext%>" />
127    <script language="JavaScript">
128    function editItem()
129    {
130      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
131    }
132    function copyItem()
133    {
134      Main.copyItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
135    }
136    function shareItem()
137    {
138      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id=<%=itemId%>', 'ShareConfiguration', 600, 400);
139    }
140    function deleteItem()
141    {
142      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>');
143    }
144    function restoreItem()
145    {
146      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
147    }
148    function deleteItemPermanently()
149    {
150      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', <%=itemId%>, '&callback=itemDeleted');
151    }
152    function itemDeleted()
153    {
154      Main.listItems('<%=ID%>', '<%=itemType.name()%>');
155    }
156    function showUsingItems()
157    {
158      Main.showUsingItems('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
159    }
160    function setOwner()
161    {
162      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=SetOwnerOfItem&item_id=<%=itemId%>', 'SetOwnerOfItem', 450, 150);
163    }
164    function runPlugin(cmd)
165    {
166      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>', 'RunPlugin'+cmd, 740, 540);
167    }
168    function configure()
169    {
170      Main.openPopup('../../common/plugin/index.jsp?ID=<%=ID%>&cmd=ConfigurePlugin&pluginconfiguration_id=<%=itemId%>', 'ConfigurePlugin', 800, 600);
171    }
172    </script>
173  </base:head>
174  <base:body>
175    <p>
176    <p:path>
177      <p:pathelement title="Plugin configurations" href="<%="index.jsp?ID="+ID%>" />
178      <p:pathelement title="<%=HTML.encodeTags(configuration.getName())%>" />
179    </p:path>
180   
181    <t:tabcontrol id="main" active="properties">
182    <t:tab id="properties" title="Properties">
183    <tbl:toolbar
184      >
185      <tbl:button 
186        disabled="<%=writePermission ? false : true%>" 
187        image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" 
188        onclick="editItem()" 
189        title="Edit&hellip;" 
190        tooltip="<%=writePermission ? "Edit this plugin configuration" : "You do not have permission to edit this plugin configuration"%>" 
191      />
192      <tbl:button 
193        disabled="<%=!createPermission%>" 
194        image="<%=createPermission ? "copy.gif" : "copy_disabled.gif"%>"
195        onclick="copyItem()" 
196        title="Copy&hellip;" 
197        tooltip="<%=createPermission ? "Create a copy of this configuration" : "You do not have permission to create new configurations"%>"
198      />
199      <tbl:button 
200        disabled="<%=deletePermission ? false : true%>" 
201        image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
202        onclick="deleteItem()" 
203        title="Delete"
204        visible="<%=!configuration.isRemoved()%>"
205        tooltip="<%=deletePermission ? "Delete this plugin configuration" : "You do not have permission to delete this plugin configuration"%>" 
206      />
207      <tbl:button 
208        disabled="<%=writePermission ? false : true%>" 
209        image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" 
210        onclick="restoreItem()" 
211        title="Restore"
212        visible="<%=configuration.isRemoved()%>"
213        tooltip="<%=writePermission ? "Restore this plugin configuration" : "You do not have permission to restore this plugin configuration"%>" 
214      />
215      <tbl:button 
216        disabled="<%=sharePermission ? false : true%>"
217        image="<%=sharePermission ? "share.gif" : "share_disabled.gif"%>"
218        onclick="shareItem()" 
219        title="Share&hellip;" 
220        tooltip="<%=sharePermission ? "Share this plugin configuration to other user, groups and projects" : "You do not have permission to share this plugin configuration"%>"
221      />
222      <tbl:button 
223        disabled="<%=setOwnerPermission ? false : true%>"
224        image="<%=setOwnerPermission ? "take_ownership.png" : "take_ownership_disabled.png"%>"
225        onclick="setOwner()" 
226        title="Set owner&hellip;"
227        tooltip="<%=setOwnerPermission ? "Change owner of this item" : "You do not have permission to change ownership of this item"%>"
228      />
229      <tbl:button 
230        image="import.gif" 
231        onclick="runPlugin('ImportItem')" 
232        title="Import&hellip;" 
233        tooltip="Import data" 
234        visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
235      />
236      <tbl:button 
237        image="export.gif" 
238        onclick="runPlugin('ExportItem')" 
239        title="Export&hellip;" 
240        tooltip="Export data" 
241        visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
242      />
243      <tbl:button 
244        image="runplugin.gif" 
245        onclick="runPlugin('RunPlugin')" 
246        title="Run plugin&hellip;" 
247        tooltip="Run a plugin" 
248        visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
249      />
250      <tbl:button
251        image="runplugin.gif"
252        onclick="configure()"
253        title="Configure&hellip;"
254        tooltip="Configure this plugin"
255        visible="<%=configurable && writePermission%>"
256      />
257      <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
258        wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
259      <tbl:button
260        image="help.gif"
261        onclick="<%="Main.openHelp('" + ID +"', 'pluginconfiguration.view.properties')"%>"
262        title="Help&hellip;"
263        tooltip="Get help about this page"
264      />
265      </tbl:toolbar>
266    <div class="boxedbottom">
267      <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(configuration)%></i></div>
268      <%
269      if (configuration.isRemoved() || configuration.isShared())
270      {
271        %>
272        <div class="itemstatus">
273          <base:icon 
274            image="<%=deletePermanentlyPermission ? "deleted.gif" : "deleted_disabled.gif"%>"
275            onclick="<%=deletePermanentlyPermission ? "deleteItemPermanently()" : null%>"
276            tooltip="<%=deletePermanentlyPermission ? "Permanently delete this item" : null%>"
277            visible="<%=isRemoved%>"> This item has been flagged for deletion<br></base:icon>
278          <base:icon image="used.gif" 
279            onclick="showUsingItems()"
280            tooltip="Show the items that are using this one"
281            visible="<%=isUsed%>"> This item is used by other items and can't be permanently deleted<br></base:icon>
282          <base:icon image="shared.gif" 
283            visible="<%=configuration.isShared()%>"> This item is shared to other users, groups and/or projects</base:icon>
284        </div>
285        <%
286      }
287      %>
288      <table class="form" cellspacing="0">
289      <tr>
290        <td class="prompt">Name</td>
291        <td><%=HTML.encodeTags(configuration.getName())%></td>
292      </tr>
293      <tr>
294        <td class="prompt">Registered</td>
295        <td><%=dateFormatter.format(configuration.getEntryDate())%></td>
296      </tr>
297      <tr>
298        <td class="prompt">Plugin</td>
299        <td>
300          <%=Base.getLinkedName(ID, nameableProxy, plugin == null, true)%>
301        </td>
302      </tr>
303      <tr>
304        <td class="prompt">Type</td>
305        <td><%=plugin == null ? "<i>- denied -</i>" : plugin.getMainType().toString()%></td>
306      </tr>
307      <tr>
308        <td class="prompt">Owner</td>
309        <td><base:propertyvalue item="<%=configuration%>" property="owner" /></td>
310      </tr>
311      <tr valign="top">
312        <td class="prompt">Description</td>
313        <td><%=HTML.niceFormat(configuration.getDescription())%></td>
314      </tr>
315      </table>
316   
317      <%   
318      // Tables with users/groups/projects that this item is shared to
319      MultiPermissions mp = new MultiPermissions(Collections.singleton(configuration));
320      List<User> users = mp.getUsers().list(dc);
321      List<Group> groups = mp.getGroups().list(dc);
322      List<Project> projects = mp.getProjects().list(dc);
323      int totalShare = users.size() + groups.size() + projects.size();
324     
325      if (totalShare > 0)
326      {
327        %>
328        <base:section
329          id="sharedTo"
330          title="<%="Shared to (" + totalShare + ")"%>"
331          context="<%=cc%>"
332          >
333          <tbl:table 
334            id="itemsSharedTo"
335            clazz="itemlist"
336            columns="all"
337          >
338            <tbl:columndef 
339              id="itemType"
340              title="Item type"
341            />
342            <tbl:columndef 
343              id="name"
344              title="Name"
345            />
346            <tbl:columndef 
347              id="permissions"
348              title="Permissions"
349            />
350            <tbl:data>
351              <tbl:columns>
352              </tbl:columns>
353              <tbl:rows>
354              <%
355              for (Project project : projects)
356              {             
357                Set<Permission> permissions = mp.getPermissions(project).values().iterator().next();
358                %>     
359                <tbl:row>
360                  <tbl:cell column="itemType"><%=project.getType()%></tbl:cell>
361                  <tbl:cell column="name"><base:icon 
362                    image="deleted.gif" 
363                    tooltip="This item has been scheduled for deletion" 
364                    visible="<%=project.isRemoved()%>"
365                  /><%=Base.getLinkedName(ID, project, false, true)%></tbl:cell>
366                  <tbl:cell column="permissions">
367                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
368                  </tbl:cell>
369                </tbl:row>
370                <%
371              }
372              for (Group group : groups)
373              {
374                Set<Permission> permissions = mp.getPermissions(group).values().iterator().next();
375                %>
376                <tbl:row>             
377                  <tbl:cell column="itemType"><%=group.getType()%></tbl:cell>
378                  <tbl:cell column="name"><base:icon 
379                    image="deleted.gif" 
380                    tooltip="This item has been scheduled for deletion" 
381                    visible="<%=group.isRemoved()%>"
382                  /><%=Base.getLinkedName(ID, group, false, true)%></tbl:cell>
383                  <tbl:cell column="permissions">
384                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
385                  </tbl:cell>
386                </tbl:row>
387                <% 
388              }
389              for (User user : users)
390              {               
391                Set<Permission> permissions = mp.getPermissions(user).values().iterator().next();
392                %>
393                <tbl:row>             
394                  <tbl:cell column="itemType"><%=user.getType()%></tbl:cell>
395                  <tbl:cell column="name"><base:icon 
396                    image="deleted.gif" 
397                    tooltip="This item has been scheduled for deletion" 
398                    visible="<%=user.isRemoved()%>"
399                  /><%=Base.getLinkedName(ID, user, false, true)%></tbl:cell>
400                  <tbl:cell column="permissions">
401                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
402                  </tbl:cell>
403                </tbl:row>
404                <%
405              }
406              %>
407              </tbl:rows>
408            </tbl:data>
409          </tbl:table>
410        </base:section>
411        <%
412      }
413      else
414      {
415        %>
416        <h4>Shared to</h4>
417        This configuration is not shared
418        (or, you don't have permission to view the ones it is shared to).
419        <%
420      }
421      %>
422    </div>
423
424      </t:tab>
425     
426      <t:tab id="parameters" title="Configuration parameters" >
427      <div class="boxed">
428      <table class="form" cellspacing="0">
429      <%
430      if (plugin != null)
431      {
432        List<String> names = new java.util.ArrayList<String>(configuration.getParameterNames());
433        if (names == null || names.size() == 0)
434        {
435          %>
436          No parameters has been specified.
437          <%
438        }
439        else
440        {
441          Collections.sort(names);
442          for (String name : names)
443          {
444            StringBuilder sb = new StringBuilder();
445            String displayValue = "";
446            String description = "";
447            try
448            {
449              ParameterInfo pi = configuration.getParameterInfo(name);
450              if (pi.getLabel() != null) name = HTML.encodeTags(pi.getLabel());
451              description = HTML.encodeTags(pi.getDescription());
452              List<?> values = pi.getValues();
453              int i = 0;
454              for (Object value : values)
455              {
456                if (value != null)
457                {
458                  if (i > 0) sb.append(", ");
459                  i++;
460                  if (value instanceof BasicItem)
461                  {
462                    BasicItem item = (BasicItem)value;
463                    String itemName = "";
464                    if (item instanceof File)
465                    {
466                      sb.append(Base.getLinkedFile(ID, (File)item, false, true, true, root));
467                    }
468                    else 
469                    {
470                      if (item instanceof Nameable)
471                      {
472                        itemName = ((Nameable)item).getName();
473                      }
474                      else
475                      {
476                        itemName = item.toString();
477                      }
478                      sb.append(Base.getLink(ID, HTML.encodeTags(itemName), 
479                        item.getType(), item.getId(), item.hasPermission(Permission.WRITE)));
480                    }
481                  }
482                  else if (value instanceof Date)
483                  {
484                    sb.append(dateFormatter.format((Date)value));
485                  }
486                  else
487                  {
488                    sb.append(HTML.encodeTags(value.toString()));
489                  }
490                }
491              }
492              displayValue = sb.toString();
493            }
494            catch (Throwable ex)
495            {
496              displayValue = "<i>ERROR: "+ex.getMessage()+"</i>";
497            }
498            %>
499            <tr>
500              <td class="prompt"><span title="<%=description%>"><%=name%></span></td>
501              <td>
502                <%=displayValue%>
503              </td>
504            </tr>
505            <%
506          }
507        }
508      }
509      %>
510      </table>
511      </div>
512      </t:tab>
513     
514      <t:tab id="annotations" title="Annotations" 
515        tooltip="View annotation values" 
516        visible="<%=plugin != null && plugin.supports("net.sf.basedb.core.plugin.AnnotationSetterPlugin") %>">
517        <div class="boxed">
518        <jsp:include page="../../common/annotations/list_annotations.jsp">
519          <jsp:param name="item_type" value="<%=itemType.name()%>" />
520          <jsp:param name="item_id" value="<%=itemId%>" />
521          <jsp:param name="ID" value="<%=ID%>" />
522        </jsp:include>
523        </div>
524      </t:tab>
525     
526      </t:tabcontrol>
527
528  </base:body>
529  </base:page>
530  <%
531}
532finally
533{
534  if (dc != null) dc.close();
535}
536
537%>
Note: See TracBrowser for help on using the repository browser.