source: trunk/www/common/plugin/configure.jsp @ 3658

Last change on this file since 3658 was 3658, checked in by Nicklas Nordborg, 16 years ago

Show stacktrace when a plug-in reports an error

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 36.9 KB
Line 
1<%-- $Id: configure.jsp 3658 2007-08-13 09:44:15Z 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.BasicItem"
31  import="net.sf.basedb.core.Permission"
32  import="net.sf.basedb.core.Item"
33  import="net.sf.basedb.core.File"
34  import="net.sf.basedb.core.Nameable"
35  import="net.sf.basedb.core.Job"
36  import="net.sf.basedb.core.PluginDefinition"
37  import="net.sf.basedb.core.PluginConfiguration"
38  import="net.sf.basedb.core.PluginConfigurationRequest"
39  import="net.sf.basedb.core.RequestInformation"
40  import="net.sf.basedb.core.PluginParameter"
41  import="net.sf.basedb.core.ParameterType"
42  import="net.sf.basedb.core.StringParameterType"
43  import="net.sf.basedb.core.IntegerParameterType"
44  import="net.sf.basedb.core.LongParameterType"
45  import="net.sf.basedb.core.FloatParameterType"
46  import="net.sf.basedb.core.DoubleParameterType"
47  import="net.sf.basedb.core.ItemParameterType"
48  import="net.sf.basedb.core.DateParameterType"
49  import="net.sf.basedb.core.BooleanParameterType"
50  import="net.sf.basedb.core.FileParameterType"
51  import="net.sf.basedb.core.PathParameterType"
52  import="net.sf.basedb.core.ItemContext"
53  import="net.sf.basedb.core.Path"
54  import="net.sf.basedb.util.Enumeration"
55  import="net.sf.basedb.clients.web.Base"
56  import="net.sf.basedb.clients.web.WebException"
57  import="net.sf.basedb.clients.web.util.HTML"
58  import="net.sf.basedb.util.formatter.Formatter"
59  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
60  import="net.sf.basedb.clients.web.formatter.FormatterSettings"
61  import="net.sf.basedb.util.Values"
62  import="java.util.Date"
63  import="java.util.List"
64  import="java.util.Arrays"
65  import="java.util.Collections"
66%>
67<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
68<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
69<%
70final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
71final String ID = sc.getId();
72final float scale = Base.getScale(sc);
73final String clazz = "class=\"text\"";
74final String requiredClazz = "class=\"text required\"";
75
76final Item itemType = request.getParameter("item_type") == null ? null : Item.valueOf(request.getParameter("item_type"));
77final String subContext = Values.getString(request.getParameter("subcontext"), "");
78final ItemContext currentContext = itemType == null ? null : sc.getCurrentContext(itemType, subContext);
79DbControl dc = null;
80try
81{
82  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
83  String dateFormat = FormatterSettings.getDateFormat(sc);
84  String jsDateFormat = HTML.javaScriptEncode(dateFormat);
85  String htmlDateFormat = HTML.encodeTags(dateFormat);
86
87  dc = sc.newDbControl();
88  PluginConfigurationRequest pcRequest = (PluginConfigurationRequest)sc.getSessionSetting("plugin.configure.request");
89  if (pcRequest == null) throw new WebException("popup", "No request information found", "No request information found");
90 
91  PluginDefinition plugin = (PluginDefinition)sc.getSessionSetting("plugin.configure.plugin");
92  Job job = (Job)sc.getSessionSetting("plugin.configure.job");
93  dc.reattachItem(plugin);
94  boolean configureByExample = false;
95  PluginConfiguration pluginConfig = (PluginConfiguration)sc.getSessionSetting("plugin.configure.config");
96  String errorMessage = (String)sc.getSessionSetting("plugin.configure.errors.message");
97  List<Throwable> errors = (List<Throwable>)sc.getSessionSetting("plugin.configure.errors.list");
98 
99  RequestInformation ri = pcRequest.getRequestInformation();
100  List<PluginParameter<?>> parameters =  ri.getParameters();
101  String title = HTML.encodeTags(ri.getTitle());
102  String jobName = Values.getString(request.getParameter("job_name"), title);
103  StringBuilder sb = new StringBuilder();
104 
105  List<File> recentFiles = null;
106  %>
107
108  <base:page type="popup" title="<%=title%>">
109  <base:head scripts="plugin.js,parameters.js" styles="parameters.css">
110    <script language="JavaScript">
111    function init()
112    {
113      var width = Main.getWindowWidth();
114      var height = Main.getWindowHeight();
115      if (height < 600) height = 600;
116      if (width < 800) width = 800; // >
117      window.resizeTo(width, height);
118      <%
119      if (parameters != null && parameters.size() > 0)
120      {
121        for (PluginParameter<?> param : parameters)
122        {
123          ParameterType pType = param.getParameterType();
124          String name = param.getName();
125          if ("parserSection".equals(name)) 
126          {
127            configureByExample = plugin.supports("net.sf.basedb.util.parser.ConfigureByExample");
128          }
129          String label = HTML.encodeTags(Values.trimString(param.getLabel(), 30));
130          String fullLabel = HTML.encodeTags(param.getLabel());
131          if (pType != null)
132          {
133            // Get the current values... First we look in the http request object...
134            String[] requestValues = request.getParameterValues("parameter:"+param.getName());
135            // ...or in the current values from the job / plugin configuration
136            List values = requestValues != null ? Arrays.asList(requestValues) : pcRequest.getCurrentParameterValues(param.getName());
137            // Then, we check the parameters default value
138            if ((values == null || values.size() == 0) && param.getDefaultValue() != null)
139            {
140              values = Collections.singletonList(param.getDefaultValue());
141            }
142            // Item and File parameters will also look in the current context unless they are enumerated
143            if ((values == null || values.size() == 0) && 
144              !pType.isEnumeration() &&
145              (pType instanceof ItemParameterType || pType instanceof FileParameterType))
146            {
147              Item parameterItemType = Item.fromClass(pType.getParameterClass());
148              ItemContext cc = sc.getCurrentContext(parameterItemType, parameterItemType == itemType ? subContext : "");
149              if (cc.getId() != 0 && pType.getMultiplicity() == 1)
150              {
151                values = new java.util.ArrayList();
152                if (pType instanceof FileParameterType)
153                {
154                  try
155                  {
156                    values.add(File.getById(dc, cc.getId()).getPath().toString());
157                  }
158                  catch (Throwable t)
159                  {}
160                  if (currentContext != null && recentFiles == null)
161                  {
162                    recentFiles = (List<File>)currentContext.getRecent(dc, Item.FILE);
163                  }
164                }
165                else
166                {
167                  values.add(cc.getId());
168                }
169              }
170              else if (cc.getSelected().size() > 0 && pType.getMultiplicity() != 1)
171              {
172                values = new java.util.ArrayList(cc.getSelected());
173              }
174            }
175            // Finally, if the parameter has multiplicity=1, is requried and has a list of enumeration values
176            if ((values == null || values.size() == 0) && pType.getNotNull() && 
177              pType.getMultiplicity() == 1 && pType.getItems() != null && pType.getItems().size() > 0)
178            {
179              values = Collections.singletonList(pType.getItems().get(0)); 
180            }
181            String icon = "";
182            if (values != null && values.size() > 0)
183            {
184              icon = pType.getNotNull() ? "required_values.gif" : "notrequired_values.gif";
185            }
186            else
187            {
188              icon = pType.getNotNull() ? "required_novalues.gif" : "notrequired_novalues.gif";
189            }
190            if (!param.isHidden())
191            {
192              icon = "<span class=\"icon\"><img id=\"icon_"+name+"\" src=\"../../images/"+icon+"\"></span>";
193              sb.append("<div class=\"param\" id=\"prompt_"+name+"\" onclick=\"parametersOnClick('"+name+"')\"");
194              sb.append(" onmouseover=\"Main.addClass(this, 'hover')\" onmouseout=\"Main.removeClass(this, 'hover')\" title=\""+fullLabel+"\">");
195              sb.append(icon+"<span class=\"label\">"+label+"</span></div>\n");
196            }
197            %>
198            var values = new Array();
199            <%
200            if (values != null && values.size() > 0)
201            {
202              for (Object value : values)
203              {
204                if (value instanceof Date) 
205                {
206                  if (pType.isEnumeration())
207                  {
208                    value = ((Date)value).getTime();
209                  }
210                  else
211                  {
212                    value = dateFormatter.format((Date)value);
213                  }
214                }
215                else if (value instanceof File && pType instanceof FileParameterType)
216                {
217                  value = ((File)value).getPath().toString();
218                }
219                else if (value instanceof BasicItem)
220                {
221                  value = ((BasicItem)value).getId();
222                }
223                %>
224                values[values.length] = '<%=HTML.javaScriptEncode(value == null ? "" : value.toString())%>';
225                <%
226              }
227            }
228            %>
229            new Parameter('<%=name%>', '<%=HTML.javaScriptEncode(param.getLabel())%>', <%=pType.getMultiplicity()%>, <%=pType.isEnumeration()%>, <%=pType.getNotNull()%>, values);
230            <%
231          }
232          else
233          {
234            sb.append("<h4 class=\"param\" id=\"prompt_"+name+"\" title=\""+fullLabel+"\" onclick=\"parametersOnClick('"+name+"')\" onmouseover=\"Main.addClass(this, 'hover')\" onmouseout=\"Main.removeClass(this, 'hover')\">"+label+"</h4>");
235            %>
236            new Parameter('<%=name%>', '[<%=HTML.javaScriptEncode(param.getLabel())%>]', 1, 0, 0, {});
237            <%
238          }
239        }
240      }
241      %>
242    }
243   
244    var oldValueDiv;
245    function parametersOnClick(parameterId)
246    {
247      var frm = document.forms['configure'];
248      if (oldValueDiv) Main.hide(oldValueDiv);
249     
250      var pp = Parameters.allParameters['ID'+parameterId];
251      setSelectedParameter(pp, parameterId);
252      oldValueDiv = 'value_'+pp.name+'_div'
253      Main.show(oldValueDiv);
254      var valueElement = frm['value_'+pp.name];
255      if (valueElement.focus && !valueElement.disabled) valueElement.focus();
256      if (pp.enumeration)
257      {
258        Main.hide('valuecontainer');
259        var numSelected;
260        if (valueElement.type && valueElement.type.search('select') != -1)
261        {
262          numSelected = Forms.selectListOptions(valueElement, pp.values);
263        }
264        else if (pp.multiplicity == 1)
265        {
266          // radio buttons
267          numSelected = Forms.checkRadio(valueElement, pp.values[0]) == -1 ? 0 : 1;
268        }
269        else
270        {
271          // check boxes
272          numSelected = Forms.checkCheckBoxes(valueElement, pp.values);
273        }
274        if (numSelected == 0)
275        {
276          pp.values.length = 0;
277          updateSelectedStyle();
278        }
279      }
280      else if (pp.multiplicity == 1)
281      {
282        Main.hide('valuecontainer');
283        var currentValue = pp.values.length > 0 ? pp.values[0] : '';
284        if (valueElement.length) // ie. radio buttons for boolean parameter
285        {
286          Forms.checkRadio(valueElement, currentValue);
287        }
288        else if (!valueElement.disabled)
289        {
290          valueElement.value = currentValue;
291        }
292      }
293      else
294      {
295        var values = frm.values;
296        values.length = 0;
297        for (var i = 0; i < pp.values.length; i++) // >
298        {
299          var value = Main.cutString(pp.values[i].replace(/\n/g, ' '), 40);
300          values[values.length] = new Option(value);
301        }
302        var mult = document.getElementById('multiplicity');
303        mult.innerHTML = pp.multiplicity == 0 ? '' : '(Max '+pp.multiplicity+' values)';
304        Main.show('valuecontainer');
305      }
306    }
307   
308    var selectedPluginParameter = null;
309    var selectedPluginParameterId = null;
310    function getSelectedParameter()
311    {
312      return selectedPluginParameter;
313    }
314   
315    function setSelectedParameter(pluginParameter, parameterId)
316    {
317      if (selectedPluginParameter != null)
318      {
319        Main.removeClass(document.getElementById('prompt_'+selectedPluginParameter.name), 'selected');
320      }
321      selectedPluginParameter = pluginParameter;
322      selectedPluginParameterId = parameterId;
323      if (selectedPluginParameter != null)
324      {
325        Main.addClass(document.getElementById('prompt_'+selectedPluginParameter.name), 'selected');
326      }
327    }
328
329    function updateStyle(pp)
330    {
331      var icon = document.getElementById('icon_'+pp.name);
332      var gif = getRoot()+'images/';
333      if (pp.values.length == 0)
334      {
335        gif += pp.required ? 'required_novalues.gif' : 'notrequired_novalues.gif';
336      }
337      else
338      {
339        gif += pp.required ? 'required_values.gif' : 'notrequired_values.gif';
340      }
341      icon.src = gif;
342    }
343
344    function updateSelectedStyle()
345    {
346      updateStyle(getSelectedParameter());
347    }
348   
349    function setCurrentValue(value)
350    {
351      var pp = getSelectedParameter();
352      if (value == null || value == '')
353      {
354        pp.removeValue(0);
355      }
356      else
357      {
358        pp.updateValue(0, value);
359      }
360      updateSelectedStyle();
361    }
362   
363    function setEnumValues(name)
364    {
365      var pp = getSelectedParameter();
366      if (!pp) return;
367   
368      var frm = document.forms['configure'];
369      var valueElement = frm[name];
370      var values = new Array();
371      for (var i = 0; i < valueElement.length; i++) // >
372      {
373        if (valueElement[i].checked || valueElement[i].selected)
374        {
375          values[values.length] = valueElement[i].value;
376        }
377      }
378      pp.setValues(values);
379      updateSelectedStyle();
380    }
381
382    var lastValueIndex = -1;
383    function valuesOnClick()
384    {
385      var frm = document.forms['configure'];
386      var pp = getSelectedParameter();
387      lastValueIndex = frm.values.selectedIndex;
388      if (lastValueIndex >= 0)
389      {
390        frm['value_'+pp.name].value = pp.values[lastValueIndex];
391      }
392    }
393
394    function valueOnBlur(value)
395    {
396      var pp = getSelectedParameter();
397      if (!pp) return;
398      if (pp.multiplicity == 1)
399      {
400        setCurrentValue(value);
401      }
402      else
403      {
404        if (lastValueIndex < 0) return; // >
405        var frm = document.forms['configure'];
406        if (value == '' || value == null)
407        {
408          pp.removeValue(lastValueIndex);
409          frm.values[lastValueIndex] = null;
410        }
411        else
412        {
413          pp.updateValue(lastValueIndex, value);
414          frm.values[lastValueIndex].text = value;
415        }
416      }
417    }
418    function addOnClick()
419    {
420      var pp = getSelectedParameter();
421      if (!pp) return;
422      var frm = document.forms['configure'];
423      var valueElement = frm['value_'+pp.name];
424      if (frm.values.selectedIndex < 0 && valueElement.value != '') // >
425      {
426        if (pp.addValue(valueElement.value))
427        {
428          lastValueIndex = frm.values.length;
429          frm.values[lastValueIndex] = new Option(valueElement.value, '', false, false);
430          valueElement.value = '';
431          lastValueIndex = -1;
432        }
433      }
434      else
435      {
436        if (pp.addValue(''))
437        {
438          lastValueIndex = frm.values.length;
439          frm.values[lastValueIndex] = new Option('<new>', '', false, true);
440          valueElement.value = '';
441        }
442      }
443      valueElement.focus();
444      updateSelectedStyle();
445    }
446    function removeOnClick()
447    {
448      var pp = getSelectedParameter();
449      if (!pp) return;
450     
451      var frm = document.forms['configure'];
452      var values = frm.values;
453      for (var i = 0; i < values.length; i++) // >
454      {
455        if (values[i].selected)
456        {
457          pp.removeValue(i);
458          values[i] = null;
459          i--;
460        }
461      }
462      updateSelectedStyle();
463    }
464    function setDateCallback(frmName, inputName, theDate)
465    {
466      var frm = document.forms[frmName];
467      frm[inputName].value = theDate;
468      valueOnBlur(theDate);
469    }
470    var lastFileInputName;
471    function browseOnClick(inputName)
472    {
473      var frm = document.forms['configure'];
474      var url = '../../filemanager/index.jsp?ID=<%=ID%>&cmd=SelectOne&callback=setFileCallback';
475      lastFileInputName = inputName;
476      Main.openPopup(url, 'SelectFile', 1000, 700);
477    }
478    function setFileCallback(fileId, path)
479    {
480      var frm = document.forms['configure'];
481      frm[lastFileInputName].value = path;
482      valueOnBlur(path);
483    }
484   
485    function recentOnChange(inputName)
486    {
487      var frm = document.forms['configure'];
488      var recentList = frm['recent.'+inputName];
489      var path = recentList[recentList.selectedIndex].text;
490      frm[inputName].value = path;
491      valueOnBlur(path);
492      recentList.selectedIndex = 0;
493    }
494   
495    var lastItemInputName;
496    function selectItemOnClick(inputName, itemType)
497    {
498      lastItemInputName = inputName;
499      Main.selectItem('<%=ID%>', itemType, 'selectone', 'selectItemCallback');
500    }
501    function selectItemCallback(itemId, name)
502    {
503      var frm = document.forms['configure'];
504      frm[lastItemInputName].value = name;
505      setCurrentValue(itemId);
506    }
507    function clearItemOnClick(inputName, itemType)
508    {
509      var frm = document.forms['configure'];
510      frm[inputName].value = '';
511      setCurrentValue();
512    }
513   
514    function saveAsOnClick(inputName)
515    {
516      var frm = document.forms['configure'];
517      var url = '../../filemanager/index.jsp?ID=<%=ID%>&cmd=SaveAs&callback=saveAsCallback';
518      lastFileInputName = inputName;
519      Main.openPopup(url, 'SaveAs', 1000, 700);
520    }
521    function saveAsCallback(path)
522    {
523      var frm = document.forms['configure'];
524      frm[lastFileInputName].value = path;
525      valueOnBlur(path);
526    }
527    function selectDirectoryOnClick(inputName)
528    {
529      var frm = document.forms['configure'];
530      var url = '../../filemanager/directories/index.jsp?ID=<%=ID%>&mode=selectonedirectory&callback=setFileCallback';
531      lastFileInputName = inputName;
532      Main.openPopup(url, 'SelectDirectory', 350, 500);
533    }
534   
535    function hideErrorList()
536    {
537      Main.hide('errorlist');
538      Main.show('showerrorlist');
539    }
540    function showErrorList()
541    {
542      Main.show('errorlist');
543      Main.hide('showerrorlist');
544    }
545   
546    function saveSettings()
547    {
548      var frm = document.forms['configure'];
549      for (var i = 0; i < Parameters.allParameters.length; i++) // > 
550      {
551        var pp = Parameters.allParameters[i];
552        if (pp.required && pp.values.length == 0)
553        {
554          alert('No value entered for parameter '+pp.label);
555          return;
556        }
557      }
558      Parameters.addParameterValuesToForm(frm);
559      //Main.openPopup('', 'SubmitPluginParameters', 100, 100);
560      //frm.target = 'SubmitPluginParameters';
561      frm.submit();
562    }
563   
564    function doCancel()
565    {
566      location = 'index.jsp?ID=<%=ID%>&cmd=CancelWizard';
567    }
568   
569    function testWithFile()
570    {
571      Main.openPopup('test_with_file.jsp?ID=<%=ID%>', 'TestWithFile', 1000, 800);
572    }
573   
574    function getParameterValue(ID)
575    {
576      var param = Parameters.allParameters['ID'+ID];
577      if (param)
578      {
579        return param.values;
580      }
581      else
582      {
583        return '';
584      }
585    }
586   
587    function setParameterValue(ID, value)
588    {
589      var param = Parameters.allParameters['ID'+ID];
590      if (param)
591      {
592        if (value == null || Main.trimString(value) == '')
593        {
594          param.clearValues();
595        }
596        else
597        {
598          var values = new Array();
599          values[values.length] = value;
600          param.setValues(values);
601        }
602        var selected = getSelectedParameter();
603        if (selected && selected.name == param.name)
604        {
605          parametersOnClick(param.name);
606        }
607        updateStyle(param);
608      }
609    }
610    </script>
611  </base:head>
612  <base:body onload="init()">
613    <p>
614    <form action="index.jsp?ID=<%=ID%>" method="post" name="configure" onsubmit="return false;">
615    <input type="hidden" name="cmd" value="SetParameters">
616    <input type="hidden" name="title" value="<%=title%>">
617    <input type="hidden" name="requestId" value="<%=request.getParameter("requestId")%>">
618    <%
619    if (itemType != null)
620    {
621      %>
622      <input type="hidden" name="item_type" value="<%=itemType.name()%>">
623      <%
624    }
625    %>
626    <input type="hidden" name="subcontext" value="<%=subContext%>">
627   
628    <h3 class="docked"><%=title%> <base:help 
629      helpid="<%="runplugin.configure"+(job != null ? "." + plugin.getMainType().name().toLowerCase() : "") %>" /></h3>
630    <div class="boxed">
631   
632      <table class="form">
633      <tr valign="baseline">
634        <td class="prompt">Plugin</td>
635        <td><%=plugin == null ? "<i>- none -</i>" : HTML.encodeTags(plugin.getName())%></td>
636        <td class="prompt">Configuration</td>
637        <td><%=pluginConfig == null ? "<i>- none -</i>" : HTML.encodeTags(pluginConfig.getName())%></td>
638      </tr>
639      </table>
640   
641      <div class="pluginhelp">
642        <%=HTML.niceFormat(ri.getDescription())%>
643      </div>
644
645      <table class="form" cellspacing="0" border="0" cellpadding="0" width="100%">
646      <tr valign="top">
647        <td nowrap style="width: 240px">
648          <div class="parameterlist" style="height: <%=(int)(scale*320)%>px; width:240px;">
649          <%=sb.toString()%>
650          </div>
651          <base:icon image="hasvalues.gif" /> = has value(s), <base:icon image="required.gif" /> = required
652        </td>
653       
654        <td>
655          <%
656          if (errorMessage != null || (errors != null && errors.size() > 0))
657          {
658            %>
659            <div id="errors" style="margin-bottom: 12px;" class="parameterhelp">
660              <div class="error" style="margin: 0px;">
661              <%=errorMessage %>
662              </div>
663              <%
664              if (errors != null && errors.size() > 0)
665              {
666                %>
667                <div id="showerrorlist" style="display: none;">
668                  <base:icon image="bullet.gif" /><a href="javascript:showErrorList()">Show details</a>
669                </div>
670                <div id="errorlist">
671                <ol>
672                <%
673                int i = 0;
674                java.io.PrintWriter pw = new java.io.PrintWriter(out);
675                for (Throwable t : errors)
676                {
677                  ++i;
678                  t.printStackTrace();
679                  StackTraceElement[] st = t.getStackTrace();
680                  %>
681                  <li><%=t.getMessage()%> 
682                    <br>
683                    (<a href="javascript:Main.showHide('stacktrace.<%=i%>')" title="Show/hide stacktrace">+</a>)
684                    <div id="stacktrace.<%=i%>" style="display:none; font-size: smaller;">
685                    <%
686                    out.print("<pre>");
687                    while (t != null)
688                    {
689                      out.println(t.toString());
690                      for (int index = 0; index < st.length; ++index)
691                      {
692                        out.print("...at ");
693                        out.println(st[index].toString());
694                      }
695                      t = t.getCause();
696                      if (t != null) out.print("\nCaused by: ");
697                    }
698                    %>
699                    </pre>
700                    </div>
701                  <%
702                }
703                %>
704                </ol>
705                <base:icon image="bullet.gif" /><a href="javascript:hideErrorList()">Hide details</a>
706                </div>
707                <%
708              }
709              %>
710            </div>
711            <%
712          }
713          %>
714       
715          <div id="valuecontainer" style="display: none;">
716          <table cellspacing="2" border="0" cellpadding="0" cellspacing="0">
717            <tr valign="top">
718            <td>
719              <b>Values</b> <span id="multiplicity"></span><br>
720              <select name="values" size="5" style="width: 20em;"
721                onchange="valuesOnClick()" multiple>
722              </select>
723            </td>
724            <td>&nbsp;</td>
725            <td>
726            <td>
727              <br>
728              <base:button onclick="addOnClick()" title="Add" />
729              <base:button onclick="removeOnClick()" title="Remove" />
730            </td>
731          </table>
732          </div>
733
734          <%
735          if (parameters != null && parameters.size() > 0)
736          {
737            for (PluginParameter<?> param : parameters)
738            {
739              if (!param.isHidden())
740              {
741                ParameterType pType = param.getParameterType();
742                String inputName = "value_"+param.getName();
743                if (pType != null)
744                {
745                  int multiplicity = pType.getMultiplicity();
746                  String select = null;
747                  if (multiplicity == 0)
748                  {
749                    if (pType.getNotNull())
750                    {
751                      select = "Select one or more";
752                    }
753                    else
754                    {
755                      select = "Select zero or more";
756                    }
757                  }
758                  else if (multiplicity == 1)
759                  {
760                    select = "Select one";
761                  }
762                  else
763                  {
764                    if (pType.getNotNull())
765                    {
766                      select = "Select 1 -- " + multiplicity;
767                    }
768                    else
769                    {
770                      select = "Select 0 -- " + multiplicity;
771                    }
772                  }
773                  %>
774                  <div id="<%=inputName%>_div" style="display: none;">
775                  <%
776                  if (pType.isEnumeration())
777                  {
778                    Enumeration<?, String> enumeration = pType.getEnumeration();
779                    List<?> values = pType.getItems();
780                    %>
781                    <b><%=HTML.encodeTags(param.getLabel())%></b> (<%=select%>)<br>
782                    <%
783                    if (multiplicity == 1)
784                    {
785                      %>
786                      <select name="<%=inputName%>"
787                        onchange="setCurrentValue(this[this.selectedIndex].value)">
788                      <%
789                      if (!pType.getNotNull())
790                      {
791                        %>
792                        <option value="" style="font-style: italic;">- not specified -
793                        <%
794                      }
795                    }
796                    else
797                    {
798                      %>
799                      <select name="<%=inputName%>" multiple size="10" style="width: 30em;"
800                        onchange="setEnumValues('<%=inputName%>')">
801                      <%
802                    }
803                    for (int i = 0; i < values.size(); ++i)
804                    {
805                      Object value;
806                      String listValue = "";
807                      String listText = "";
808                      String listTitle = "";
809                      if (enumeration != null)
810                      {
811                        value = enumeration.getKey(i);
812                        listText = HTML.encodeTags(enumeration.getValue(i));
813                      }
814                      else
815                      {
816                        value = values.get(i);
817                      }
818                      if (value instanceof Date) 
819                      {
820                        listValue = Long.toString(((Date)value).getTime());
821                        if (enumeration == null) listText = dateFormatter.format((Date)value);
822                      }
823                      else if (value instanceof BasicItem)
824                      {
825                        BasicItem item = (BasicItem)value;
826                        listValue = Integer.toString(item.getId());
827                        if (item instanceof Nameable)
828                        {
829                          Nameable nameable = (Nameable)item;
830                          if (enumeration == null) listText = HTML.encodeTags(nameable.getName());
831                          listTitle = HTML.encodeTags(nameable.getDescription());
832                        }
833                        else
834                        {
835                          if (enumeration == null) listText = HTML.encodeTags(item.toString());
836                        }
837                      }
838                      else
839                      {
840                        listValue = HTML.encodeTags(value == null ? "" : value.toString());
841                        if (enumeration == null) listText = listValue;
842                      }
843                      %>
844                      <option value="<%=listValue%>" title="<%=listTitle%>"><%=listText%>
845                      <%
846                    }
847                    %>
848                    </select>
849                    <%
850                  }
851                  else if (pType instanceof StringParameterType)
852                  {
853                    Integer maxLength = ((StringParameterType)pType).getMaxLength();
854                    int width = pType.getWidth() <= 0 ? 40 : pType.getWidth();
855                    if (width > 80) width = 80;
856                    int height = pType.getHeight() <= 0 ? 6 : pType.getHeight();
857                    if (height > 20) height = 20;
858                    if (maxLength == null || maxLength > 255)
859                    {
860                      %>
861                      <b><%=HTML.encodeTags(param.getLabel())%></b> (Text)<br>
862                      <textarea <%=pType.getNotNull() ? requiredClazz : clazz%> 
863                        name="<%=inputName%>" rows="<%=height%>" cols="<%=width%>"
864                        onblur="valueOnBlur(this.value)"></textarea>
865                      <a href="javascript:Main.zoom('<%=HTML.javaScriptEncode(param.getLabel())%>', 'configure', '<%=inputName%>')" 
866                        title="Edit in larger window"><base:icon image="zoom.gif" /></a>
867                      <%
868                    }
869                    else
870                    {
871                      %>
872                      <b><%=HTML.encodeTags(param.getLabel())%></b> (String)<br>
873                      <input <%=pType.getNotNull() ? requiredClazz : clazz%> type="text" 
874                        name="<%=inputName%>" value=""
875                        size="<%=width%>" maxlength="<%=maxLength%>"
876                        onblur="valueOnBlur(this.value)">
877                      <%
878                    }
879                  }
880                  else if (pType instanceof IntegerParameterType)
881                  {
882                    IntegerParameterType ipType = (IntegerParameterType)pType;
883                    Integer minValue = ipType.getLowerLimit();
884                    Integer maxValue = ipType.getUpperLimit();
885                    String minMax = "";
886                    if (minValue != null && maxValue != null)
887                    {
888                      minMax = ": " + minValue + " -- " +maxValue;
889                    }
890                    else if (minValue != null)
891                    {
892                      minMax = " >= "+minValue;
893                    }
894                    else if (maxValue != null)
895                    {
896                      minMax = " <= "+maxValue;
897                    }
898                    %>
899                    <b><%=HTML.encodeTags(param.getLabel())%></b> (Integer<%=minMax%>)<br>
900                    <input <%=pType.getNotNull() ? requiredClazz : clazz%>
901                      type="text" name="<%=inputName%>" value=""
902                      size="20" maxlength="20" onkeypress="return Numbers.integerOnly(event)"
903                      onblur="valueOnBlur(this.value)">
904                    <%
905                  }
906                  else if (pType instanceof LongParameterType)
907                  {
908                    LongParameterType ipType = (LongParameterType)pType;
909                    Long minValue = ipType.getLowerLimit();
910                    Long maxValue = ipType.getUpperLimit();
911                    String minMax = "";
912                    if (minValue != null && maxValue != null)
913                    {
914                      minMax = ": " + minValue + " -- " +maxValue;
915                    }
916                    else if (minValue != null)
917                    {
918                      minMax = " >= "+minValue;
919                    }
920                    else if (maxValue != null)
921                    {
922                      minMax = " <= "+maxValue;
923                    }
924                    %>
925                    <b><%=HTML.encodeTags(param.getLabel())%></b> (Long<%=minMax%>)<br>
926                    <input <%=pType.getNotNull() ? requiredClazz : clazz%>
927                      type="text" name="<%=inputName%>" value=""
928                      size="20" maxlength="20" onkeypress="return Numbers.integerOnly(event)"
929                      onblur="valueOnBlur(this.value)">
930                    <%
931                  }
932                  else if (pType instanceof FloatParameterType)
933                  {
934                    FloatParameterType ipType = (FloatParameterType)pType;
935                    Float minValue = ipType.getLowerLimit();
936                    Float maxValue = ipType.getUpperLimit();
937                    String minMax = "";
938                    if (minValue != null && maxValue != null)
939                    {
940                      minMax = ": " + minValue + " -- " +maxValue;
941                    }
942                    else if (minValue != null)
943                    {
944                      minMax = " >= "+minValue;
945                    }
946                    else if (maxValue != null)
947                    {
948                      minMax = " <= "+maxValue;
949                    }
950                    %>
951                    <b><%=HTML.encodeTags(param.getLabel())%></b> (Float<%=minMax%>)<br>
952                    <input <%=pType.getNotNull() ? requiredClazz : clazz%>
953                      type="text" name="<%=inputName%>" value=""
954                      size="20" maxlength="20" onkeypress="return Numbers.numberOnly(event)"
955                      onblur="valueOnBlur(this.value)">
956                    <%
957                  }
958                  else if (pType instanceof DoubleParameterType)
959                  {
960                    DoubleParameterType ipType = (DoubleParameterType)pType;
961                    Double minValue = ipType.getLowerLimit();
962                    Double maxValue = ipType.getUpperLimit();
963                    String minMax = "";
964                    if (minValue != null && maxValue != null)
965                    {
966                      minMax = ": " + minValue + " -- " +maxValue;
967                    }
968                    else if (minValue != null)
969                    {
970                      minMax = " >= "+minValue;
971                    }
972                    else if (maxValue != null)
973                    {
974                      minMax = " <= "+maxValue;
975                    }
976                    %>
977                    <b><%=HTML.encodeTags(param.getLabel())%></b> (Double<%=minMax%>)<br>
978                    <input <%=pType.getNotNull() ? requiredClazz : clazz%>
979                      type="text" name="<%=inputName%>" value=""
980                      size="20" maxlength="20" onkeypress="return Numbers.numberOnly(event)"
981                      onblur="valueOnBlur(this.value)">
982                    <%
983                  }
984                  else if (pType instanceof DateParameterType)
985                  {
986                    %>
987                    <table>
988                    <tr>
989                    <td>
990                      <b><%=HTML.encodeTags(param.getLabel())%></b> (Date)<br>
991                      <input <%=pType.getNotNull() ? requiredClazz : clazz%>
992                        type="text" name="<%=inputName%>" value=""
993                        size="20" maxlength="20" title="Enter date in format: <%=htmlDateFormat%>"
994                        onblur="valueOnBlur(this.value)">
995                    </td>
996                    <td>
997                      <br>
998                      <base:button 
999                        onclick="<%="Dates.selectDate('Value', 'configure', '"+inputName+"', 'setDateCallback', '"+jsDateFormat+"')"%>" 
1000                        image="calendar.png"
1001                        title="Calendar&hellip;" 
1002                        tooltip="Select a date from a calendar" 
1003                      />
1004                    </td>
1005                    </tr>
1006                    </table>
1007                    <%
1008                  }
1009                  else if (pType instanceof BooleanParameterType)
1010                  {
1011                    %>
1012                    <b><%=HTML.encodeTags(param.getLabel())%></b><br>
1013                    <input type="radio" name="<%=inputName%>" value="" checked
1014                      onclick="setCurrentValue(null)"><a
1015                      href="javascript:document.forms['configure'].<%=inputName%>[0].click()"><i>- not specified -</i></a><br>
1016                    <input type="radio" name="<%=inputName%>" value="true" 
1017                      onclick="setCurrentValue('true')"><a
1018                      href="javascript:document.forms['configure'].<%=inputName%>[1].click()">true</a><br>
1019                    <input type="radio" name="<%=inputName%>" value="false" 
1020                      onclick="setCurrentValue('false')"><a
1021                      href="javascript:document.forms['configure'].<%=inputName%>[2].click()">false</a>
1022                    <%
1023                  }
1024                  else if (pType instanceof FileParameterType)
1025                  {
1026                    %>
1027                    <b><%=HTML.encodeTags(param.getLabel())%></b><br>
1028                    <table border="0" cellspacing="0" cellpadding="0">
1029                    <tr>
1030                    <td><input <%=pType.getNotNull() ? requiredClazz : clazz%> type="text" 
1031                      name="<%=inputName%>" value=""
1032                      size="50"
1033                      onblur="valueOnBlur(this.value)">&nbsp;</td>
1034                    <td><base:button 
1035                        title="Browse&hellip;"
1036                        onclick="<%="browseOnClick('"+inputName+"')"%>"
1037                        />
1038                    </td>
1039                    </tr>
1040                    </table>
1041                    <%
1042                    if (recentFiles != null && recentFiles.size() > 0)
1043                    {
1044                      %>
1045                      <b>Recently used</b><br>
1046                      <select name="recent.<%=inputName%>" onchange="recentOnChange('<%=inputName%>')">
1047                      <option value="">
1048                      <%
1049                      for (File recent : recentFiles)
1050                      {
1051                        %>
1052                        <option value="<%=recent.getId()%>"><%=HTML.encodeTags(recent.getPath().toString())%>
1053                        <%
1054                      }
1055                      %>
1056                      </select>
1057                      <%
1058                    }
1059                  }
1060                  else if (pType instanceof ItemParameterType)
1061                  {
1062                    Item parameterItemType = Item.fromClass(pType.getParameterClass());
1063                    BasicItem item = (BasicItem)pcRequest.getCurrentParameterValue(param.getName());
1064                    if (item == null)
1065                    {
1066                      ItemContext cc = sc.getCurrentContext(parameterItemType, parameterItemType == itemType ? subContext : "");
1067                      if (cc.getId() != 0)
1068                      {
1069                        try
1070                        {
1071                          item = parameterItemType.getById(dc, cc.getId());
1072                        }
1073                        catch (Throwable t)
1074                        {}
1075                      }
1076                    }
1077                    if (item != null)
1078                    {
1079                      String display = "";
1080                      if (item instanceof Nameable)
1081                      {
1082                        Nameable nameable = (Nameable)item;
1083                        display = nameable.getName();
1084                      }
1085                      else 
1086                      {
1087                        display = item.toString();
1088                      }
1089                      %>
1090                      <b><%=HTML.encodeTags(param.getLabel())%></b><br>
1091                      <table border="0" cellspacing="2" cellpadding="0">
1092                      <tr>
1093                      <td><input class="text disabled" size="50" 
1094                        name="<%=inputName%>" type="text" disabled
1095                        value="<%=HTML.encodeTags(display)%>"></td>
1096                      <td><base:button title="Select&hellip;"
1097                          onclick="<%="selectItemOnClick('"+inputName+"', '" + parameterItemType.name() + "')"%>"
1098                          visible="false" /></td>
1099                      <td><base:button title="Clear"
1100                          onclick="<%="clearItemOnClick('"+inputName+"', '" + parameterItemType.name() + "')"%>"
1101                          visible="false" /></td>
1102                      </tr>
1103                      </table>
1104                      <%
1105                    }
1106                  }
1107                  else if (pType instanceof PathParameterType)
1108                  {
1109                    PathParameterType ppType = (PathParameterType)pType;
1110                    String browse = "";
1111                    if (ppType.getPathType() == Path.Type.FILE)
1112                    {
1113                      browse = "saveAsOnClick('" + inputName + "')";
1114                    }
1115                    else
1116                    {
1117                      browse = "selectDirectoryOnClick('" + inputName + "')";
1118                    }
1119                    %>
1120                    <b><%=HTML.encodeTags(param.getLabel())%></b><br>
1121                    <table border="0" cellspacing="0" cellpadding="0">
1122                    <tr>
1123                    <td>
1124                      <input type="text" class="text" name="<%=inputName%>" size="40" value=""
1125                        onblur="valueOnBlur(this.value)">&nbsp;</td>
1126                    <td><base:button 
1127                        title="Browse&hellip;"
1128                        onclick="<%=browse%>"
1129                        />
1130                    </td>
1131                    </tr>
1132                    </table>
1133                    <%
1134                  }
1135                  else
1136                  {
1137                    %>
1138                    <b><%=HTML.encodeTags(param.getLabel())%></b><br>
1139                    <%
1140                  }
1141                  %>
1142                  <br>
1143                  <div class="parameterhelp">
1144                  <%=HTML.niceFormat(param.getDescription())%>
1145                  </div>
1146                  </div>
1147                  <%
1148                }
1149                else
1150                {
1151                  %>
1152                  <div id="<%=inputName%>_div" style="display: none;" class="parameterhelp">
1153                  <%=HTML.niceFormat(param.getDescription())%>
1154                  </div>
1155                  <%
1156                }
1157              }
1158            }
1159          }
1160          %>
1161        </td>
1162      </tr>
1163      </table>
1164      </div>
1165    </form>
1166    <div align="center">
1167    <base:buttongroup>
1168      <base:button onclick="testWithFile()" title="Test with file&hellip;" image="file.gif"
1169        tooltip="Use an uploaded file to create the regular expressions and column mappings"
1170        visible="<%=configureByExample%>" />
1171      <base:button onclick="saveSettings()" title="Next" />
1172      <base:button onclick="doCancel()" title="Cancel" />
1173    </base:buttongroup>
1174    </div>
1175  </base:body>
1176  </base:page>
1177  <%
1178}
1179finally
1180{
1181  if (dc != null) dc.close();
1182}
1183%>
Note: See TracBrowser for help on using the repository browser.