1 | <%-- $Id:select_files.jsp 3820 2007-10-12 10:03:18Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2005 Nicklas Nordborg |
---|
4 | Copyright (C) 2006 Jari Hakkinen, 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 2 |
---|
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 this program; if not, write to the Free Software |
---|
22 | Foundation, Inc., 59 Temple Place - Suite 330, |
---|
23 | Boston, MA 02111-1307, USA. |
---|
24 | ------------------------------------------------------------------ |
---|
25 | |
---|
26 | --%> |
---|
27 | <%@ page |
---|
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.ItemContext" |
---|
32 | import="net.sf.basedb.core.Type" |
---|
33 | import="net.sf.basedb.core.BasicItem" |
---|
34 | import="net.sf.basedb.core.Permission" |
---|
35 | import="net.sf.basedb.core.Nameable" |
---|
36 | import="net.sf.basedb.core.FileStoreEnabled" |
---|
37 | import="net.sf.basedb.core.FileSet" |
---|
38 | import="net.sf.basedb.core.FileSetMember" |
---|
39 | import="net.sf.basedb.core.File" |
---|
40 | import="net.sf.basedb.core.Platform" |
---|
41 | import="net.sf.basedb.core.PlatformVariant" |
---|
42 | import="net.sf.basedb.core.PlatformFileType" |
---|
43 | import="net.sf.basedb.core.DataFileType" |
---|
44 | import="net.sf.basedb.core.ItemQuery" |
---|
45 | import="net.sf.basedb.core.Include" |
---|
46 | import="net.sf.basedb.core.ItemResultList" |
---|
47 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
48 | import="net.sf.basedb.core.query.Expressions" |
---|
49 | import="net.sf.basedb.core.query.Restrictions" |
---|
50 | import="net.sf.basedb.core.query.Hql" |
---|
51 | import="net.sf.basedb.core.query.Orders" |
---|
52 | import="net.sf.basedb.clients.web.Base" |
---|
53 | import="net.sf.basedb.clients.web.util.HTML" |
---|
54 | import="net.sf.basedb.util.formatter.Formatter" |
---|
55 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
56 | import="net.sf.basedb.clients.web.formatter.FormatterSettings" |
---|
57 | import="net.sf.basedb.util.Values" |
---|
58 | import="java.util.ArrayList" |
---|
59 | import="java.util.List" |
---|
60 | import="java.util.Date" |
---|
61 | import="java.util.Set" |
---|
62 | import="java.util.HashSet" |
---|
63 | import="java.util.TreeSet" |
---|
64 | %> |
---|
65 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
66 | <% |
---|
67 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
68 | final String ID = sc.getId(); |
---|
69 | final float scale = Base.getScale(sc); |
---|
70 | final Item itemType = Item.valueOf(request.getParameter("item_type")); |
---|
71 | final int itemId = Values.getInt(request.getParameter("item_id")); |
---|
72 | final int platformId = Values.getInt(request.getParameter("platform_id"), -1); |
---|
73 | final int variantId = Values.getInt(request.getParameter("variant_id"), -1); |
---|
74 | final ItemContext cc = sc.getCurrentContext(itemType); |
---|
75 | |
---|
76 | final DbControl dc = sc.newDbControl(); |
---|
77 | try |
---|
78 | { |
---|
79 | |
---|
80 | // Get the current item; null if we are editing a new item |
---|
81 | final FileStoreEnabled item = itemId == 0 ? null : (FileStoreEnabled)itemType.getById(dc, itemId); |
---|
82 | FileSet fileSet = null; |
---|
83 | if (item != null && item.hasFileSet()) |
---|
84 | { |
---|
85 | fileSet = item.getFileSet(); |
---|
86 | } |
---|
87 | |
---|
88 | // Get the current platform/variant |
---|
89 | // -- if not submitted in URL use values from current item |
---|
90 | PlatformVariant variant = null; |
---|
91 | Platform platform = null; |
---|
92 | boolean deniedPlatform = false; |
---|
93 | try |
---|
94 | { |
---|
95 | if (variantId > 0) |
---|
96 | { |
---|
97 | variant = PlatformVariant.getById(dc, variantId); |
---|
98 | platform = variant.getPlatform(); |
---|
99 | } |
---|
100 | else if (platformId > 0) |
---|
101 | { |
---|
102 | platform = Platform.getById(dc, platformId); |
---|
103 | } |
---|
104 | else if (item != null) |
---|
105 | { |
---|
106 | variant = item.getVariant(); |
---|
107 | platform = item.getPlatform(); |
---|
108 | } |
---|
109 | } |
---|
110 | catch (PermissionDeniedException ex) |
---|
111 | { |
---|
112 | deniedPlatform = true; |
---|
113 | } |
---|
114 | |
---|
115 | // Query to load data file types for specific itemType/platform/variant |
---|
116 | final ItemQuery<DataFileType> fileTypeQuery = |
---|
117 | Base.getDataFileTypes(itemType, platform, variant); |
---|
118 | List<DataFileType> fileTypes = fileTypeQuery.list(dc); |
---|
119 | |
---|
120 | String title = "Select data files for " + |
---|
121 | HTML.encodeTags((item instanceof Nameable ? ((Nameable)item).getName() : |
---|
122 | (item == null ? " new item" : item.toString()))); |
---|
123 | |
---|
124 | final String clazz = "class=\"text\""; |
---|
125 | final String requiredClazz = "class=\"text required\""; |
---|
126 | final StringBuilder sb = new StringBuilder(); |
---|
127 | List<File> recentFiles = null; |
---|
128 | |
---|
129 | %> |
---|
130 | <%@page import="net.sf.basedb.core.PlatformFileType"%> |
---|
131 | <base:page type="popup" title="<%=title%>"> |
---|
132 | <base:head scripts="" styles="parameters.css"> |
---|
133 | |
---|
134 | <script language="JavaScript"> |
---|
135 | function init() |
---|
136 | { |
---|
137 | } |
---|
138 | var lastFileInputName; |
---|
139 | function browseOnClick(inputName, extension) |
---|
140 | { |
---|
141 | var frm = document.forms['datafiles']; |
---|
142 | var url = '../../filemanager/index.jsp?ID=<%=ID%>&cmd=SelectOne&callback=setFileCallback'; |
---|
143 | if (extension) |
---|
144 | { |
---|
145 | url += '&filter:STRING:name='+escape('%.' + extension); |
---|
146 | } |
---|
147 | else |
---|
148 | { |
---|
149 | url += '&filter:STRING:name='; |
---|
150 | } |
---|
151 | lastFileInputName = inputName; |
---|
152 | Main.openPopup(url, 'SelectFile', 1000, 700); |
---|
153 | } |
---|
154 | function setFileCallback(fileId, path) |
---|
155 | { |
---|
156 | var frm = document.forms['datafiles']; |
---|
157 | frm[lastFileInputName].value = path; |
---|
158 | fileOnChange(lastFileInputName); |
---|
159 | } |
---|
160 | function fileOnChange(inputName) |
---|
161 | { |
---|
162 | var frm = document.forms['datafiles']; |
---|
163 | if (frm[inputName].value != '') |
---|
164 | { |
---|
165 | frm['datafiles.validate'].checked = true; |
---|
166 | frm['datafiles.metadata'].checked = true; |
---|
167 | } |
---|
168 | } |
---|
169 | function recentOnChange(inputName) |
---|
170 | { |
---|
171 | var frm = document.forms['datafiles']; |
---|
172 | var recentInput = frm['recent.'+inputName]; |
---|
173 | if (recentInput.selectedIndex > 0) |
---|
174 | { |
---|
175 | var path = recentInput[recentInput.selectedIndex].text; |
---|
176 | if (frm[inputName].value != path) |
---|
177 | { |
---|
178 | frm[inputName].value = path; |
---|
179 | fileOnChange(inputName); |
---|
180 | } |
---|
181 | recentInput.selectedIndex = 0; |
---|
182 | } |
---|
183 | } |
---|
184 | </script> |
---|
185 | </base:head> |
---|
186 | |
---|
187 | <base:body onload="init()" style="background: #E0E0E0;"> |
---|
188 | |
---|
189 | <form name="datafiles"> |
---|
190 | <% |
---|
191 | if (fileTypes.size() == 0) |
---|
192 | { |
---|
193 | %> |
---|
194 | <div class="error"> |
---|
195 | The <%=platform == null ? "" : "'" + HTML.encodeTags(platform.getName()) + "'" %> |
---|
196 | platform doesn't define any file types for <%=itemType.toString() %> |
---|
197 | items. |
---|
198 | </div> |
---|
199 | <% |
---|
200 | } |
---|
201 | else if (deniedPlatform) |
---|
202 | { |
---|
203 | %> |
---|
204 | <div class="error">Denied</div> |
---|
205 | <% |
---|
206 | } |
---|
207 | else |
---|
208 | { |
---|
209 | %> |
---|
210 | <table class="form" cellspacing="2" border="0" cellpadding="0" width="100%"> |
---|
211 | <% |
---|
212 | for (DataFileType dft : fileTypes) |
---|
213 | { |
---|
214 | PlatformFileType pft = platform == null ? |
---|
215 | null : platform.getFileType(dft, variant); |
---|
216 | boolean isRequired = pft == null ? false : pft.isRequired(); |
---|
217 | FileSetMember member = fileSet == null || !fileSet.hasMember(dft) ? |
---|
218 | null : fileSet.getMember(dft); |
---|
219 | File file = null; |
---|
220 | boolean deniedFile = false; |
---|
221 | String extension = dft.getExtension(); |
---|
222 | if (member != null) |
---|
223 | { |
---|
224 | try |
---|
225 | { |
---|
226 | file = member.getFile(); |
---|
227 | } |
---|
228 | catch (PermissionDeniedException ex) |
---|
229 | { |
---|
230 | deniedFile = true; |
---|
231 | } |
---|
232 | } |
---|
233 | |
---|
234 | String path = ""; |
---|
235 | if (file != null) |
---|
236 | { |
---|
237 | path = file.getPath().toString(); |
---|
238 | } |
---|
239 | else if (deniedFile || deniedPlatform) |
---|
240 | { |
---|
241 | path = "- denied -"; |
---|
242 | } |
---|
243 | String inputName= "datafile."+dft.getId(); |
---|
244 | recentFiles = (List<File>)cc.getRecent(dc, Item.FILE, dft.getExternalId()); |
---|
245 | %> |
---|
246 | <tr> |
---|
247 | <td class="prompt"><%=HTML.encodeTags(dft.getName())%></td> |
---|
248 | <td> |
---|
249 | <table border="0" cellspacing="0" cellpadding="0"> |
---|
250 | <tr> |
---|
251 | <td> |
---|
252 | <input <%=isRequired ? requiredClazz : clazz%> type="text" |
---|
253 | name="<%=inputName%>" value="<%=HTML.encodeTags(path)%>" |
---|
254 | size="50" title="<%=HTML.encodeTags(dft.getDescription())%>" |
---|
255 | <%=deniedFile || deniedPlatform ? "disabled" : "" %> |
---|
256 | onchange="fileOnChange('<%=inputName%>')"> |
---|
257 | </td> |
---|
258 | <td><base:button |
---|
259 | title="Browse…" |
---|
260 | onclick="<%="browseOnClick('"+inputName+"', '" + HTML.javaScriptEncode(extension) + "')"%>" |
---|
261 | disabled="<%=deniedFile || deniedPlatform %>" |
---|
262 | /> |
---|
263 | </td> |
---|
264 | </tr> |
---|
265 | </table> |
---|
266 | </td> |
---|
267 | </tr> |
---|
268 | <tr> |
---|
269 | <td align="right"></td> |
---|
270 | <td> |
---|
271 | <% |
---|
272 | if (recentFiles != null && recentFiles.size() > 0) |
---|
273 | { |
---|
274 | %> |
---|
275 | <select name="recent.<%=inputName%>" onchange="recentOnChange('<%=inputName%>')"> |
---|
276 | <option value="">- recently used - |
---|
277 | <% |
---|
278 | for (File recent : recentFiles) |
---|
279 | { |
---|
280 | %> |
---|
281 | <option value="<%=recent.getId()%>"><%=HTML.encodeTags(recent.getPath().toString())%> |
---|
282 | <% |
---|
283 | } |
---|
284 | %> |
---|
285 | </select> |
---|
286 | <% |
---|
287 | } |
---|
288 | %> |
---|
289 | </td> |
---|
290 | </tr> |
---|
291 | <% |
---|
292 | } |
---|
293 | %> |
---|
294 | <tr> |
---|
295 | <td class="prompt">Validate</td> |
---|
296 | <td><input type="checkbox" value="1" name="datafiles.validate"></td> |
---|
297 | </tr> |
---|
298 | <tr> |
---|
299 | <td class="prompt">Extract metadata</td> |
---|
300 | <td><input type="checkbox" value="1" name="datafiles.metadata"></td> |
---|
301 | </tr> |
---|
302 | </table> |
---|
303 | <% |
---|
304 | } |
---|
305 | %> |
---|
306 | |
---|
307 | </form> |
---|
308 | |
---|
309 | </base:body> |
---|
310 | </base:page> |
---|
311 | <% |
---|
312 | } |
---|
313 | finally |
---|
314 | { |
---|
315 | if (dc != null) dc.close(); |
---|
316 | } |
---|
317 | %> |
---|