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

Last change on this file since 2992 was 2992, checked in by Johan Enell, 16 years ago

Merged log:branches/2.1#2846:2990 trunk.

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