1 | <%-- $Id: select_file.jsp 3852 2007-10-17 07:58:57Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2005 Nicklas Nordborg |
---|
4 | Copyright (C) 2006 Jari Hakkinen, 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 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.ItemContext" |
---|
33 | import="net.sf.basedb.core.File" |
---|
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 | %> |
---|
56 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
57 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
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 ItemContext currentContext = sc.getCurrentContext(itemType, subContext); |
---|
64 | final GuiContext.Type contextType = GuiContext.Type.valueOf(request.getParameter("context_type")); |
---|
65 | final GuiContext context = new GuiContext(itemType, contextType); |
---|
66 | final String title = request.getParameter("title"); |
---|
67 | final DbControl dc = sc.newDbControl(); |
---|
68 | |
---|
69 | try |
---|
70 | { |
---|
71 | // Try to get data files attached to FileStoreEnabled items |
---|
72 | File currentFile = null; |
---|
73 | List<FileSetMember> dataFiles = null; |
---|
74 | if (FileStoreEnabled.class.isAssignableFrom(itemType.getItemClass())) |
---|
75 | { |
---|
76 | FileStoreEnabled fileStoreItem = null; |
---|
77 | try |
---|
78 | { |
---|
79 | fileStoreItem = (FileStoreEnabled)itemType.getById(dc, currentContext.getId()); |
---|
80 | } |
---|
81 | catch (Throwable t) |
---|
82 | {} |
---|
83 | if (fileStoreItem != null && fileStoreItem.hasFileSet()) |
---|
84 | { |
---|
85 | dataFiles = fileStoreItem.getFileSet().getMembers().list(dc); |
---|
86 | if (dataFiles.size() > 0) |
---|
87 | { |
---|
88 | // The first file will be selected by default |
---|
89 | try |
---|
90 | { |
---|
91 | currentFile = dataFiles.get(0).getFile(); |
---|
92 | } |
---|
93 | catch (Throwable t) |
---|
94 | {} |
---|
95 | } |
---|
96 | } |
---|
97 | } |
---|
98 | List<File> recentFiles = (List<File>)currentContext.getRecent(dc, Item.FILE); |
---|
99 | %> |
---|
100 | <%@page import="net.sf.basedb.core.RawBioAssay"%> |
---|
101 | <%@page import="net.sf.basedb.core.FileStoreUtil"%> |
---|
102 | <%@page import="net.sf.basedb.core.FileType"%> |
---|
103 | <%@page import="net.sf.basedb.core.FileStoreEnabled"%> |
---|
104 | <base:page type="popup" title="<%=title%>"> |
---|
105 | <base:head> |
---|
106 | <script language="JavaScript"> |
---|
107 | function doImport() |
---|
108 | { |
---|
109 | var frm = document.forms['import']; |
---|
110 | if (Main.trimString(frm.path.value) == '') |
---|
111 | { |
---|
112 | alert("You must select a file to import from"); |
---|
113 | frm.path.focus(); |
---|
114 | } |
---|
115 | else |
---|
116 | { |
---|
117 | frm.submit(); |
---|
118 | } |
---|
119 | } |
---|
120 | function browseOnClick() |
---|
121 | { |
---|
122 | var frm = document.forms['import']; |
---|
123 | var url = '../../filemanager/index.jsp?ID=<%=ID%>&cmd=SelectOne&title=Select+file+to+import&callback=setFileCallback'; |
---|
124 | url += '&filter:INT:location=<%=Location.PRIMARY.getValue()%>'; |
---|
125 | Main.openPopup(url, 'SelectFile', 1000, 700); |
---|
126 | } |
---|
127 | function setFileCallback(fileId, path) |
---|
128 | { |
---|
129 | var frm = document.forms['import']; |
---|
130 | frm.file_id.value = fileId; |
---|
131 | frm.path.value = path; |
---|
132 | } |
---|
133 | function recentFileOnChange() |
---|
134 | { |
---|
135 | var frm = document.forms['import']; |
---|
136 | var selected = frm.recentFile[frm.recentFile.selectedIndex]; |
---|
137 | setFileCallback(selected.value, selected.text); |
---|
138 | frm.recentFile.selectedIndex = 0; |
---|
139 | } |
---|
140 | function dataFileOnChange() |
---|
141 | { |
---|
142 | var frm = document.forms['import']; |
---|
143 | var selected = frm.dataFile[frm.dataFile.selectedIndex]; |
---|
144 | setFileCallback(selected.value, selected.text.replace(/\[.*\]\s/, '')); |
---|
145 | frm.dataFile.selectedIndex = 0; |
---|
146 | } |
---|
147 | </script> |
---|
148 | </base:head> |
---|
149 | <base:body> |
---|
150 | <form name="import" action="index.jsp" method="get" onsubmit="return false;"> |
---|
151 | <input type="hidden" name="ID" value="<%=ID%>"> |
---|
152 | <input type="hidden" name="cmd" value="AutoDetect"> |
---|
153 | <input type="hidden" name="item_type" value="<%=itemType.name()%>"> |
---|
154 | <input type="hidden" name="subcontext" value="<%=subContext%>"> |
---|
155 | <input type="hidden" name="context_type" value="<%=contextType.name()%>"> |
---|
156 | <input type="hidden" name="title" value="<%=title%>"> |
---|
157 | <input type="hidden" name="job_name" value="<%=HTML.encodeTags(request.getParameter("job_name"))%>"> |
---|
158 | <input type="hidden" name="job_description" value="<%=HTML.encodeTags(request.getParameter("job_description"))%>"> |
---|
159 | <input type="hidden" name="plugindefinition_id" value="<%=request.getParameter("plugindefinition_id")%>"> |
---|
160 | <input type="hidden" name="file_id" value=""> |
---|
161 | |
---|
162 | <h3 class="docked"><%=title%> <base:help helpid="import.autodetect.selectfile" /></h3> |
---|
163 | <div class="boxed"> |
---|
164 | <div class="helpmessage"> |
---|
165 | Select a file to import from. |
---|
166 | </div> |
---|
167 | <table class="form" width="100%"> |
---|
168 | <tr valign="top"> |
---|
169 | <td class="prompt">File</td> |
---|
170 | <td> |
---|
171 | <table border="0" cellspacing="0" cellpadding="0"> |
---|
172 | <tr> |
---|
173 | <td><input type="text" class="text required" name="path" size="60" |
---|
174 | value="<%=currentFile != null ? HTML.encodeTags(currentFile.getPath().toString()) : "" %>"> </td> |
---|
175 | <td><base:button |
---|
176 | title="Browse…" |
---|
177 | onclick="browseOnClick()" |
---|
178 | /> |
---|
179 | </td> |
---|
180 | </tr> |
---|
181 | </table> |
---|
182 | </td> |
---|
183 | </tr> |
---|
184 | <% |
---|
185 | if (dataFiles != null && dataFiles.size() > 0) |
---|
186 | { |
---|
187 | %> |
---|
188 | <tr> |
---|
189 | <td class="prompt">Data files</td> |
---|
190 | <td> |
---|
191 | <select name="dataFile" onchange="dataFileOnChange()"> |
---|
192 | <option value=""> |
---|
193 | <% |
---|
194 | for (FileSetMember member : dataFiles) |
---|
195 | { |
---|
196 | File file = null; |
---|
197 | DataFileType dft = null; |
---|
198 | try |
---|
199 | { |
---|
200 | dft = member.getDataFileType(); |
---|
201 | } |
---|
202 | catch (Throwable t) |
---|
203 | {} |
---|
204 | try |
---|
205 | { |
---|
206 | file = member.getFile(); |
---|
207 | } |
---|
208 | catch (Throwable t) |
---|
209 | {} |
---|
210 | if (file != null) |
---|
211 | { |
---|
212 | String path = HTML.encodeTags(file.getPath().toString()); |
---|
213 | String type = dft != null ? "[" + HTML.encodeTags(dft.getName()) + "] " : ""; |
---|
214 | %> |
---|
215 | <option value="<%=file.getId()%>"><%=type%><%=path%> |
---|
216 | <% |
---|
217 | } |
---|
218 | } |
---|
219 | %> |
---|
220 | </select> |
---|
221 | </td> |
---|
222 | </tr> |
---|
223 | <% |
---|
224 | } |
---|
225 | %> |
---|
226 | <% |
---|
227 | if (recentFiles.size() > 0) |
---|
228 | { |
---|
229 | %> |
---|
230 | <tr> |
---|
231 | <td class="prompt">Recently used</td> |
---|
232 | <td> |
---|
233 | <select name="recentFile" onchange="recentFileOnChange()"> |
---|
234 | <option value=""> |
---|
235 | <% |
---|
236 | for (File recent : recentFiles) |
---|
237 | { |
---|
238 | String path = HTML.encodeTags(recent.getPath().toString()); |
---|
239 | %> |
---|
240 | <option value="<%=recent.getId()%>"><%=path%> |
---|
241 | <% |
---|
242 | } |
---|
243 | %> |
---|
244 | </select> |
---|
245 | </td> |
---|
246 | </tr> |
---|
247 | <% |
---|
248 | } |
---|
249 | %> |
---|
250 | </table> |
---|
251 | <div align=right> <i><base:icon image="required.gif" /> = required information</i></div> |
---|
252 | </div> |
---|
253 | </form> |
---|
254 | |
---|
255 | <table align="center"> |
---|
256 | <tr> |
---|
257 | <td width="50%"><base:button onclick="doImport();" title="Next" /></td> |
---|
258 | <td width="50%"><base:button onclick="window.close();" title="Cancel" /></td> |
---|
259 | </tr> |
---|
260 | </table> |
---|
261 | </base:body> |
---|
262 | </base:page> |
---|
263 | <% |
---|
264 | } |
---|
265 | finally |
---|
266 | { |
---|
267 | if (dc != null) dc.close(); |
---|
268 | } |
---|
269 | %> |
---|
270 | |
---|