source: trunk/www/common/plugin/select_plugin.jsp @ 5372

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

Fixes #1462: Select plugin+configuration in a single list

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 8.5 KB
Line 
1<%-- $Id: select_plugin.jsp 5372 2010-06-24 12:28:06Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg
4  Copyright (C) 2007 Nicklas Nordborg
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.PluginDefinition"
31  import="net.sf.basedb.core.PluginConfiguration"
32  import="net.sf.basedb.core.PluginType"
33  import="net.sf.basedb.core.ItemQuery"
34  import="net.sf.basedb.core.ItemResultList"
35  import="net.sf.basedb.core.Include"
36  import="net.sf.basedb.core.Job"
37  import="net.sf.basedb.core.query.Hql"
38  import="net.sf.basedb.core.query.Expressions"
39  import="net.sf.basedb.core.query.Restrictions"
40  import="net.sf.basedb.core.query.Orders"
41  import="net.sf.basedb.core.plugin.GuiContext"
42  import="net.sf.basedb.core.plugin.Plugin"
43  import="net.sf.basedb.core.plugin.InteractivePlugin"
44  import="net.sf.basedb.core.plugin.AutoDetectingImporter"
45  import="net.sf.basedb.clients.web.Base"
46  import="net.sf.basedb.util.Values"
47  import="net.sf.basedb.util.ContextUtil"
48  import="net.sf.basedb.util.ContextUtil.ContextResult"
49  import="net.sf.basedb.clients.web.util.HTML"
50  import="java.util.Set"
51  import="java.util.Map"
52  import="java.util.List"
53%>
54<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
55<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
56
57<%
58final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
59final String ID = sc.getId();
60final Item itemType = Item.valueOf(request.getParameter("item_type"));
61final String subContext = Values.getString(request.getParameter("subcontext"), "");
62final GuiContext.Type contextType = GuiContext.Type.valueOf(request.getParameter("context_type"));
63final Plugin.MainType mainType = Plugin.MainType.valueOf(request.getParameter("main_type"));
64final GuiContext context = new GuiContext(itemType, contextType);
65final String title = request.getParameter("title");
66final String message = request.getParameter("message");
67final DbControl dc = sc.newDbControl();
68final float scale = Base.getScale(sc);
69final boolean anotherIsOpen = sc.getSessionSetting("plugin.configure.plugin") != null;
70
71try
72{
73  List<ContextResult> contextResults = (List<ContextResult>)sc.getSessionSetting("PLUGINS");
74  Set<String> messages = (Set<String>)sc.getSessionSetting("MESSAGES");
75  StringBuilder descriptions = new StringBuilder();
76  %>
77  <base:page type="popup" title="<%=title%>">
78  <base:head scripts="plugin.js">
79    <script language="JavaScript">
80    function doNext()
81    {
82      var frm = document.forms['plugin'];
83      var anotherIsOpen = <%=anotherIsOpen%>;
84      if (anotherIsOpen)
85      {
86        if (!confirm('Are you sure? Unsaved settings in the other wizard will be lost.')) return;
87        frm.warnIfOpen.value = '0';
88      }
89      frm.submit();
90    }
91   
92    var lastSelectedPlugin;
93    var lastSelectedConfig;
94    function pluginOnChange()
95    {
96      var frm = document.forms['plugin'];
97      var pluginList = frm.plugins;
98      var plugin = pluginList[pluginList.selectedIndex].plugin;
99      var config = pluginList[pluginList.selectedIndex].configuration;
100
101      if (lastSelectedPlugin)
102      {
103        Main.hide('description.'+lastSelectedPlugin.id);
104      }
105      if (lastSelectedConfig)
106      {
107        Main.hide('description.config.'+lastSelectedConfig.id);
108      }
109      if (plugin)
110      {
111        Main.show('description.'+plugin.id);
112        frm.plugindefinition_id.value = plugin.id;
113        frm.pluginconfiguration_id.value = 0;
114      }
115      if (config)
116      {
117        Main.show('description.config.'+config.id);
118        frm.pluginconfiguration_id.value = config.id;
119      }
120      lastSelectedConfig = config;
121      lastSelectedPlugin = plugin;
122    }
123   
124    function init()
125    {
126      var frm = document.forms['plugin'];
127      var pluginList = frm.plugins;
128      <%
129      PluginDefinition lastPlugin = null;
130      for (ContextResult result : contextResults)
131      {
132        if (result.isInContext())
133        {
134          PluginDefinition pd = result.getPluginDefinition();
135          if (!pd.equals(lastPlugin))
136          {
137            lastPlugin = pd;
138            dc.reattachItem(pd, false);
139            String supportsConfig = pd.supportsConfigurations() ? "true" : "false";
140            String requiresConfig = pd.requiresConfiguration() ? "true" : "false";
141            descriptions.append("<div id=\"description." + pd.getId() +"\" style=\"display: none;\">");
142            descriptions.append(HTML.niceFormat("<b>" + pd.getName() + "</b>\n" + Values.getString(pd.getDescription())));
143            descriptions.append("</div>");
144            %>
145            var thePlugin = new Plugin(<%=pd.getId()%>, '<%=HTML.javaScriptEncode(pd.getName())%>', false, <%=supportsConfig%>, <%=requiresConfig%>);
146            <%
147          }
148          PluginConfiguration pc = result.getPluginConfiguration();
149          if (pc != null)
150          {
151            descriptions.append("<div id=\"description.config." + pc.getId() + "\" style=\"display: none; padding-top: 6px;\">");
152            descriptions.append(HTML.niceFormat("<b>" + pc.getName() + "</b>\n" +Values.getString(pc.getDescription())));           
153            descriptions.append("</div>");
154            %>
155            thePlugin.addConfiguration(<%=pc.getId()%>, '<%=HTML.javaScriptEncode(pc.getName())%>');
156            <%
157          }
158        }
159      }
160      %>
161      Plugins.populateLists(pluginList);
162      pluginOnChange();
163    }
164    </script>
165  </base:head>
166  <base:body onload="init()">
167    <form name="plugin" action="index.jsp" method="post" onsubmit="return false;">
168    <input type="hidden" name="ID" value="<%=ID%>">
169    <input type="hidden" name="cmd" value="NewJob">
170    <input type="hidden" name="item_type" value="<%=itemType.name()%>">
171    <input type="hidden" name="subcontext" value="<%=subContext%>">
172    <input type="hidden" name="context_type" value="<%=contextType.name()%>">
173    <input type="hidden" name="main_type" value="<%=mainType.name()%>">
174    <input type="hidden" name="title" value="<%=title%>">
175    <input type="hidden" name="warnIfOpen" value="1">
176    <input type="hidden" name="plugindefinition_id" value="">
177    <input type="hidden" name="pluginconfiguration_id" value="">
178
179    <h3 class="docked"><%=title%> <base:help helpid="runplugin.selectplugin" /></h3>
180    <div class="boxed" style="height: <%=(int)(scale*420)%>px; overflow: auto;">
181      <div class="helpmessage">
182      <%
183      if (message != null)
184      {
185        %>
186        <%=message%>
187        <%
188      }
189      else
190      {
191        %>
192        Please select the plugin and, optionally, the configuration to use.
193        <%
194      }
195      %>
196      </div>
197   
198      <table class="form" width="100%">
199      <tr valign="top">
200        <td class="prompt">Plugin + configuration</td>
201        <td>
202          <select name="plugins" class="required" onchange="pluginOnChange()">
203          </select>
204        </td>
205      </tr>
206      <%
207      if (messages != null && messages.size() > 0)
208      {
209        %>
210        <tr>
211          <td class="prompt">&nbsp;</td>
212          <td>
213            <base:icon image="bullet.gif" />
214            <a href="javascript:Main.showHide('pluginMessages')" 
215              title="Show/hide the messages from the plugins that couldn't be used">
216            Some plugins couldn't be used
217            </a>
218            <div id="pluginMessages" style="display: none;">
219            <ul>
220            <li><%=Values.getString(messages, "<li>", true)%>
221            </ul>
222            </div>
223          </td>
224        </tr>
225        <%
226      }
227      %>
228      </table>
229      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
230      <div id="descriptions" class="helpmessage" 
231        style="height: <%=(int)(scale*270)%>px; overflow: auto;">
232      <%=descriptions.toString()%>
233      </div>
234    </div>
235    </form>
236 
237    <%
238    if (anotherIsOpen)
239    {
240      %>
241      <div class="error">
242        Another plug-in configuration wizard is open, or it hasn't properly
243        clean up after itself.<br>
244        If you continue unsaved settings in the other wizard is lost.
245      </div>
246      <%
247    }
248    %>
249    <table align="center">
250    <tr>
251      <td width="50%"><base:button onclick="doNext();" title="Next" /></td>
252      <td width="50%"><base:button onclick="window.close();" title="Cancel" /></td>
253    </tr>
254    </table>
255  </base:body>
256  </base:page>
257  <%
258}
259finally
260{
261  if (dc != null) dc.close();
262}
263%>
264
Note: See TracBrowser for help on using the repository browser.