1 | <%-- $Id: select_plugin.jsp 5060 2009-08-19 07:02:11Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2005 Nicklas Nordborg |
---|
4 | Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg |
---|
5 | Copyright (C) 2007 Nicklas Nordborg |
---|
6 | |
---|
7 | This file is part of BASE - BioArray Software Environment. |
---|
8 | Available at http://base.thep.lu.se/ |
---|
9 | |
---|
10 | BASE is free software; you can redistribute it and/or |
---|
11 | modify it under the terms of the GNU General Public License |
---|
12 | as published by the Free Software Foundation; either version 3 |
---|
13 | of the License, or (at your option) any later version. |
---|
14 | |
---|
15 | BASE is distributed in the hope that it will be useful, |
---|
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | GNU General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU General Public License |
---|
21 | along with BASE. If not, see <http://www.gnu.org/licenses/>. |
---|
22 | ------------------------------------------------------------------ |
---|
23 | |
---|
24 | @author Nicklas |
---|
25 | @version 2.0 |
---|
26 | --%> |
---|
27 | <%@ page session="false" |
---|
28 | import="net.sf.basedb.core.SessionControl" |
---|
29 | import="net.sf.basedb.core.DbControl" |
---|
30 | import="net.sf.basedb.core.Item" |
---|
31 | import="net.sf.basedb.core.PluginDefinition" |
---|
32 | import="net.sf.basedb.core.PluginConfiguration" |
---|
33 | import="net.sf.basedb.core.PluginType" |
---|
34 | import="net.sf.basedb.core.ItemQuery" |
---|
35 | import="net.sf.basedb.core.ItemResultList" |
---|
36 | import="net.sf.basedb.core.Include" |
---|
37 | import="net.sf.basedb.core.Job" |
---|
38 | import="net.sf.basedb.core.query.Hql" |
---|
39 | import="net.sf.basedb.core.query.Expressions" |
---|
40 | import="net.sf.basedb.core.query.Restrictions" |
---|
41 | import="net.sf.basedb.core.query.Orders" |
---|
42 | import="net.sf.basedb.core.plugin.GuiContext" |
---|
43 | import="net.sf.basedb.core.plugin.Plugin" |
---|
44 | import="net.sf.basedb.core.plugin.InteractivePlugin" |
---|
45 | import="net.sf.basedb.core.plugin.AutoDetectingImporter" |
---|
46 | import="net.sf.basedb.clients.web.Base" |
---|
47 | import="net.sf.basedb.util.Values" |
---|
48 | import="net.sf.basedb.util.ContextUtil" |
---|
49 | import="net.sf.basedb.util.ContextUtil.ContextResult" |
---|
50 | import="net.sf.basedb.clients.web.util.HTML" |
---|
51 | import="java.util.Set" |
---|
52 | import="java.util.Map" |
---|
53 | import="java.util.List" |
---|
54 | %> |
---|
55 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
56 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
57 | |
---|
58 | <% |
---|
59 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
60 | final String ID = sc.getId(); |
---|
61 | final Item itemType = Item.valueOf(request.getParameter("item_type")); |
---|
62 | final String subContext = Values.getString(request.getParameter("subcontext"), ""); |
---|
63 | final GuiContext.Type contextType = GuiContext.Type.valueOf(request.getParameter("context_type")); |
---|
64 | final GuiContext context = new GuiContext(itemType, contextType); |
---|
65 | final String title = request.getParameter("title"); |
---|
66 | final boolean noAutodetect = Values.getBoolean(request.getParameter("noautodetect")); |
---|
67 | final String message = request.getParameter("message"); |
---|
68 | final boolean anotherIsOpen = sc.getSessionSetting("plugin.configure.plugin") != null; |
---|
69 | final DbControl dc = sc.newDbControl(); |
---|
70 | final float scale = Base.getScale(sc); |
---|
71 | try |
---|
72 | { |
---|
73 | final PluginType autoDetectingType = PluginType.getByInterfaceName(dc, AutoDetectingImporter.class.getName()); |
---|
74 | |
---|
75 | String jobName = Values.getString(request.getParameter("job_name"), title); |
---|
76 | |
---|
77 | List<ContextResult> contextResults = (List<ContextResult>)sc.getSessionSetting("IMPORTERS"); |
---|
78 | Set<String> messages = (Set<String>)sc.getSessionSetting("MESSAGES"); |
---|
79 | StringBuilder descriptions = new StringBuilder(); |
---|
80 | %> |
---|
81 | <base:page type="popup" title="<%=title%>"> |
---|
82 | <base:head scripts="plugin.js"> |
---|
83 | <script language="JavaScript"> |
---|
84 | function doNext() |
---|
85 | { |
---|
86 | var frm = document.forms['import']; |
---|
87 | var anotherIsOpen = <%=anotherIsOpen%>; |
---|
88 | if (anotherIsOpen) |
---|
89 | { |
---|
90 | if (!confirm('Are you sure? Unsaved settings in the other wizard will be lost.')) return; |
---|
91 | frm.warnIfOpen.value = '0'; |
---|
92 | } |
---|
93 | frm.submit(); |
---|
94 | } |
---|
95 | |
---|
96 | var lastSelectedPlugin; |
---|
97 | function pluginOnChange() |
---|
98 | { |
---|
99 | var frm = document.forms['import']; |
---|
100 | var pluginList = frm.plugindefinition_id; |
---|
101 | var configurationList = frm.pluginconfiguration_id; |
---|
102 | var plugin = pluginList[pluginList.selectedIndex].plugin; |
---|
103 | Plugins.updateConfigurationsList(plugin, configurationList); |
---|
104 | if (configurationList.length == 0) |
---|
105 | { |
---|
106 | Main.hide('configurations'); |
---|
107 | } |
---|
108 | else |
---|
109 | { |
---|
110 | Main.show('configurations'); |
---|
111 | } |
---|
112 | if (lastSelectedPlugin) |
---|
113 | { |
---|
114 | Main.hide('description.'+lastSelectedPlugin.id); |
---|
115 | } |
---|
116 | else |
---|
117 | { |
---|
118 | Main.show('descriptions'); |
---|
119 | } |
---|
120 | if (lastSelectedConfig) |
---|
121 | { |
---|
122 | Main.hide('description.config.'+lastSelectedConfig.id); |
---|
123 | } |
---|
124 | if (plugin) |
---|
125 | { |
---|
126 | Main.show('description.'+plugin.id); |
---|
127 | } |
---|
128 | else |
---|
129 | { |
---|
130 | Main.hide('descriptions'); |
---|
131 | } |
---|
132 | lastSelectedConfig = null; |
---|
133 | lastSelectedPlugin = plugin; |
---|
134 | } |
---|
135 | |
---|
136 | var lastSelectedConfig; |
---|
137 | function configOnChange() |
---|
138 | { |
---|
139 | var frm = document.forms['import']; |
---|
140 | var configurationList = frm.pluginconfiguration_id; |
---|
141 | var config = configurationList[configurationList.selectedIndex].configuration; |
---|
142 | if (lastSelectedConfig) |
---|
143 | { |
---|
144 | Main.hide('description.config.'+lastSelectedConfig.id); |
---|
145 | } |
---|
146 | else |
---|
147 | { |
---|
148 | Main.show('descriptions'); |
---|
149 | } |
---|
150 | if (config) |
---|
151 | { |
---|
152 | Main.show('description.config.'+config.id); |
---|
153 | } |
---|
154 | else |
---|
155 | { |
---|
156 | Main.hide('descriptions'); |
---|
157 | } |
---|
158 | lastSelectedConfig = config; |
---|
159 | } |
---|
160 | |
---|
161 | function init() |
---|
162 | { |
---|
163 | var frm = document.forms['import']; |
---|
164 | var pluginList = frm.plugindefinition_id; |
---|
165 | var configurationList = frm.pluginconfiguration_id; |
---|
166 | <% |
---|
167 | PluginDefinition lastPlugin = null; |
---|
168 | for (ContextResult result : contextResults) |
---|
169 | { |
---|
170 | if (result.isInContext()) |
---|
171 | { |
---|
172 | PluginDefinition pd = result.getPluginDefinition(); |
---|
173 | if (!pd.equals(lastPlugin)) |
---|
174 | { |
---|
175 | lastPlugin = pd; |
---|
176 | dc.reattachItem(pd, false); |
---|
177 | boolean autoDetecting = !noAutodetect && pd.supports(autoDetectingType); |
---|
178 | String supportsConfig = pd.supportsConfigurations() ? "true" : "false"; |
---|
179 | String requiresConfig = noAutodetect || pd.requiresConfiguration() ? "true" : "false"; |
---|
180 | descriptions.append("<div id=\"description." + pd.getId() +"\" style=\"display: none;\">"); |
---|
181 | descriptions.append(HTML.niceFormat("<b>" + pd.getName() + "</b>\n" + pd.getDescription())); |
---|
182 | descriptions.append("</div>"); |
---|
183 | %> |
---|
184 | var thePlugin = new Plugin(<%=pd.getId()%>, '<%=HTML.javaScriptEncode(pd.getName())%>', <%=autoDetecting%>, <%=supportsConfig%>, <%=requiresConfig%>); |
---|
185 | <% |
---|
186 | } |
---|
187 | PluginConfiguration pc = result.getPluginConfiguration(); |
---|
188 | if (pc != null) |
---|
189 | { |
---|
190 | descriptions.append("<div id=\"description.config." + pc.getId() + "\" style=\"display: none; padding-top: 6px;\">"); |
---|
191 | descriptions.append(HTML.niceFormat("<b>" + pc.getName() + "</b>\n" +pc.getDescription())); |
---|
192 | descriptions.append("</div>"); |
---|
193 | %> |
---|
194 | thePlugin.addConfiguration(<%=pc.getId()%>, '<%=HTML.javaScriptEncode(pc.getName())%>'); |
---|
195 | <% |
---|
196 | } |
---|
197 | } |
---|
198 | } |
---|
199 | %> |
---|
200 | Plugins.populateLists(pluginList, configurationList); |
---|
201 | if (configurationList.length == 0) |
---|
202 | { |
---|
203 | Main.hide('configurations'); |
---|
204 | } |
---|
205 | else |
---|
206 | { |
---|
207 | Main.show('configurations'); |
---|
208 | } |
---|
209 | pluginOnChange(); |
---|
210 | } |
---|
211 | </script> |
---|
212 | </base:head> |
---|
213 | <base:body onload="init()"> |
---|
214 | <form name="import" action="index.jsp" method="post" onsubmit="return false;"> |
---|
215 | <input type="hidden" name="ID" value="<%=ID%>"> |
---|
216 | <input type="hidden" name="cmd" value="RunPlugin"> |
---|
217 | <input type="hidden" name="item_type" value="<%=itemType.name()%>"> |
---|
218 | <input type="hidden" name="subcontext" value="<%=subContext%>"> |
---|
219 | <input type="hidden" name="context_type" value="<%=contextType.name()%>"> |
---|
220 | <input type="hidden" name="title" value="<%=title%>"> |
---|
221 | <input type="hidden" name="warnIfOpen" value="1"> |
---|
222 | |
---|
223 | <h3 class="docked"><%=title%> <base:help helpid="import.selectplugin" /></h3> |
---|
224 | <div class="boxed" style="height: <%=(int)(scale*420)%>px; overflow: auto;"> |
---|
225 | <div class="helpmessage"> |
---|
226 | <% |
---|
227 | if (message != null) |
---|
228 | { |
---|
229 | %> |
---|
230 | <%=message%> |
---|
231 | <% |
---|
232 | } |
---|
233 | else |
---|
234 | { |
---|
235 | %> |
---|
236 | Please select a plugin and file format to use. |
---|
237 | <% |
---|
238 | } |
---|
239 | %> |
---|
240 | </div> |
---|
241 | |
---|
242 | <table class="form" width="100%"> |
---|
243 | <tr valign="top"> |
---|
244 | <td class="prompt">Plugin</td> |
---|
245 | <td> |
---|
246 | <select name="plugindefinition_id" class="required" onchange="pluginOnChange()"> |
---|
247 | </select> |
---|
248 | <% |
---|
249 | if (!noAutodetect) |
---|
250 | { |
---|
251 | %> |
---|
252 | × = Supports auto-detection |
---|
253 | <% |
---|
254 | } |
---|
255 | %> |
---|
256 | </td> |
---|
257 | </tr> |
---|
258 | <tr valign="top" id="configurations"> |
---|
259 | <td class="prompt">File format</td> |
---|
260 | <td> |
---|
261 | <select name="pluginconfiguration_id" onchange="configOnChange()"> |
---|
262 | </select> |
---|
263 | </td> |
---|
264 | </tr> |
---|
265 | <% |
---|
266 | if (messages != null && messages.size() > 0) |
---|
267 | { |
---|
268 | %> |
---|
269 | <tr> |
---|
270 | <td class="prompt"> </td> |
---|
271 | <td> |
---|
272 | <base:icon image="bullet.gif" /> |
---|
273 | <a href="javascript:Main.showHide('pluginMessages')" |
---|
274 | title="Show/hide the messages from the plugins that couldn't be used"> |
---|
275 | Some plugins couldn't be used |
---|
276 | </a> |
---|
277 | <div id="pluginMessages" style="display: none;"> |
---|
278 | <ul> |
---|
279 | <li><%=Values.getString(messages, "<li>", true)%> |
---|
280 | </ul> |
---|
281 | </div> |
---|
282 | </td> |
---|
283 | </tr> |
---|
284 | <% |
---|
285 | } |
---|
286 | %> |
---|
287 | </table> |
---|
288 | <div align=right> <i><base:icon image="required.gif" /> = required information</i></div> |
---|
289 | <div id="descriptions" class="helpmessage" |
---|
290 | style="height: <%=(int)(scale*270)%>px; overflow: auto; display: none;"> |
---|
291 | <%=descriptions.toString()%> |
---|
292 | </div> |
---|
293 | </div> |
---|
294 | </form> |
---|
295 | |
---|
296 | <% |
---|
297 | if (anotherIsOpen) |
---|
298 | { |
---|
299 | %> |
---|
300 | <div class="error"> |
---|
301 | Another plug-in configuration wizard is open, or it hasn't properly |
---|
302 | clean up after itself.<br> |
---|
303 | If you continue unsaved settings in the other wizard is lost. |
---|
304 | </div> |
---|
305 | <% |
---|
306 | } |
---|
307 | %> |
---|
308 | <table align="center"> |
---|
309 | <tr> |
---|
310 | <td width="50%"><base:button onclick="doNext();" title="Next" /></td> |
---|
311 | <td width="50%"><base:button onclick="window.close();" title="Cancel" /></td> |
---|
312 | </tr> |
---|
313 | </table> |
---|
314 | </base:body> |
---|
315 | </base:page> |
---|
316 | <% |
---|
317 | } |
---|
318 | finally |
---|
319 | { |
---|
320 | if (dc != null) dc.close(); |
---|
321 | } |
---|
322 | %> |
---|
323 | |
---|