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