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

Last change on this file since 5060 was 5060, checked in by Nicklas Nordborg, 13 years ago

References #108: Logging the change history of an item

  • Documented the change made in [5058]
  • Changed calls to DbControl?.reattachItem() from all core code and jsp scripts
  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 9.2 KB
Line 
1<%-- $Id: select_plugin.jsp 5060 2009-08-19 07:02:11Z 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    function pluginOnChange()
94    {
95      var frm = document.forms['plugin'];
96      var pluginList = frm.plugindefinition_id;
97      var configurationList = frm.pluginconfiguration_id;
98      var plugin = pluginList[pluginList.selectedIndex].plugin;
99      Plugins.updateConfigurationsList(plugin, configurationList);
100      if (configurationList.length == 0)
101      {
102        Main.hide('configurations');
103      }
104      else
105      {
106        Main.show('configurations');
107      }
108      if (lastSelectedPlugin)
109      {
110        Main.hide('description.'+lastSelectedPlugin.id);
111      }
112      else
113      {
114        Main.show('descriptions');
115      }
116      if (lastSelectedConfig)
117      {
118        Main.hide('description.config.'+lastSelectedConfig.id);
119      }
120      Main.show('description.'+plugin.id);
121      lastSelectedPlugin = plugin;
122      lastSelectedConfig = null;
123      configOnChange();
124    }
125   
126    var lastSelectedConfig;
127    function configOnChange()
128    {
129      var frm = document.forms['plugin'];
130      var configurationList = frm.pluginconfiguration_id;
131      if (configurationList.selectedIndex < 0) return; 
132      var config = configurationList[configurationList.selectedIndex].configuration;
133      if (lastSelectedConfig)
134      {
135        Main.hide('description.config.'+lastSelectedConfig.id);
136      }
137      else
138      {
139        Main.show('descriptions');
140      }
141      if (config)
142      {
143        Main.show('description.config.'+config.id);
144      }
145      else
146      {
147        Main.hide('descriptions');
148      }
149      lastSelectedConfig = config;
150    }
151   
152    function init()
153    {
154      var frm = document.forms['plugin'];
155      var pluginList = frm.plugindefinition_id;
156      var configurationList = frm.pluginconfiguration_id;
157      <%
158      PluginDefinition lastPlugin = null;
159      for (ContextResult result : contextResults)
160      {
161        if (result.isInContext())
162        {
163          PluginDefinition pd = result.getPluginDefinition();
164          if (!pd.equals(lastPlugin))
165          {
166            lastPlugin = pd;
167            dc.reattachItem(pd, false);
168            String supportsConfig = pd.supportsConfigurations() ? "true" : "false";
169            String requiresConfig = pd.requiresConfiguration() ? "true" : "false";
170            descriptions.append("<div id=\"description." + pd.getId() +"\" style=\"display: none;\">");
171            descriptions.append(HTML.niceFormat("<b>" + pd.getName() + "</b>\n" + Values.getString(pd.getDescription())));
172            descriptions.append("</div>");
173            %>
174            var thePlugin = new Plugin(<%=pd.getId()%>, '<%=HTML.javaScriptEncode(pd.getName())%>', false, <%=supportsConfig%>, <%=requiresConfig%>);
175            <%
176          }
177          PluginConfiguration pc = result.getPluginConfiguration();
178          if (pc != null)
179          {
180            descriptions.append("<div id=\"description.config." + pc.getId() + "\" style=\"display: none; padding-top: 6px;\">");
181            descriptions.append(HTML.niceFormat("<b>" + pc.getName() + "</b>\n" +Values.getString(pc.getDescription())));           
182            descriptions.append("</div>");
183            %>
184            thePlugin.addConfiguration(<%=pc.getId()%>, '<%=HTML.javaScriptEncode(pc.getName())%>');
185            <%
186          }
187        }
188      }
189      %>
190      Plugins.populateLists(pluginList, configurationList);
191      pluginOnChange();
192    }
193    </script>
194  </base:head>
195  <base:body onload="init()">
196    <form name="plugin" action="index.jsp" method="post" onsubmit="return false;">
197    <input type="hidden" name="ID" value="<%=ID%>">
198    <input type="hidden" name="cmd" value="NewJob">
199    <input type="hidden" name="item_type" value="<%=itemType.name()%>">
200    <input type="hidden" name="subcontext" value="<%=subContext%>">
201    <input type="hidden" name="context_type" value="<%=contextType.name()%>">
202    <input type="hidden" name="main_type" value="<%=mainType.name()%>">
203    <input type="hidden" name="title" value="<%=title%>">
204    <input type="hidden" name="warnIfOpen" value="1">
205
206    <h3 class="docked"><%=title%> <base:help helpid="runplugin.selectplugin" /></h3>
207    <div class="boxed" style="height: <%=(int)(scale*420)%>px; overflow: auto;">
208      <div class="helpmessage">
209      <%
210      if (message != null)
211      {
212        %>
213        <%=message%>
214        <%
215      }
216      else
217      {
218        %>
219        Please select the plugin and, optionally, the configuration to use.
220        <%
221      }
222      %>
223      </div>
224   
225      <table class="form" width="100%">
226      <tr valign="top">
227        <td class="prompt">Plugin</td>
228        <td>
229          <select name="plugindefinition_id" class="required" onchange="pluginOnChange()">
230          </select>
231        </td>
232      </tr>
233      <tr valign="top" id="configurations">
234        <td class="prompt">Configuration</td>
235        <td>
236          <select name="pluginconfiguration_id" onchange="configOnChange()">
237          </select>
238        </td>
239      </tr>
240      <%
241      if (messages != null && messages.size() > 0)
242      {
243        %>
244        <tr>
245          <td class="prompt">&nbsp;</td>
246          <td>
247            <base:icon image="bullet.gif" />
248            <a href="javascript:Main.showHide('pluginMessages')" 
249              title="Show/hide the messages from the plugins that couldn't be used">
250            Some plugins couldn't be used
251            </a>
252            <div id="pluginMessages" style="display: none;">
253            <ul>
254            <li><%=Values.getString(messages, "<li>", true)%>
255            </ul>
256            </div>
257          </td>
258        </tr>
259        <%
260      }
261      %>
262      </table>
263      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
264      <div id="descriptions" class="helpmessage" 
265        style="height: <%=(int)(scale*270)%>px; overflow: auto; display: none;">
266      <%=descriptions.toString()%>
267      </div>
268    </div>
269    </form>
270 
271    <%
272    if (anotherIsOpen)
273    {
274      %>
275      <div class="error">
276        Another plug-in configuration wizard is open, or it hasn't properly
277        clean up after itself.<br>
278        If you continue unsaved settings in the other wizard is lost.
279      </div>
280      <%
281    }
282    %>
283    <table align="center">
284    <tr>
285      <td width="50%"><base:button onclick="doNext();" title="Next" /></td>
286      <td width="50%"><base:button onclick="window.close();" title="Cancel" /></td>
287    </tr>
288    </table>
289  </base:body>
290  </base:page>
291  <%
292}
293finally
294{
295  if (dc != null) dc.close();
296}
297%>
298
Note: See TracBrowser for help on using the repository browser.