1 | <%-- $Id: jep_extra_value_calculator.jsp 3518 2007-06-20 06:48:57Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) Authors contributing to this file. |
---|
4 | |
---|
5 | This file is part of BASE - BioArray Software Environment. |
---|
6 | Available at http://base.thep.lu.se/ |
---|
7 | |
---|
8 | BASE is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU General Public License |
---|
10 | as published by the Free Software Foundation; either version 2 |
---|
11 | of the License, or (at your option) any later version. |
---|
12 | |
---|
13 | BASE is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | GNU General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with this program; if not, write to the Free Software |
---|
20 | Foundation, Inc., 59 Temple Place - Suite 330, |
---|
21 | Boston, MA 02111-1307, USA. |
---|
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.ItemContext" |
---|
32 | import="net.sf.basedb.core.RawDataType" |
---|
33 | import="net.sf.basedb.core.BioAssaySet" |
---|
34 | import="net.sf.basedb.core.Formula" |
---|
35 | import="net.sf.basedb.core.Job" |
---|
36 | import="net.sf.basedb.core.ExtraValueType" |
---|
37 | import="net.sf.basedb.core.ItemQuery" |
---|
38 | import="net.sf.basedb.core.ItemResultList" |
---|
39 | import="net.sf.basedb.core.Include" |
---|
40 | import="net.sf.basedb.core.query.Orders" |
---|
41 | import="net.sf.basedb.core.query.Hql" |
---|
42 | import="net.sf.basedb.clients.web.Base" |
---|
43 | import="net.sf.basedb.clients.web.WebException" |
---|
44 | import="net.sf.basedb.clients.web.util.HTML" |
---|
45 | import="net.sf.basedb.util.Values" |
---|
46 | import="java.util.List" |
---|
47 | %> |
---|
48 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
49 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
50 | <%! |
---|
51 | private static void addFormulaOption(StringBuilder options, String formula, String title, String description) |
---|
52 | { |
---|
53 | options.append("<option value=\"").append(HTML.encodeTags(formula)).append("\""); |
---|
54 | options.append(" title=\"").append(HTML.encodeTags(description)).append("\""); |
---|
55 | options.append(">").append(HTML.encodeTags(title)).append("\n"); |
---|
56 | } |
---|
57 | %> |
---|
58 | <% |
---|
59 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
60 | final String ID = sc.getId(); |
---|
61 | ItemContext cc = sc.getCurrentContext(Item.BIOASSAYSET); |
---|
62 | ItemContext realContext = (ItemContext)sc.getSessionSetting("plugin.configure.currentContext"); |
---|
63 | if (realContext == null) realContext = cc; |
---|
64 | DbControl dc = null; |
---|
65 | try |
---|
66 | { |
---|
67 | String errorMessage = (String)sc.getSessionSetting("plugin.configure.errors.message"); |
---|
68 | List<Throwable> errors = (List<Throwable>)sc.getSessionSetting("plugin.configure.errors.list"); |
---|
69 | |
---|
70 | dc = sc.newDbControl(); |
---|
71 | Job job = (Job)sc.getSessionSetting("plugin.configure.job"); |
---|
72 | dc.reattachItem(job); |
---|
73 | BioAssaySet source = null; |
---|
74 | if (job != null) source = (BioAssaySet)job.getParameterValue("source"); |
---|
75 | if (source == null && cc.getId() != 0) source = BioAssaySet.getById(dc, cc.getId()); |
---|
76 | if (source == null) throw new WebException("popup", "No current bioassay set", |
---|
77 | "Could not find any current bioassay set. Please select a bioassay set before trying again"); |
---|
78 | source = BioAssaySet.getById(dc, source.getId()); |
---|
79 | int maxRawMappings = source.getMaxRawMappingsForSpot(); |
---|
80 | |
---|
81 | RawDataType rdt = source.getRawDataType(); |
---|
82 | |
---|
83 | // Current parameter values |
---|
84 | ExtraValueType currentExtraValueType = (ExtraValueType)job.getParameterValue("extraValueType"); |
---|
85 | String expression = (String)job.getParameterValue("expression"); |
---|
86 | |
---|
87 | |
---|
88 | // Predefined formulas |
---|
89 | ItemQuery<Formula> formulaQuery = Formula.getQuery(Formula.Type.COLUMN_EXPRESSION, rdt); |
---|
90 | formulaQuery.order(Orders.asc(Hql.property("name"))); |
---|
91 | formulaQuery.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS); |
---|
92 | ItemResultList<Formula> formulas = formulaQuery.list(dc); |
---|
93 | StringBuilder formulaOptions = new StringBuilder(); |
---|
94 | for (Formula f : formulas) |
---|
95 | { |
---|
96 | String formula = f.getFormula(0); |
---|
97 | if (maxRawMappings == 1 || !formula.contains("raw(")) |
---|
98 | { |
---|
99 | addFormulaOption(formulaOptions, formula, f.getName(), f.getDescription()); |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | // Load recently used items |
---|
104 | List<ExtraValueType> recentExtraValueTypes = (List<ExtraValueType>)realContext.getRecent(dc, Item.EXTRAVALUETYPE); |
---|
105 | %> |
---|
106 | <base:page type="popup" title="Calculate extra value"> |
---|
107 | <base:head styles="parameters.css"> |
---|
108 | <script language="JavaScript"> |
---|
109 | function hideErrorList() |
---|
110 | { |
---|
111 | Main.hide('errorlist'); |
---|
112 | Main.show('showerrorlist'); |
---|
113 | } |
---|
114 | function showErrorList() |
---|
115 | { |
---|
116 | Main.show('errorlist'); |
---|
117 | Main.hide('showerrorlist'); |
---|
118 | } |
---|
119 | function selectExtraValueTypeOnClick() |
---|
120 | { |
---|
121 | var frm = document.forms['extraValue']; |
---|
122 | var url = '../../admin/extravaluetypes/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setExtraValueTypeCallback'; |
---|
123 | if (frm['parameter:extraValueType'].length > 1) |
---|
124 | { |
---|
125 | var id = Math.abs(parseInt(frm['parameter:extraValueType'][1].value)); |
---|
126 | url += '&item_id='+id; |
---|
127 | } |
---|
128 | Main.openPopup(url, 'SelectExtraValueType', 1000, 700); |
---|
129 | } |
---|
130 | function setExtraValueTypeCallback(id, name) |
---|
131 | { |
---|
132 | var frm = document.forms['extraValue']; |
---|
133 | var list = frm['parameter:extraValueType']; |
---|
134 | if (list.length < 1 || list[0].value == '0') // > |
---|
135 | { |
---|
136 | Forms.addListOption(list, 0, new Option()); |
---|
137 | } |
---|
138 | list[0].value = id; |
---|
139 | list[0].text = name; |
---|
140 | list.selectedIndex = 0; |
---|
141 | } |
---|
142 | |
---|
143 | function presetOnChange(list, formula, label) |
---|
144 | { |
---|
145 | var index = list.selectedIndex; |
---|
146 | formula.value = list[index].value; |
---|
147 | if (list[index].value != '' && label) label.value = list[index].text; |
---|
148 | } |
---|
149 | function openExpressionBuilder() |
---|
150 | { |
---|
151 | Main.expressionBuilder('<%=ID%>', 'Expression', 'extraValue', 'parameter:expression', 'COLUMN_EXPRESSION', '<%=rdt.getId()%>', <%=rdt.getChannels()%>, false, <%=source.getId()%>); |
---|
152 | } |
---|
153 | function validate() |
---|
154 | { |
---|
155 | var frm = document.forms['extraValue']; |
---|
156 | if (frm['parameter:extraValueType'].selectedIndex < 0) |
---|
157 | { |
---|
158 | alert('You must select a type'); |
---|
159 | return false; |
---|
160 | } |
---|
161 | else if (Main.trimString(frm['parameter:expression'].value) == '') |
---|
162 | { |
---|
163 | alert('You must enter an expression for the extra value'); |
---|
164 | frm['parameter:expression'].focus(); |
---|
165 | return false; |
---|
166 | } |
---|
167 | <% |
---|
168 | if (maxRawMappings != 1) |
---|
169 | { |
---|
170 | %> |
---|
171 | else if (frm['parameter:expression'].value.search(/raw\(/) != -1) |
---|
172 | { |
---|
173 | alert('Can\'t use function raw() for bioassaysets with multiple mappings to raw data'); |
---|
174 | frm['parameter:expression'].focus(); |
---|
175 | return false; |
---|
176 | } |
---|
177 | <% |
---|
178 | } |
---|
179 | %> |
---|
180 | return true; |
---|
181 | } |
---|
182 | function doNext() |
---|
183 | { |
---|
184 | if (validate()) |
---|
185 | { |
---|
186 | var frm = document.forms['extraValue']; |
---|
187 | frm.submit(); |
---|
188 | } |
---|
189 | } |
---|
190 | function doCancel() |
---|
191 | { |
---|
192 | location = 'index.jsp?ID=<%=ID%>&cmd=CancelWizard'; |
---|
193 | } |
---|
194 | </script> |
---|
195 | </base:head> |
---|
196 | <base:body> |
---|
197 | <form name="extraValue" action="index.jsp" method="get" onsubmit="return false;"> |
---|
198 | <input type="hidden" name="ID" value="<%=ID%>"> |
---|
199 | <input type="hidden" name="requestId" value="<%=request.getParameter("requestId")%>"> |
---|
200 | <input type="hidden" name="cmd" value="SetParameters"> |
---|
201 | <input type="hidden" name="parameter:source" value="<%=source.getId()%>"> |
---|
202 | |
---|
203 | <h3 class="docked">Calculate extra value <base:help helpid="jepextravaluecalculator.options"/></h3> |
---|
204 | <div class="boxed"> |
---|
205 | |
---|
206 | <% |
---|
207 | if (errorMessage != null || (errors != null && errors.size() > 0)) |
---|
208 | { |
---|
209 | %> |
---|
210 | <div id="errors" style="margin-bottom: 12px;" class="parameterhelp"> |
---|
211 | <div class="error" style="margin: 0px;"> |
---|
212 | <%=errorMessage %> |
---|
213 | </div> |
---|
214 | <% |
---|
215 | if (errors != null && errors.size() > 0) |
---|
216 | { |
---|
217 | %> |
---|
218 | <div id="showerrorlist" style="display: none;"> |
---|
219 | <base:icon image="bullet.gif" /><a href="javascript:showErrorList()">Show details</a> |
---|
220 | </div> |
---|
221 | <div id="errorlist"> |
---|
222 | <ol> |
---|
223 | <% |
---|
224 | for (Throwable t : errors) |
---|
225 | { |
---|
226 | %> |
---|
227 | <li><%=t.getMessage()%><br> |
---|
228 | <% |
---|
229 | } |
---|
230 | %> |
---|
231 | </ol> |
---|
232 | <base:icon image="bullet.gif" /><a href="javascript:hideErrorList()">Hide details</a> |
---|
233 | </div> |
---|
234 | <% |
---|
235 | } |
---|
236 | %> |
---|
237 | </div> |
---|
238 | <% |
---|
239 | } |
---|
240 | %> |
---|
241 | |
---|
242 | <table class="form" width="100%"> |
---|
243 | <tr valign="top"> |
---|
244 | <td class="prompt">Source bioassay set</td> |
---|
245 | <td><%=HTML.encodeTags(source.getName())%></td> |
---|
246 | </tr> |
---|
247 | <tr> |
---|
248 | <td class="prompt">Extra value type</td> |
---|
249 | <td> |
---|
250 | <base:select |
---|
251 | id="parameter:extraValueType" |
---|
252 | clazz="selectionlist" |
---|
253 | required="true" |
---|
254 | current="<%=currentExtraValueType%>" |
---|
255 | recent="<%=recentExtraValueTypes%>" |
---|
256 | newitem="true" |
---|
257 | onselect="selectExtraValueTypeOnClick()" |
---|
258 | /> |
---|
259 | </td> |
---|
260 | </tr> |
---|
261 | |
---|
262 | <tr> |
---|
263 | <td class="prompt">Expression</td> |
---|
264 | <td> |
---|
265 | <select name="presets" style="width: 32em;" |
---|
266 | onchange="presetOnChange(this, this.form['parameter:expression'])" |
---|
267 | > |
---|
268 | <option value="">- select from list or enter formula below - |
---|
269 | <%=formulaOptions.toString()%> |
---|
270 | </select> |
---|
271 | </td> |
---|
272 | </tr> |
---|
273 | |
---|
274 | <tr valign="top"> |
---|
275 | <td> </td> |
---|
276 | <td> |
---|
277 | <table border="0" cellspacing="0" cellpadding="0"> |
---|
278 | <tr valign="top"> |
---|
279 | <td> |
---|
280 | <textarea class="text required" name="parameter:expression" |
---|
281 | rows="4" cols="50"><%=HTML.encodeTags(expression)%></textarea> |
---|
282 | </td> |
---|
283 | <td><base:button onclick="openExpressionBuilder()" |
---|
284 | title="Expression builder…" |
---|
285 | image="expression_builder.gif" |
---|
286 | tooltip="A simple utility for building expressions" /> |
---|
287 | </td> |
---|
288 | </tr> |
---|
289 | </table> |
---|
290 | </td> |
---|
291 | </tr> |
---|
292 | </table> |
---|
293 | </div> |
---|
294 | </form> |
---|
295 | |
---|
296 | <table align="center"> |
---|
297 | <tr> |
---|
298 | <td width="50%"><base:button onclick="doNext();" title="Next" /></td> |
---|
299 | <td width="50%"><base:button onclick="doCancel();" title="Cancel" /></td> |
---|
300 | </tr> |
---|
301 | </table> |
---|
302 | </base:body> |
---|
303 | </base:page> |
---|
304 | <% |
---|
305 | } |
---|
306 | finally |
---|
307 | { |
---|
308 | if (dc != null) dc.close(); |
---|
309 | }%> |
---|