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

Last change on this file since 4111 was 4111, checked in by Nicklas Nordborg, 15 years ago

Fixes #910: Plug-ins ignore file set by the auto-detect file format function

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