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

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

Fixes #681

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