1 | <%-- $Id: select_file.jsp 5372 2010-06-24 12:28:06Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2005 Nicklas Nordborg |
---|
4 | Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, 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.Config" |
---|
29 | import="net.sf.basedb.core.DbControl" |
---|
30 | import="net.sf.basedb.core.Item" |
---|
31 | import="net.sf.basedb.core.ItemContext" |
---|
32 | import="net.sf.basedb.core.File" |
---|
33 | import="net.sf.basedb.core.PluginDefinition" |
---|
34 | import="net.sf.basedb.core.PluginConfiguration" |
---|
35 | import="net.sf.basedb.core.PluginType" |
---|
36 | import="net.sf.basedb.core.ItemQuery" |
---|
37 | import="net.sf.basedb.core.ItemResultList" |
---|
38 | import="net.sf.basedb.core.Include" |
---|
39 | import="net.sf.basedb.core.Job" |
---|
40 | import="net.sf.basedb.core.Location" |
---|
41 | import="net.sf.basedb.core.FileStoreEnabled" |
---|
42 | import="net.sf.basedb.core.FileSetMember" |
---|
43 | import="net.sf.basedb.core.DataFileType" |
---|
44 | import="net.sf.basedb.core.query.Hql" |
---|
45 | import="net.sf.basedb.core.query.Expressions" |
---|
46 | import="net.sf.basedb.core.query.Restrictions" |
---|
47 | import="net.sf.basedb.core.query.Orders" |
---|
48 | import="net.sf.basedb.core.plugin.GuiContext" |
---|
49 | import="net.sf.basedb.core.plugin.Plugin" |
---|
50 | import="net.sf.basedb.core.plugin.AutoDetectingImporter" |
---|
51 | import="net.sf.basedb.clients.web.Base" |
---|
52 | import="net.sf.basedb.clients.web.util.HTML" |
---|
53 | import="net.sf.basedb.util.Values" |
---|
54 | import="java.util.List" |
---|
55 | import="java.nio.charset.Charset" |
---|
56 | %> |
---|
57 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
58 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
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 ItemContext currentContext = sc.getCurrentContext(itemType, subContext); |
---|
65 | final GuiContext.Type contextType = GuiContext.Type.valueOf(request.getParameter("context_type")); |
---|
66 | final GuiContext context = new GuiContext(itemType, contextType); |
---|
67 | final String title = request.getParameter("title"); |
---|
68 | final DbControl dc = sc.newDbControl(); |
---|
69 | final int pluginId = Values.getInt(request.getParameter("plugindefinition_id")); |
---|
70 | PluginDefinition plugin = null; |
---|
71 | if (pluginId > 0) |
---|
72 | { |
---|
73 | plugin = PluginDefinition.getById(dc, pluginId); |
---|
74 | } |
---|
75 | |
---|
76 | try |
---|
77 | { |
---|
78 | // Try to get data files attached to FileStoreEnabled items |
---|
79 | File currentFile = null; |
---|
80 | List<FileSetMember> dataFiles = null; |
---|
81 | if (itemType.getItemClass() != null && |
---|
82 | FileStoreEnabled.class.isAssignableFrom(itemType.getItemClass())) |
---|
83 | { |
---|
84 | FileStoreEnabled fileStoreItem = null; |
---|
85 | try |
---|
86 | { |
---|
87 | fileStoreItem = (FileStoreEnabled)itemType.getById(dc, currentContext.getId()); |
---|
88 | } |
---|
89 | catch (Throwable t) |
---|
90 | {} |
---|
91 | if (fileStoreItem != null && fileStoreItem.hasFileSet()) |
---|
92 | { |
---|
93 | dataFiles = fileStoreItem.getFileSet().getMembers().list(dc); |
---|
94 | if (dataFiles.size() > 0) |
---|
95 | { |
---|
96 | // The first file will be selected by default |
---|
97 | try |
---|
98 | { |
---|
99 | currentFile = dataFiles.get(0).getFile(); |
---|
100 | } |
---|
101 | catch (Throwable t) |
---|
102 | {} |
---|
103 | } |
---|
104 | } |
---|
105 | } |
---|
106 | List<File> recentFiles = (List<File>)currentContext.getRecent(dc, Item.FILE); |
---|
107 | %> |
---|
108 | <base:page type="popup" title="<%=title%>"> |
---|
109 | <base:head scripts="ajax.js"> |
---|
110 | <script language="JavaScript"> |
---|
111 | function doImport() |
---|
112 | { |
---|
113 | var frm = document.forms['import']; |
---|
114 | if (Main.trimString(frm.path.value) == '') |
---|
115 | { |
---|
116 | alert("You must select a file to import from"); |
---|
117 | frm.path.focus(); |
---|
118 | } |
---|
119 | else |
---|
120 | { |
---|
121 | frm.submit(); |
---|
122 | } |
---|
123 | } |
---|
124 | function browseOnClick() |
---|
125 | { |
---|
126 | var frm = document.forms['import']; |
---|
127 | var url = '../../filemanager/index.jsp?ID=<%=ID%>&cmd=SelectOne&title=Select+file+to+import&callback=setFileCallback'; |
---|
128 | Main.openPopup(url, 'SelectFile', 1000, 700); |
---|
129 | } |
---|
130 | function setFileCallback(fileId, path) |
---|
131 | { |
---|
132 | var frm = document.forms['import']; |
---|
133 | frm.file_id.value = fileId; |
---|
134 | frm.path.value = path; |
---|
135 | updateCharset(fileId); |
---|
136 | } |
---|
137 | function updateCharset(fileId) |
---|
138 | { |
---|
139 | var request = Ajax.getXmlHttpRequest(); |
---|
140 | if (request != null) |
---|
141 | { |
---|
142 | var url = '../../filemanager/files/ajax.jsp?ID=<%=ID%>&cmd=GetCharset&item_id=' + fileId; |
---|
143 | request.open("GET", url, true); |
---|
144 | Ajax.setReadyStateHandler(request, updateCharsetCallback); |
---|
145 | request.send(null); |
---|
146 | } |
---|
147 | return request != null; |
---|
148 | } |
---|
149 | function updateCharsetCallback(request) |
---|
150 | { |
---|
151 | var charset = Main.trimString(request.responseText); |
---|
152 | if (!charset) charset = '<%=Config.getCharset()%>'; |
---|
153 | var frm = document.forms['import']; |
---|
154 | Forms.selectListOption(frm.charset, charset); |
---|
155 | } |
---|
156 | function recentFileOnChange() |
---|
157 | { |
---|
158 | var frm = document.forms['import']; |
---|
159 | var selected = frm.recentFile[frm.recentFile.selectedIndex]; |
---|
160 | setFileCallback(selected.value, selected.text); |
---|
161 | frm.recentFile.selectedIndex = 0; |
---|
162 | } |
---|
163 | function dataFileOnChange() |
---|
164 | { |
---|
165 | var frm = document.forms['import']; |
---|
166 | var selected = frm.dataFile[frm.dataFile.selectedIndex]; |
---|
167 | setFileCallback(selected.value, selected.text.replace(/\[.*\]\s/, '')); |
---|
168 | frm.dataFile.selectedIndex = 0; |
---|
169 | } |
---|
170 | </script> |
---|
171 | </base:head> |
---|
172 | <base:body> |
---|
173 | <form name="import" action="index.jsp" method="get" onsubmit="return false;"> |
---|
174 | <input type="hidden" name="ID" value="<%=ID%>"> |
---|
175 | <input type="hidden" name="cmd" value="AutoDetect"> |
---|
176 | <input type="hidden" name="item_type" value="<%=itemType.name()%>"> |
---|
177 | <input type="hidden" name="subcontext" value="<%=subContext%>"> |
---|
178 | <input type="hidden" name="context_type" value="<%=contextType.name()%>"> |
---|
179 | <input type="hidden" name="title" value="<%=title%>"> |
---|
180 | <input type="hidden" name="job_name" value="<%=HTML.encodeTags(request.getParameter("job_name"))%>"> |
---|
181 | <input type="hidden" name="job_description" value="<%=HTML.encodeTags(request.getParameter("job_description"))%>"> |
---|
182 | <input type="hidden" name="plugindefinition_id" value="<%=request.getParameter("plugindefinition_id")%>"> |
---|
183 | <input type="hidden" name="file_id" value=""> |
---|
184 | |
---|
185 | <h3 class="docked"><%=title%> (auto-detect file format) <base:help helpid="import.autodetect.selectfile" /></h3> |
---|
186 | <div class="boxed"> |
---|
187 | <div class="helpmessage"> |
---|
188 | Select a file to import from. |
---|
189 | </div> |
---|
190 | <table class="form" width="100%"> |
---|
191 | <tr valign="top"> |
---|
192 | <td class="prompt">Plugin</td> |
---|
193 | <td><%=plugin != null ? HTML.encodeTags(plugin.getName()) : "<i>- all -</i>"%></td> |
---|
194 | </tr> |
---|
195 | <tr valign="top"> |
---|
196 | <td class="prompt">File</td> |
---|
197 | <td> |
---|
198 | <table border="0" cellspacing="0" cellpadding="0"> |
---|
199 | <tr> |
---|
200 | <td><input type="text" class="text required" name="path" size="60" |
---|
201 | value="<%=currentFile != null ? HTML.encodeTags(currentFile.getPath().toString()) : "" %>"> </td> |
---|
202 | <td><base:button |
---|
203 | title="Browse…" |
---|
204 | onclick="browseOnClick()" |
---|
205 | /> |
---|
206 | </td> |
---|
207 | </tr> |
---|
208 | </table> |
---|
209 | </td> |
---|
210 | </tr> |
---|
211 | <tr> |
---|
212 | <td class="prompt">Character set</td> |
---|
213 | <td> |
---|
214 | <select name="charset"> |
---|
215 | <% |
---|
216 | String defaultCharset = Config.getCharset(); |
---|
217 | for (String charset : Charset.availableCharsets().keySet()) |
---|
218 | { |
---|
219 | %> |
---|
220 | <option value="<%=charset%>" |
---|
221 | <%=defaultCharset.equalsIgnoreCase(charset) ? "selected" : ""%>><%=charset%> |
---|
222 | <% |
---|
223 | } |
---|
224 | %> |
---|
225 | </select> |
---|
226 | </td> |
---|
227 | </tr> |
---|
228 | <% |
---|
229 | if (dataFiles != null && dataFiles.size() > 0) |
---|
230 | { |
---|
231 | %> |
---|
232 | <tr> |
---|
233 | <td class="prompt">Data files</td> |
---|
234 | <td> |
---|
235 | <select name="dataFile" onchange="dataFileOnChange()"> |
---|
236 | <option value=""> |
---|
237 | <% |
---|
238 | for (FileSetMember member : dataFiles) |
---|
239 | { |
---|
240 | File file = null; |
---|
241 | DataFileType dft = null; |
---|
242 | try |
---|
243 | { |
---|
244 | dft = member.getDataFileType(); |
---|
245 | } |
---|
246 | catch (Throwable t) |
---|
247 | {} |
---|
248 | try |
---|
249 | { |
---|
250 | file = member.getFile(); |
---|
251 | } |
---|
252 | catch (Throwable t) |
---|
253 | {} |
---|
254 | if (file != null) |
---|
255 | { |
---|
256 | String path = HTML.encodeTags(file.getPath().toString()); |
---|
257 | String type = dft != null ? "[" + HTML.encodeTags(dft.getName()) + "] " : ""; |
---|
258 | %> |
---|
259 | <option value="<%=file.getId()%>"><%=type%><%=path%> |
---|
260 | <% |
---|
261 | } |
---|
262 | } |
---|
263 | %> |
---|
264 | </select> |
---|
265 | </td> |
---|
266 | </tr> |
---|
267 | <% |
---|
268 | } |
---|
269 | %> |
---|
270 | <% |
---|
271 | if (recentFiles.size() > 0) |
---|
272 | { |
---|
273 | %> |
---|
274 | <tr> |
---|
275 | <td class="prompt">Recently used</td> |
---|
276 | <td> |
---|
277 | <select name="recentFile" onchange="recentFileOnChange()"> |
---|
278 | <option value=""> |
---|
279 | <% |
---|
280 | for (File recent : recentFiles) |
---|
281 | { |
---|
282 | String path = HTML.encodeTags(recent.getPath().toString()); |
---|
283 | %> |
---|
284 | <option value="<%=recent.getId()%>"><%=path%> |
---|
285 | <% |
---|
286 | } |
---|
287 | %> |
---|
288 | </select> |
---|
289 | </td> |
---|
290 | </tr> |
---|
291 | <% |
---|
292 | } |
---|
293 | %> |
---|
294 | </table> |
---|
295 | <div align=right> <i><base:icon image="required.gif" /> = required information</i></div> |
---|
296 | </div> |
---|
297 | </form> |
---|
298 | |
---|
299 | <table align="center"> |
---|
300 | <tr> |
---|
301 | <td width="50%"><base:button onclick="doImport();" title="Next" /></td> |
---|
302 | <td width="50%"><base:button onclick="window.close();" title="Cancel" /></td> |
---|
303 | </tr> |
---|
304 | </table> |
---|
305 | </base:body> |
---|
306 | </base:page> |
---|
307 | <% |
---|
308 | } |
---|
309 | finally |
---|
310 | { |
---|
311 | if (dc != null) dc.close(); |
---|
312 | } |
---|
313 | %> |
---|
314 | |
---|