Changeset 3880


Ignore:
Timestamp:
Oct 8, 2010, 10:58:28 AM (13 years ago)
Author:
Gregory Vincic
Message:

Refs #698. Removed method getSecondaryExtractForm() from FormFactory.

Location:
trunk/client/servlet/src/org/proteios
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/client/servlet/src/org/proteios/action/extract/AddSecondaryExtract.java

    r3829 r3880  
    11/*
    2  $Id$
    3  
    4  Copyright (C) 2008 Gregory Vincic
    5  
    6  Files are copyright by their respective authors. The contributions to
    7  files where copyright is not explicitly stated can be traced with the
    8  source code revision system.
    9  
    10  This file is part of Proteios.
    11  Available at http://www.proteios.org/
    12  
    13  Proteios is free software; you can redistribute it and/or
    14  modify it under the terms of the GNU General Public License
    15  as published by the Free Software Foundation; either version 2
    16  of the License, or (at your option) any later version.
    17  
    18  Proteios is distributed in the hope that it will be useful,
    19  but WITHOUT ANY WARRANTY; without even the implied warranty of
    20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    21  GNU General Public License for more details.
    22  
    23  You should have received a copy of the GNU General Public License
    24  along with this program; if not, write to the Free Software
    25  Foundation, Inc., 59 Temple Place - Suite 330,
    26  Boston, MA  02111-1307, USA.
    27  */
     2    $Id$
     3    
     4    Copyright (C) 2008 Gregory Vincic
     5    
     6    Files are copyright by their respective authors. The contributions to
     7    files where copyright is not explicitly stated can be traced with the
     8    source code revision system.
     9    
     10    This file is part of Proteios.
     11    Available at http://www.proteios.org/
     12    
     13    Proteios is free software; you can redistribute it and/or
     14    modify it under the terms of the GNU General Public License
     15    as published by the Free Software Foundation; either version 2
     16    of the License, or (at your option) any later version.
     17    
     18    Proteios is distributed in the hope that it will be useful,
     19    but WITHOUT ANY WARRANTY; without even the implied warranty of
     20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     21    GNU General Public License for more details.
     22    
     23    You should have received a copy of the GNU General Public License
     24    along with this program; if not, write to the Free Software
     25    Foundation, Inc., 59 Temple Place - Suite 330,
     26    Boston, MA  02111-1307, USA.
     27*/
    2828package org.proteios.action.extract;
    2929
     
    3838
    3939/**
    40  * @author olle
    41  */
     40    Creates a new extract from an already existing extract
     41*/
    4242public class AddSecondaryExtract
    43     extends ProteiosAction<AddSecondaryExtract>
     43extends ProteiosAction<AddSecondaryExtract>
    4444{
    45   @Override
    46   protected void runMe()
    47       throws ActionException, InvalidParameterValue
    48   {
    49     /***********************************************************************
    50      * Verify parameters
    51      */
    52     Form form = getFormFactory().getSecondaryExtractForm(null, null);
    53     verifyParameters(form);
    54     verifySessionAttributes(ViewActiveExtract.VEXTRACTID);
    55     /***********************************************************************
    56      * Get values
    57      */
    58     Float extractQuantity = getFloat(FormFactory.VORIGINALQUANTITY);
    59     Float usedQuantity = getFloat(FormFactory.VQUANTITY);
    60     /***********************************************************************
    61      * Sample
    62      */
    63     Integer extractId = getSessionAttribute(ViewActiveExtract.VEXTRACTID);
    64     DbControl dc = newDbControl();
    65     ItemFactory factory = getItemFactory(dc);
    66     Extract sourceExtract = extractId == null ? null : factory.getById(
    67       Extract.class, extractId);
    68     /***********************************************************************
    69      * Create secondary extract
    70      */
    71     Extract extract = factory.create(Extract.class);
    72     dc.saveItem(extract);
    73     CreationEvent creation = factory.createCreationEvent(extract,
    74       sourceExtract, usedQuantity);
    75     dc.saveItem(creation);
    76     creation.setComment("Extraction");
    77     //
    78     String name = getString(NameField.VPARAM);
    79     extract.setName(name);
    80     //
    81     String externalId = getString(ExternalIdField.VPARAM);
    82     extract.setExternalId(externalId);
    83     //
    84     extract.setDescription(getString(DescriptionField.VPARAM));
    85     //
    86     String storageLocation = getString(StorageLocationField.VPARAM);
    87     extract.setStorageLocation(storageLocation);
    88     //
    89     extract.setOriginalQuantityInMicroLiters(extractQuantity);
    90     extract
    91       .setConcentrationInGramsPerLiter(getValidFloat(ConcentrationField.VPARAM));
    92     dc.commit();
    93     setMessage("Extract saved");
    94     setSessionAttribute(ViewActiveExtract.VEXTRACTID,
    95       extract.getId());
    96     setForwardTo(ViewActiveExtract.class);
    97   }
     45    @Override
     46    protected void runMe()
     47    throws ActionException, InvalidParameterValue
     48    {
     49        ExtractForm form;
     50        Float usedQuantity;
     51        Integer extractId;
     52        DbControl dc;
     53        ItemFactory factory;
     54        Extract sourceExtract;
     55        Extract extract;
     56        CreationEvent creation;
     57       
     58        form = new ExtractForm();
     59        verifyParameters(form);
     60        populateForm(form); // Let's us get the values below
     61        verifySessionAttributes(ViewActiveExtract.VEXTRACTID);
     62        extractId = getSessionAttribute(ViewActiveExtract.VEXTRACTID);
     63
     64        // Find parent extract object
     65        dc = newDbControl();
     66        factory = getItemFactory(dc);
     67        // TODO if there is no parent extract this action should fail here
     68        sourceExtract = extractId == null ? null : factory.getById(Extract.class, extractId);
     69       
     70        // Create secondary extract
     71        extract = factory.create(Extract.class);
     72        dc.saveItem(extract); // Required so we can create a new CreationEvent
     73        usedQuantity = getFloat(FormFactory.VQUANTITY);
     74        creation = factory.createCreationEvent(extract, sourceExtract, usedQuantity);
     75        dc.saveItem(creation);
     76        creation.setComment("Extraction");
     77       
     78        // Set values taken from the populated form
     79        extract.setName(form.nameF.getValue());
     80        extract.setExternalId(form.externalIdF.getValue());
     81        extract.setDescription(form.descriptionF.getValue());
     82        extract.setStorageLocation(form.storageLocationF.getValue());
     83        extract.setOriginalQuantityInMicroLiters(form.originalQuantityF.getValue());
     84        extract.setConcentrationInGramsPerLiter(form.concF.getValue());
     85        dc.commit();
     86        setMessage("Extract saved");
     87
     88        // View the newly created extract
     89        setSessionAttribute(ViewActiveExtract.VEXTRACTID, extract.getId());
     90        setForwardTo(ViewActiveExtract.class);
     91    }
    9892}
  • trunk/client/servlet/src/org/proteios/action/extract/NewSecondaryExtract.java

    r2491 r3880  
    11/*
    2  $Id$
    3  
    4  Copyright (C) 2008 Gregory Vincic
    5  
    6  Files are copyright by their respective authors. The contributions to
    7  files where copyright is not explicitly stated can be traced with the
    8  source code revision system.
    9  
    10  This file is part of Proteios.
    11  Available at http://www.proteios.org/
    12  
    13  Proteios is free software; you can redistribute it and/or
    14  modify it under the terms of the GNU General Public License
    15  as published by the Free Software Foundation; either version 2
    16  of the License, or (at your option) any later version.
    17  
    18  Proteios is distributed in the hope that it will be useful,
    19  but WITHOUT ANY WARRANTY; without even the implied warranty of
    20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    21  GNU General Public License for more details.
    22  
    23  You should have received a copy of the GNU General Public License
    24  along with this program; if not, write to the Free Software
    25  Foundation, Inc., 59 Temple Place - Suite 330,
    26  Boston, MA  02111-1307, USA.
    27  */
     2    $Id$
     3         
     4    Copyright (C) 2008 Olle Mansson
     5    Copyright (C) 2010 Gregory Vincic
     6         
     7    Files are copyright by their respective authors. The contributions to
     8    files where copyright is not explicitly stated can be traced with the
     9    source code revision system.
     10         
     11    This file is part of Proteios.
     12    Available at http://www.proteios.org/
     13         
     14    Proteios is free software; you can redistribute it and/or
     15    modify it under the terms of the GNU General Public License
     16    as published by the Free Software Foundation; either version 2
     17    of the License, or (at your option) any later version.
     18         
     19    Proteios is distributed in the hope that it will be useful,
     20    but WITHOUT ANY WARRANTY; without even the implied warranty of
     21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     22    GNU General Public License for more details.
     23         
     24    You should have received a copy of the GNU General Public License
     25    along with this program; if not, write to the Free Software
     26    Foundation, Inc., 59 Temple Place - Suite 330,
     27    Boston, MA  02111-1307, USA.
     28*/
    2829package org.proteios.action.extract;
    2930
     
    3435import org.proteios.gui.Title;
    3536import org.proteios.gui.Toolbar;
    36 import org.proteios.gui.form.Form;
     37import org.proteios.gui.form.*;
    3738import org.proteios.gui.layout.RowLayout;
    38 
    3939import se.lu.thep.waf.ActionException;
    4040import se.lu.thep.waf.constraints.InvalidParameterValue;
     
    4242
    4343/**
    44  * @author olle
    45  */
     44    This class displays a form when the user wants to create an extract from an existing
     45    extract.
     46*/
    4647public class NewSecondaryExtract
    47     extends ProteiosAction<NewSecondaryExtract>
     48extends ProteiosAction<NewSecondaryExtract>
    4849{
    49   public final static VInteger VEXTRACTID = new VInteger("active.extract.id",
    50     1, false);
    51 
    52 
    53   @Override
    54   protected void runMe()
    55       throws ActionException, InvalidParameterValue
    56   {
    57     /***********************************************************************
    58      * Verify parameters
    59      */
    60     verifySessionAttributes(ViewActiveExtract.VEXTRACTID);
    61     /***********************************************************************
    62      * Extract form
    63      */
    64     Integer extractId = getSessionAttribute(ViewActiveExtract.VEXTRACTID);
    65     DbControl dc = newDbControl();
    66     ItemFactory factory = getItemFactory(dc);
    67     Extract extract = null;
    68     if (extractId != null && extractId > 0)
    69     {
    70       extract = factory.getById(Extract.class, extractId);
    71     }
    72     Form form = getFormFactory().getSecondaryExtractForm(null, extract);
    73     if (extract != null)
    74     {
    75       form.addFieldset(getFormFactory().getUsedExtractFieldset(extract));
    76     }
    77     //populateForm(form); // In case saving failed
    78     // Toolbar
    79     Toolbar tb = new Toolbar();
    80     form.setToolbar(tb);
    81     tb.add(getActionFactory().getActionLink(AddSecondaryExtract.class,
    82       "Save"));
    83     /***********************************************************************
    84      * Layout
    85      */
    86     RowLayout layout = getLayoutFactory().getRowLayout();
    87     layout.add(new Title("NewSecondaryExtract"));
    88     layout.add(form);
    89     setLayout(layout);
    90   }
     50    public final static VInteger VEXTRACTID = new VInteger("active.extract.id",
     51    1, false);
     52       
     53    @Override
     54    protected void runMe()
     55    throws ActionException, InvalidParameterValue
     56    {
     57        Integer extractId;
     58        DbControl dc;
     59        ItemFactory factory;
     60        Extract extract;
     61        ExtractForm form;
     62        Toolbar tb;
     63        RowLayout layout;
     64        Title title;
     65               
     66        verifySessionAttributes(ViewActiveExtract.VEXTRACTID);
     67        extractId = getSessionAttribute(ViewActiveExtract.VEXTRACTID);
     68               
     69        // Use the already available ItemFactory to get the parent Extract object if any
     70        dc = newDbControl();
     71        factory = getItemFactory(dc);
     72        extract = null;
     73        // TODO If this is a secondary extract how come we allow it's parent to be null?
     74        // It looks like this action also handles the creation of an Extract without any connection
     75        // to another biomaterial.
     76        if (extractId != null && extractId > 0)
     77        {
     78            extract = factory.getById(Extract.class, extractId);
     79        }
     80               
     81        form = new ExtractForm();
     82        if (extract != null)
     83        {
     84            form.addFieldset(getFormFactory().getUsedExtractFieldset(extract));
     85            // Some parent values are set as default values
     86            form.nameF.setValue(extract.getName());
     87            form.externalIdF.setValue(extract.getExternalId());
     88            form.descriptionF.setValue(extract.getDescription());
     89            form.originalQuantityF.setValue(extract.getRemainingQuantityInMicroLiters());
     90            form.concF.setValue(extract.getConcentrationInGramsPerLiter());
     91        }
     92               
     93        // Put graphical elements together
     94        title = new Title("NewSecondaryExtract");
     95        tb = new Toolbar();
     96        tb.add(getActionFactory().getActionLink(AddSecondaryExtract.class,
     97        "Save"));
     98               
     99        form.setToolbar(tb);
     100        layout = getLayoutFactory().getRowLayout();
     101        layout.add(title);
     102        layout.add(form);
     103        setLayout(layout);
     104    }
    91105}
  • trunk/client/servlet/src/org/proteios/gui/form/ExtractForm.java

    r3879 r3880  
    11/*
    22    $Id$
    3                    
     3                                           
    44    Copyright (C) 2010 Gregory Vincic
    5                    
     5                                           
    66    Files are copyright by their respective authors. The contributions to
    77    files where copyright is not explicitly stated can be traced with the
    88    source code revision system.
    9                    
     9                                           
    1010    This file is part of Proteios.
    1111    Available at http://www.proteios.org/
    12                    
     12                                           
    1313    Proteios is free software; you can redistribute it and/or
    1414    modify it under the terms of the GNU General Public License
    1515    as published by the Free Software Foundation; either version 2
    1616    of the License, or (at your option) any later version.
    17                    
     17                                           
    1818    Proteios is distributed in the hope that it will be useful,
    1919    but WITHOUT ANY WARRANTY; without even the implied warranty of
    2020    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    2121    GNU General Public License for more details.
    22                    
     22                                           
    2323    You should have received a copy of the GNU General Public License
    2424    along with this program; if not, write to the Free Software
     
    4444    public TextArea descriptionF;
    4545    public TextField<String> storageLocationF;
    46        
     46                               
    4747    /**
    4848        Fieldset for quantities and concentration
    4949    */
    5050    public Fieldset quantityFS;
    51     public TextField<Float> quantityF;
     51    public TextField<Float> originalQuantityF;
    5252    public TextField<Float> remainingQuantityF = null;
    5353    public TextField<Float> concF;
    5454    public TextField<Integer> itemIdF = null;
    55                
     55                                      
    5656    /**
    5757        Creates an empty form with no id field and no
     
    6666        descriptionF = new DescriptionField();
    6767        storageLocationF = new StorageLocationField();
    68                                    
     68                                                                                   
    6969        fs = new Fieldset("Quantity");
    7070        fs.setTitle("Properties");
     
    7474        fs.add(storageLocationF);
    7575        addFieldset(fs);
    76                                
    77         quantityF = new OriginalQuantityField();
     76                                                                               
     77        originalQuantityF = new OriginalQuantityField();
    7878        concF = new ConcentrationField();
    79                                
     79                                                                               
    8080        quantityFS = new Fieldset();
    81         quantityFS.add(quantityF);
     81        quantityFS.add(originalQuantityF);
    8282        quantityFS.add(concF);
    8383        addFieldset(quantityFS);
    8484    }
    85                  
     85                                         
    8686    /**
    8787        Creates a form with values also containing an ItemIdField and
     
    101101        descriptionF.setValue(extract.getDescription());
    102102        storageLocationF.setValue(extract.getStorageLocation());
    103         quantityF.setValue(extract.getOriginalQuantityInMicroLiters());
     103        originalQuantityF.setValue(extract.getOriginalQuantityInMicroLiters());
    104104        quantityFS.add(remainingQuantityF);
    105105        concF.setValue(extract.getConcentrationInGramsPerLiter());
  • trunk/client/servlet/src/org/proteios/gui/form/FormFactory.java

    r3875 r3880  
    11/*
    2  $Id$
    3 
    4  Copyright (C) 2006, 2007 Fredrik Levander, Gregory Vincic, Olle Mansson
    5 
    6  Files are copyright by their respective authors. The contributions to
    7  files where copyright is not explicitly stated can be traced with the
    8  source code revision system.
    9 
    10  This file is part of Proteios.
    11  Available at http://www.proteios.org/
    12 
    13  proteios-2.x is free software; you can redistribute it and/or
    14  modify it under the terms of the GNU General Public License
    15  as published by the Free Software Foundation; either version 2
    16  of the License, or (at your option) any later version.
    17 
    18  Proteios is distributed in the hope that it will be useful,
    19  but WITHOUT ANY WARRANTY; without even the implied warranty of
    20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    21  GNU General Public License for more details.
    22 
    23  You should have received a copy of the GNU General Public License
    24  along with this program; if not, write to the Free Software
    25  Foundation, Inc., 59 Temple Place - Suite 330,
    26  Boston, MA  02111-1307, USA.
    27  */
     2    $Id$
     3   
     4    Copyright (C) 2006, 2007 Fredrik Levander, Gregory Vincic, Olle Mansson
     5   
     6    Files are copyright by their respective authors. The contributions to
     7    files where copyright is not explicitly stated can be traced with the
     8    source code revision system.
     9   
     10    This file is part of Proteios.
     11    Available at http://www.proteios.org/
     12   
     13    proteios-2.x is free software; you can redistribute it and/or
     14    modify it under the terms of the GNU General Public License
     15    as published by the Free Software Foundation; either version 2
     16    of the License, or (at your option) any later version.
     17   
     18    Proteios is distributed in the hope that it will be useful,
     19    but WITHOUT ANY WARRANTY; without even the implied warranty of
     20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     21    GNU General Public License for more details.
     22   
     23    You should have received a copy of the GNU General Public License
     24    along with this program; if not, write to the Free Software
     25    Foundation, Inc., 59 Temple Place - Suite 330,
     26    Boston, MA  02111-1307, USA.
     27*/
    2828package org.proteios.gui.form;
    2929
     
    5858
    5959/**
    60  * Generates various forms used in the gui. It also populates forms from
    61  * requests. NOTE! this class will be deprecated shortly
    62  *
    63  * @author gregory
    64  */
     60    * Generates various forms used in the gui. It also populates forms from
     61    * requests. NOTE! this class will be deprecated shortly
     62    *
     63    * @author gregory
     64*/
    6565public class FormFactory
    6666{
    67   private ActionFactory actionFactory = null;
    68   private HttpServletRequest request = null;
    69   private SessionControl sc = null;
    70   /**
    71    * List<String> of excluded getter methods declared in current class. If a
    72    * getter accessor method is included in this list, when a generic form for
    73    * an object is created with getForm(), no field will be added to the form
    74    * for an instance variable (if any) corresponding to the getter method.
    75    */
    76   private List<String> excludedDeclMethods = new ArrayList<String>();
    77   private Localizer locale = null;
    78   private String forwardActionId = null;
    79   private String sortColumnKey = null;
    80   private Integer filterListSize = null;
    81   private List<String> filterKeyColumnList = null;
    82   private HashMap<String, String> filterClassColumnHashMap = null;
    83   private HashMap<String, String> filterConditionColumnHashMap = null;
    84   private HashMap<String, String> filterValueColumnHashMap = null;
    85   // Valid parameters
    86   public static final VInteger VID = new DBID();
    87   public static final VInteger VPROTOCOLID = new ProtocolID();
    88   public static final VInteger VPROJECTTYPE = new ProjectTypeID();
    89   public static final VInteger VPROJECTSTATUS = new ProjectStatus();
    90   public static final VInteger VPROTOCOLFILEID = new VInteger("protocolfileId", 0, true);
    91   public static final VBoolean VPROTOCOLFILERESET = new VBoolean("protocolFileReset", false);
    92   public static final VInteger VANNOTYPEID = new VInteger("annotationTypeId",0, true);
    93   public static final VInteger VGROUPID = new VInteger("groupId", 1, false);
    94   public static final VString VANNONAME = new VString("annotationName", 1,64, false);
    95   public static final VString VPWD1 = new VString("pwd1", 1, 32, true);
    96   public static final VString VPWD2 = new VString("pwd2", 1, 32, true);
    97   public static final VString VANNOVALUE = new VString("value", 0, 255);
    98   public static final VString VTYPE = new VString("type", 1, 64, true);
    99   public static final VString VFILE = new VString("file", 1, 512); // Allow
    100   public static final VString VNONREQUIRED_FILENAME = new VString("fileName",0, 255, false);
    101   public static final VString VREQUIRED_FILENAME = new VString("fileName", 1,255, true);
    102   public static final VString VFWD2ACTION = new VString("forward2ActionId",1, 255, false);
    103   public static final VString VCLASSNAME = new VString("className", 1, 255,true);
    104   public static final VString VURI = new VString("fileURI", 0, 255, false);
    105   public static final VString VROLEPERMISSIONID = new VString("rolePermId",1, 64, true);
    106   public static final VString VWELLPOSITION = new VString("wellPosition", 0,8, false);
    107   public static final VInteger VDIRID = new VInteger("dirId", 1, true);
    108   public static final VInteger VSPOTID = new VInteger("spotId", 0, false);
    109   public static final VInteger VFILETYPEID = new VInteger("fileTypeId", 0,true);
    110   public static final VString VPERCENT = new VString("percent", 0, 4, false);
    111   public static final VInteger VMASSSTART = new VInteger("massStartInKiloDaltons", 0, false);
    112   public static final VInteger VMASSEND = new VInteger("massEndInKiloDaltons", 0, false);
    113   public static final VInteger VSIZEX = new VInteger("sizeXInCentiMeters", 0,false);
    114   public static final VInteger VSIZEY = new VInteger("sizeYInCentiMeters", 0,false);
    115   public static final VInteger VPERCENTACRYLAMID = new VInteger("percentAcrylAmid", 0, 100, false);
    116   public static final VString VDENATURATINGAGENT = new VString("denaturatingAgent", 0, 255, false);
    117   public static final VString VPROTEINASSAY = new VString("proteinAssay", 0,255, false);
    118   public static final VString VSOLUBILIZATIONBUFFER = new VString("solubilizationBuffer", 0, 255, false);
    119   public static final VFloat VORIGINALQUANTITY = new VFloat("originalQuantity", true);
    120   public static final VFloat VREMAININGQUANTITY = new VFloat("remainingQuantity", false);
    121   public static final VFloat VQUANTITY = new VFloat("quantity", true);
    122   public static final VFloat VUSEDQUANTITYINMICROLITERS = new VFloat("UsedQuantityInMicroLiters", true);
    123   public static final VBoolean VPEPTIDECOMPARE = new VBoolean("isPeptideCompare", false);
    124   public static final VBoolean VISMICROTITREPLATE = new VBoolean("isMicrotitrePlate", false);
    125   public static final VString VRANDOMSTRING = new VString("randomString", 1,15, true);
    126   public static final VInteger VCOUNT = new VInteger("count", 0, true);
    127   public static final VInteger VDIRCOUNT = new VInteger("dirCount", 0, true);
    128   public static final VInteger VJOBCOUNT = new VInteger("jobCount", 0, true);
    129   public static final VInteger VSPECTRUMSEARCHCOUNT = new VInteger("spectrumSearchCount", 0, true);
    130   public static final VBoolean VREADONLYFORM = new VBoolean("readOnlyForm",false);
    131   public static final VBoolean VCONFIRM = new VBoolean("confirm", false);
    132   public static final VString VCONFIRMMESSAGE = new VString("confirmMessage",0, 255, false);
    133   public static final VString VCANCELACTION = new VString("cancelActionId",1, 255, false);
    134   public static final VString VFILTERNAME = new VString("filterName", 0, 255,false);
    135   public static final VString VFILTERCLASS = new VString("filterClass", 0,255, false);
    136   public static final VString VFILTERCONDITION = new VString("filterCondition", 0, 255, false);
    137   public static final VString VFILTERVALUE = new VString("filterValue", 0,255, false);
    138   public static final VInteger VLISTSIZE = new VInteger("listSize", 0, false);
    139   public static final VString VFILTERKEYLIST = new VString("filterKeyList",0, 255, false);
    140   public static final VString VFILTERCLASSLIST = new VString("filterClassList", 0, 255, false);
    141   public static final VString VFILTERCONDITIONLIST = new VString("filterConditionList", 0, 255, false);
    142   public static final VString VFILTERVALUELIST = new VString("filterValueList", 0, 255, false);
    143   public static final VString VSORTCOLUMNKEY = new VString("sortColumnKey",0, 255, false);
    144   public static final VString VCOMMENT = new VString("comment", 0, 255, false);
    145   public static final VDate VENTRYDATE = new VDate("entryDate", false,Format.DATETIME);
    146   public static final VDate VEVENTDATE = new VDate("eventDate", false,Format.DATETIME, Format.DATE);
    147   public static final VDate VNEWSDATE = new VDate("newsDate", true,Format.DATETIME, Format.DATE);
    148   public static final VDate VSTARTDATE = new VDate("startDate", true,Format.DATETIME, Format.DATE);
    149   public static final VDate VENDDATE = new VDate("endDate", true,Format.DATETIME, Format.DATE);
    150 
    151   public static final VInteger VBIOMATERIALID = new VInteger("bioMaterialId",1, false);
    152   // TODO what are valid values for the pistart parameter
    153 
    154 
    155   public static final VString VSTAIN = new VString("stain", 0, 255, false);
    156   public static final VInteger VLABELID = new VInteger("labelId", 0, true);
    157   // public static final VInteger VCOLUMNROWID = new VInteger("columnRowId",// 0, true);
    158   public static final VInteger VCOLUMNROWID = new VInteger("columnRowId", 0,false);
    159   public static final VInteger VCOLUMNLISTSIZE = new VInteger("columnListSize", 0, false);
    160   public static final VInteger VCOLUMNSELECTID = new VInteger("columnSelectId", 0, false);
    161   public static final VInteger VCOLUMNSELECTLISTSIZE = new VInteger("columnSelectListSize", 0, false);
    162   public static final VString VTABLECONFACTION = new VString("tableConfigurationActionId", 0, 255, false);
    163   private static final VString VOWNER = new VString("owner", 1, 32, false);
    164   public static final VString VNONREQUIRED_NAME = new VString("name", 0, 255,false);
    165   public static final VString VNONREQUIRED_INSTITUTION = new VString("institution", 0, 255, false);
    166   public static final VString VNONREQUIRED_ADDRESS = new VString("address",0, 255, false);
    167   public static final VString VNONREQUIRED_URL = new VString("url", 0, 255,false);
    168   public static final VString VNONREQUIRED_EMAIL = new VString("email", 0,255, false);
    169   public static final VString VNONREQUIRED_CONTACT_INFO = new VString("contactInfo", 0, 255, false);
    170   public static final VString VNONREQUIRED_SAMPLE_NAME = new VString("sampleName", 0, 255, false);
    171   public static final VString VNONREQUIRED_SAMPLE_NUMBER = new VString("sampleNumber", 0, 255, false);
    172   public static final VString VNONREQUIRED_SAMPLE_STATE = new VString("sampelState", 0, 255, false);
    173   public static final VString VNONREQUIRED_SAMPLE_MASS_IN_GRAMS = new VString("sampleMassInGrams", 0, 255, false);
    174   public static final VString VNONREQUIRED_SAMPLE_VOLUME_IN_MILLILITERS = new VString("sampleVolumeInMilliliters", 0, 255, false);
    175   public static final VString VNONREQUIRED_SAMPLE_CONCENTRATION_IN_GRAMS_PER_LITER = new VString("sampleConcentrationInGramsPerLiter", 0, 255, false);
    176   public static final VString VNONREQUIRED_SAMPLE_BATCH = new VString("sampleBatch", 0, 255, false);
    177   public static final VString VNONREQUIRED_SAMPLE_COMMENT = new VString("sampleComment", 0, 255, false);
    178   /**
    179    * logger to use
    180    */
    181   private static final org.apache.log4j.Logger log = org.apache.log4j.LogManager
    182     .getLogger("org.proteios.gui.form");
    183 
    184 
    185   /**
    186    * Default constructor. Initializes list excludedDeclMethods.
    187    */
    188   public FormFactory()
    189   {
    190     /*
    191      * Initialize list excludedDeclMethods.
    192      */
    193     initExcludedDeclMethods();
    194   }
    195 
    196 
    197   /**
    198    * Get list of excluded getter methods declared in current class.
    199    *
    200    * @return List<String> of excluded getter methods.
    201    */
    202   public List<String> getExcludedDeclMethods()
    203   {
    204     return this.excludedDeclMethods;
    205   }
    206 
    207 
    208   /**
    209    * Set list of excluded getter methods declared in current class.
    210    *
    211    * @param excludedDeclMethods List<String> of excluded getter methods to
    212    *        set.
    213    */
    214   public void setExcludedDeclMethods(List<String> excludedDeclMethods)
    215   {
    216     this.excludedDeclMethods = excludedDeclMethods;
    217   }
    218 
    219 
    220   /**
    221    * Add list of excluded getter methods declared in current class.
    222    *
    223    * @param excludedDeclMethods List<String> of excluded getter methods to to
    224    *        add.
    225    */
    226   public void addExcludedDeclMethods(List<String> excludedDeclMethods)
    227   {
    228     for (String exclMethod : excludedDeclMethods)
    229     {
    230       /*
    231        * Add excluded method if not already in list.
    232        */
    233       if (!getExcludedDeclMethods().contains(exclMethod))
    234       {
    235         getExcludedDeclMethods().add(exclMethod);
    236       }
    237     }
    238   }
    239 
    240  public void setActionFactory(ActionFactory af)
    241  {
    242   this.actionFactory = af;
    243  }
    244 
    245 
    246   public String getForwardActionId()
    247   {
    248     return this.forwardActionId;
    249   }
    250 
    251 
    252   public void setForwardActionId(String forwardActionId)
    253   {
    254     this.forwardActionId = forwardActionId;
    255   }
    256 
    257 
    258   public String getSortColumnKey()
    259   {
    260     return this.sortColumnKey;
    261   }
    262 
    263 
    264   public void setSortColumnKey(String sortColumnKey)
    265   {
    266     this.sortColumnKey = sortColumnKey;
    267   }
    268 
    269 
    270   public Integer getFilterListSize()
    271   {
    272     return this.filterListSize;
    273   }
    274 
    275 
    276   public void setFilterListSize(Integer filterListSize)
    277   {
    278     this.filterListSize = filterListSize;
    279   }
    280 
    281 
    282   public List<String> getFilterKeyColumnList()
    283   {
    284     return this.filterKeyColumnList;
    285   }
    286 
    287 
    288   public void setFilterKeyColumnList(List<String> filterKeyColumnList)
    289   {
    290     this.filterKeyColumnList = filterKeyColumnList;
    291   }
    292 
    293 
    294   public HashMap<String, String> getFilterClassColumnHashMap()
    295   {
    296     return this.filterClassColumnHashMap;
    297   }
    298 
    299 
    300   public void setFilterClassColumnHashMap(
    301       HashMap<String, String> filterClassColumnHashMap)
    302   {
    303     this.filterClassColumnHashMap = filterClassColumnHashMap;
    304   }
    305 
    306 
    307   public HashMap<String, String> getFilterConditionColumnHashMap()
    308   {
    309     return this.filterConditionColumnHashMap;
    310   }
    311 
    312 
    313   public void setFilterConditionColumnHashMap(
    314       HashMap<String, String> filterConditionColumnHashMap)
    315   {
    316     this.filterConditionColumnHashMap = filterConditionColumnHashMap;
    317   }
    318 
    319 
    320   public HashMap<String, String> getFilterValueColumnHashMap()
    321   {
    322     return this.filterValueColumnHashMap;
    323   }
    324 
    325 
    326   public void setFilterValueColumnHashMap(
    327       HashMap<String, String> filterValueColumnHashMap)
    328   {
    329     this.filterValueColumnHashMap = filterValueColumnHashMap;
    330   }
    331 
    332 
    333   /**
    334    * Initializes list of excluded getter methods declared in current class.
    335    */
    336   public void initExcludedDeclMethods()
    337   {
    338     /*
    339      * Initialize list of excluded declared methods.
    340      */
    341     getExcludedDeclMethods().add("getType");
    342     getExcludedDeclMethods().add("getQuery");
    343     getExcludedDeclMethods().add("getNew");
    344     getExcludedDeclMethods().add("getById");
    345     getExcludedDeclMethods().add("isUsed");
    346     getExcludedDeclMethods().add("isRemoved");
    347     getExcludedDeclMethods().add("getAnnotatableParents");
    348   }
    349 
    350 
    351   public HttpServletRequest getRequest()
    352   {
    353     return request;
    354   }
    355 
    356 
    357   public void setRequest(HttpServletRequest request)
    358   {
    359     this.request = request;
    360   }
    361 
    362 
    363 
    364   public void modifyForPopup(Fieldset fs)
    365   {
    366   actionFactory.modifyForPopup(fs);
    367   }
    368 
    369 
    370 
    371 
    372   private FileField newFileField()
    373   {
    374     FileField fileF = new FileField(VFILE);
    375     fileF.setLabel("File");
    376     return fileF;
    377   }
    378 
    379 
    380   public TextField<Integer> newIdField()
    381   {
    382     TextField<Integer> idF = new TextField<Integer>(VID);
    383     idF.setHidden(true);
    384     idF.setLabel("Id");
    385     return idF;
    386   }
    387 
    388 
    389   private TextField<String> newValueField(String setValueMethodName,
    390       Class<?> valueClass)
    391   {
    392     String setValueMethodSignature = null;
    393     if (setValueMethodName != null && !setValueMethodName.equals(""))
    394     {
    395       /*
    396        * Set valid parameter name to signature of single-argument setter
    397        * method, if existing, in order to separate between arguments of
    398        * primitive types like boolean, int, float, and double, from those
    399        * of wrapper class types like Boolean, Integer, Float, and Double.
    400        */
    401       setValueMethodSignature = setValueMethodName + ":" + valueClass
    402         .getSimpleName();
    403       if (valueClass == String.class)
    404       {
    405         VString vSetterMethodParam = new VString(
    406           setValueMethodSignature, 0, 255, false);
    407         TextField<String> valueF = new TextField<String>(
    408           vSetterMethodParam);
    409         valueF.setLabel("");
    410         valueF.setDisabled(false);
    411         return valueF;
    412       }
    413     }
    414     VString vSetterMethodParam = new VString("null", 0, 255, false);
    415     TextField<String> valueF = new TextField<String>(vSetterMethodParam);
    416     valueF.setLabel("");
    417     valueF.setDisabled(true);
    418     return valueF;
    419   }
    420 
    421 
    422   private TextArea newValueTextArea(String setValueMethodName,
    423       Class<?> valueClass)
    424   {
    425     log
    426       .debug("FormFactory::newValueTextArea(): setValueMethodName = \"" + setValueMethodName + "\" valueClass.getSimpleName() = \"" + valueClass
    427         .getSimpleName() + "\"");
    428     String setValueMethodSignature = null;
    429     if (setValueMethodName != null && !setValueMethodName.equals(""))
    430     {
    431       /*
    432        * Set valid parameter name to signature of single-argument setter
    433        * method, if existing, in order to separate between arguments of
    434        * primitive types like boolean, int, float, and double, from those
    435        * of wrapper class types like Boolean, Integer, Float, and Double.
    436        */
    437       setValueMethodSignature = setValueMethodName + ":" + valueClass
    438         .getSimpleName();
    439       if (valueClass == String.class)
    440       {
    441         VString vSetterMethodParam = new VString(
    442           setValueMethodSignature, 0, 65535, false);
    443         TextArea valueF = new TextArea(vSetterMethodParam);
    444         valueF.setLabel("");
    445         valueF.setDisabled(false);
    446         return valueF;
    447       }
    448       VString vSetterMethodParam = new VString("null", 0, 65535, false);
    449       TextArea valueF = new TextArea(vSetterMethodParam);
    450       valueF.setLabel("");
    451       valueF.setDisabled(false);
    452       return valueF;
    453     }
    454     VString vSetterMethodParam = new VString("null", 0, 65535, false);
    455     TextArea valueF = new TextArea(vSetterMethodParam);
    456     valueF.setLabel("");
    457     valueF.setDisabled(true);
    458     return valueF;
    459   }
    460 
    461 
    462 
    463   public Form getMyProfilePropertiesForm(User user)
    464   {
    465   return getForm(User.class, user);
    466  }
    467 
    468 
    469   public TextField<Integer> newHiddenItemIdField()
    470   {
    471     TextField<Integer> field = new TextField<Integer>(VID).setHidden(true);
    472     return field;
    473   }
    474 
    475 
    476   private TextField<Boolean> newHiddenReadOnlyFormField()
    477   {
    478     TextField<Boolean> field = new TextField<Boolean>(VREADONLYFORM)
    479       .setHidden(true);
    480     return field;
    481   }
    482 
    483 
    484   private TextField<Integer> newHiddenIntegerField(VInteger vInteger)
    485   {
    486     TextField<Integer> field = new TextField<Integer>(vInteger)
    487       .setHidden(true);
    488     return field;
    489   }
    490 
    491 
    492   private TextField<String> newHiddenStringField(VString vString)
    493   {
    494     TextField<String> field = new TextField<String>(vString)
    495       .setHidden(true);
    496     return field;
    497   }
    498 
    499 
    500   @SuppressWarnings("unchecked")
    501   public void populateForm(Form form, HttpServletRequest request2)
    502   {
    503     if (request2 != null)
    504     {
    505       for (Fieldset fs : form.getFieldsets())
    506       {
    507         for (Iterator iter = fs.getFields().iterator(); iter.hasNext();)
    508         {
    509           Field f = (Field) iter.next();
    510           VParameter param = f.getParam();
    511           String value = null;
    512           if (param != null)
    513           {
    514             value = request.getParameter(param.getName());
    515             if (value == null)
    516             {
    517               // Try the attributes
    518               value = (String) request.getAttribute(param
    519                 .getName());
    520             }
    521           }
    522           if (f instanceof TextField)
    523           {
    524             TextField<String> textField = (TextField<String>) f;
    525             // FIXME implement methods to check if field contains
    526             // String, Float or other
    527             textField.setValue(value);
    528             continue;
    529           }
    530           if (f instanceof TextArea)
    531           {
    532             TextArea textArea = (TextArea) f;
    533             textArea.setValue(value);
    534             continue;
    535           }
    536           if (f instanceof Checkbox)
    537           {
    538             if (value != null && value.equals(((Checkbox) f)
    539               .getValue()))
    540               ((Checkbox) f).isChecked(true);
    541           }
    542           if (f instanceof Select)
    543           {
    544             Select tmp = (Select) f;
    545             List<Option> options = tmp.getOptions();
    546             for (Option o : options)
    547             {
    548               if (value != null && value.equals(o.getValue()))
    549               {
    550                 o.setSelected(true);
    551                 break;
    552               }
    553               o.setSelected(false);
    554             }
    555             continue;
    556           }
    557         }
    558       }
    559     }
    560   }
    561 
    562 
    563   public <D extends BasicItem<?>, E extends ProteiosAction<?>> Form getAnnotationsForm(
    564       DbControl dc, D item, Class<E> forwardAction)
    565   {
    566     Form form = new Form("annotationForm");
    567     form.setTitle("Annotations");
    568     Fieldset fs = new Fieldset();
    569     form.addFieldset(fs);
    570     fs.setTitle("Annotation");
    571     // id field
    572     TextField<Integer> idF = newIdField();
    573     fs.add(idF);
    574     // type field
    575     TextField<String> typeF = newTypeField();
    576     fs.add(typeF);
    577     // Forward action field
    578     TextField<String> fwdactionF = new ForwardField();
    579     fs.add(fwdactionF);
    580     // Select field
    581     Select<VInteger> typeS = new Select<VInteger>(VANNOTYPEID);
    582     typeS.setLabel("Type");
    583     typeS.addOption(new Option("0").setContent("-- New --"));
    584     if (dc != null)
    585     {
    586       ItemQuery<AnnotationType> query = AnnotationType.getQuery(item
    587         .getType());
    588       for (AnnotationType at : query.list(dc))
    589       {
    590         typeS.addOption(new Option(new Integer(at.getId()).toString(),
    591           at.getName()));
    592       }
    593     }
    594     typeS.setLabel("Type");
    595     fs.add(typeS);
    596     // new field
    597     TextField<String> nameF = new TextField<String>(VANNONAME);
    598     nameF.setLabel("Name");
    599     fs.add(nameF);
    600     // value field
    601     TextField<String> valueF = new TextField<String>(VANNOVALUE);
    602     valueF.setLabel("Value");
    603     fs.add(valueF);
    604     if (item != null)
    605     {
    606       idF.setValue(item.getId());
    607       typeF.setValue(Item.fromClass(item.getClass()).name());
    608       fwdactionF.setValue(forwardAction.getName());
    609     }
    610     return form;
    611   }
    612 
    613 
    614   /**
    615    * @return Hidden
    616    *         <code>TextField<String> using the valid parameter {@link #VTYPE}.
    617    */
    618   private TextField<String> newTypeField()
    619   {
    620     TextField<String> field = new TextField<String>(VTYPE).setHidden(true);
    621     return field;
    622   }
    623 
    624 
    625 
    626   public Form getViewUserPropertiesForm(User user)
    627   {
    628     return getForm(User.class, user);
    629   }
    630 
    631 
    632   /**
    633    * Form for user preferences configuration settings. Arguments
    634    * NotificationConfiguration and TablePreferencesConfiguration are place
    635    * holders for current values for the notification configuration and table
    636    * preferences configuration form fields.
    637    *
    638    * @param nc NotificationConfiguration object (need not be stored in
    639    *        database) with default field values.
    640    * @return Form A form for setting user preferences configuration values.
    641    */
    642   public Form getUserPreferencesConfigurationForm(
    643       NotificationConfiguration nc, TablePreferencesConfiguration tpc)
    644   {
    645     Form form = new Form("userPreferencesConfigurationForm");
    646     // Notification configuration field set
    647     Fieldset notificationConfigurationFS = getNotificationConfigurationFieldset(nc);
    648     form.addFieldset(notificationConfigurationFS);
    649     // Table preferences configuration field set
    650     Fieldset tablePreferencesConfigurationFS = getTablePreferencesConfigurationFieldset(tpc);
    651     form.addFieldset(tablePreferencesConfigurationFS);
    652     //
    653     return form;
    654   }
    655 
    656 
    657   /**
    658    * Fieldset for notification configuration settings. Argument
    659    * NotificationConfiguration is place holder for current values for the
    660    * notification configuration form fields.
    661    *
    662    * @param nc NotificationConfiguration object (need not be stored in
    663    *        database) with default field values.
    664    * @return Fieldset A fieldset for setting NotificationConfiguration values.
    665    */
    666   public Fieldset getNotificationConfigurationFieldset(
    667       NotificationConfiguration nc)
    668   {
    669     // properties
    670     Fieldset properties = new Fieldset();
    671     properties.setTitle("NotificationConfiguration");
    672     // SMTP host field
    673     TextField<String> smtpHostF = new TextField<String>(
    674       SavePreferences.VSMTPHOSTREADONLY);
    675     smtpHostF.setLabel("MailServer");
    676     smtpHostF.setDisabled(true);
    677     properties.add(smtpHostF);
    678     // "From" address field
    679     TextField<String> fromAddressF = new TextField<String>(
    680       SavePreferences.VFROMADDRESSREADONLY);
    681     fromAddressF.setLabel("FromAddress");
    682     fromAddressF.setDisabled(true);
    683     properties.add(fromAddressF);
    684     // "From" name field
    685     TextField<String> fromNameF = new TextField<String>(
    686       SavePreferences.VFROMNAME);
    687     fromNameF.setLabel("FromName");
    688     properties.add(fromNameF);
    689     // "To" address field
    690     TextField<String> toAddressF = new TextField<String>(
    691       SavePreferences.VTOADDRESS);
    692     toAddressF.setLabel("ToAddress");
    693     properties.add(toAddressF);
    694     // Notification mode select box
    695     int initialMode = -1;
    696     if (nc != null)
    697     {
    698       initialMode = nc.getMode();
    699     }
    700     Select<VInteger> modeS = getNotificationModeSelectBox(initialMode);
    701     properties.add(modeS);
    702     //
    703     if (nc != null)
    704     {
    705       smtpHostF.setValue(nc.getSmtpHost());
    706       fromAddressF.setValue(nc.getFromAddress());
    707       fromNameF.setValue(nc.getFromName());
    708       toAddressF.setValue(nc.getToAddress());
    709     }
    710     //
    711     return properties;
    712   }
    713 
    714 
    715   /**
    716    * Creates a select box for notification mode.
    717    *
    718    * @param modeValue int Mode value for default selection.
    719    * @return Select<VInteger> Select box for notification mode selection
    720    */
    721   private Select<VInteger> getNotificationModeSelectBox(int modeValue)
    722   {
    723     Select<VInteger> modeS = new Select<VInteger>(
    724       SavePreferences.VNOTIFICATIONMODE);
    725     modeS.setLabel("NotificationMode");
    726     //
    727     NotificationConfiguration.Mode modeArray[] = NotificationConfiguration.Mode
    728       .values();
    729     int numOptions = modeArray.length;
    730     for (int i = 0; i < numOptions; i++)
    731     {
    732       Option o = new Option("" + modeArray[i].getValue());
    733       o.setContent("" + modeArray[i]);
    734       if (modeArray[i].getValue() == modeValue)
    735       {
    736         o.setSelected(true);
    737       }
    738       modeS.addOption(o);
    739     }
    740     return modeS;
    741   }
    742 
    743 
    744   /**
    745    * Fieldset for table preferences configuration settings. Argument
    746    * TablePreferencesConfiguration is place holder for current values for the
    747    * table preferences configuration form fields.
    748    *
    749    * @param tpc TablePreferencesConfiguration object (need not be stored in
    750    *        database) with default field values.
    751    * @return Fieldset A field set for setting TablePreferencesConfiguration
    752    *         values.
    753    */
    754   public Fieldset getTablePreferencesConfigurationFieldset(
    755       TablePreferencesConfiguration tpc)
    756   {
    757     // properties
    758     Fieldset properties = new Fieldset();
    759     properties.setTitle("TablePreferencesConfiguration");
    760     // Table preferences reset check-box
    761     Checkbox<VBoolean> tablePreferencesResetCB = new Checkbox<VBoolean>(
    762       SavePreferences.VTABLEPREFERENCESRESET);
    763     tablePreferencesResetCB.setLabel("TablePreferencesReset");
    764     tablePreferencesResetCB.setValue("true");
    765     tablePreferencesResetCB.isChecked(false);
    766     properties.add(tablePreferencesResetCB);
    767     // Table preferences mode select box
    768     int initialMode = -1;
    769     if (tpc != null)
    770     {
    771       initialMode = tpc.getMode();
    772     }
    773     Select<VInteger> modeS = getTablePreferencesModeSelectBox(initialMode);
    774     properties.add(modeS);
    775     //
    776     return properties;
    777   }
    778 
    779 
    780   /**
    781    * Creates a select box for table preferences mode.
    782    *
    783    * @param modeValue int Mode value for default selection.
    784    * @return Select<VInteger> Select box for table preferences mode selection
    785    */
    786   private Select<VInteger> getTablePreferencesModeSelectBox(int modeValue)
    787   {
    788     Select<VInteger> modeS = new Select<VInteger>(
    789       SavePreferences.VTABLEPREFERENCESMODE);
    790     modeS.setLabel("TablePreferencesMode");
    791     //
    792     TablePreferencesConfiguration.Mode modeArray[] = TablePreferencesConfiguration.Mode
    793       .values();
    794     int numOptions = modeArray.length;
    795     for (int i = 0; i < numOptions; i++)
    796     {
    797       Option o = new Option("" + modeArray[i].getValue());
    798       o.setContent("" + modeArray[i]);
    799       if (modeArray[i].getValue() == modeValue)
    800       {
    801         o.setSelected(true);
    802       }
    803       modeS.addOption(o);
    804     }
    805     return modeS;
    806   }
    807 
    808 
    809   /**
    810   * This will probably be removed when fixint #691
    811    * @param peaklist to edit, or null if an empty form is needed
    812    * @return Form for editing a peaklist
    813    */
    814   public Form getPeakListForm(PeakList peaklist)
    815   {
    816     DbControl dc = peaklist.getDbControl();
    817     ItemFactory factory = new ItemFactory(dc);
    818     Annotator anna = new Annotator(factory);
    819     /***********************************************************************
    820      * Properties fieldset
    821      */
    822     Fieldset propertiesFS = new Fieldset();
    823     propertiesFS.setTitle("Properties");
    824     TextField<Integer> spectrumIdF = new TextField<Integer>(new VInteger(
    825       "spectrumId", 1, true));
    826     spectrumIdF.setLabel("SpectrumId");
    827     propertiesFS.add(spectrumIdF);
    828     /***********************************************************************
    829      * Precursor
    830      */
    831     Fieldset precursorFS = new Fieldset();
    832     precursorFS.setTitle("Precursor");
    833     /***********************************************************************
    834      * Peaklistset fieldset
    835      */
    836     Fieldset peaklistsetFS = new Fieldset();
    837     peaklistsetFS.setTitle("ParentPeakListSet");
    838     PeakListSet pls = peaklist.getPeakListSet();
    839     TextField<String> plsNameF = new NameField();
    840     plsNameF.setDisabled(true);
    841     // Annotations
    842     peaklistsetFS.add(plsNameF);
    843     AnnotationSet as = anna.getAnnotationSet(pls);
    844     for (Annotation a : as.getAnnotations().list(dc))
    845     {
    846       // Only add annotations that contain something
    847       String value = joinAnnotationValues(a);
    848       if (value != null && !value.equals(""))
    849         peaklistsetFS.add(newTextField(a.getAnnotationType().getName(),
    850           value));
    851     }
    852     /***********************************************************************
    853      * Init fields
    854      */
    855     if (peaklist != null)
    856     {
    857       spectrumIdF.setValue(peaklist.getSpectrumId());
    858       spectrumIdF.setDisabled(true);
    859       if (pls != null)
    860       {
    861         plsNameF.setValue(pls.getName());
    862       }
    863       /*******************************************************************
    864        * Precursors
    865        */
    866       for (Precursor pc : peaklist.getPrecursorsQuery().list(
    867         peaklist.getDbControl()))
    868       {
    869         precursorFS.add(newTextField("charge state", pc
    870           .getChargeState()));
    871         //       
    872         precursorFS.add(newTextField("m/z", pc.getMassToChargeRatio()));
    873         precursorFS.add(newTextField("intensity", pc.getIntensity()));
    874         // ion selection
    875         InstrumentConfiguration<?> ionSelection = pc.getIonSelection();
    876         if (ionSelection != null)
    877         {
    878           AnnotationSet ionAS = anna.getAnnotationSet(ionSelection);
    879           for (Annotation a : ionAS.getAnnotations().list(dc))
    880           {
    881             precursorFS.add(newTextField(a.getAnnotationType()
    882               .getName(), a.getValues().get(0)));
    883           }
    884         }
    885         // Activation
    886         InstrumentConfiguration<?> activation = pc.getActivation();
    887         if (activation != null)
    888         {
    889           AnnotationSet actAS = anna.getAnnotationSet(activation);
    890           for (Annotation a : actAS.getAnnotations().list(dc))
    891           {
    892             precursorFS.add(newTextField(a.getAnnotationType()
    893               .getName(), a.getValues().get(0)));
    894           }
    895         }
    896       }
    897     }
    898     /***********************************************************************
    899      * Form
    900      */
    901     Form form = new Form("Peaklist");
    902     form.addFieldset(propertiesFS);
    903     form.addFieldset(precursorFS);
    904     form.addFieldset(peaklistsetFS);
    905     return form;
    906   }
    907 
    908   /**
    909    * @param hit Current Hit
    910    * @param peakListFile Core file with peakList, or null
    911    * @param peaklist to display, or null
    912    * @return Form for displaying peaklist for hit
    913    */
    914   public Form getHitPeakListForm(Hit hit, File peakListFile,
    915       PeakList peaklist, SpectrumSearch spectrumSearch)
    916   {
    917     DbControl dc = hit.getDbControl();
    918     ItemFactory factory = new ItemFactory(dc);
    919     Annotator anna = new Annotator(factory);
    920     /***********************************************************************
    921      * Properties fieldset
    922      */
    923     Fieldset propertiesFS = new Fieldset();
    924     propertiesFS.setTitle("Properties");
    925     /*
    926      * Hit id field.
    927      */
    928     TextField<String> hitDescription = new TextField<String>(new VString(
    929       "description", 0, 255));
    930     if (hit.isProtein() == null || hit.isProtein())
    931     {
    932       hitDescription.setLabel("Description");
    933     }
    934     else
    935     {
    936       hitDescription.setLabel("Sequence");
    937     }
    938     hitDescription.setValue(hit.getDescription());
    939     hitDescription.setDisabled(true);
    940     propertiesFS.add(hitDescription);
    941     TextField<String> hitId = new TextField<String>(new VString("hitId", 0,
    942       255));
    943     hitId.setLabel("Accession");
    944     hitId.setValue(hit.getExternalId());
    945     hitId.setDisabled(true);
    946     propertiesFS.add(hitId);
    947     /*
    948      * If there is a SpectrumSearch in the DB we can find modifications etc.
    949      */
    950     if (spectrumSearch != null)
    951     {
    952       Iterator<SearchModification> smIt = spectrumSearch
    953         .getSearchModifications().iterator();
    954       while (smIt.hasNext())
    955       {
    956         SearchModification mod = smIt.next();
    957         if (mod.isFixed())
    958         {
    959           TextField<String> modF = new TextField<String>(new VString(
    960             "mod", 0, 255));
    961           modF.setLabel("FixedModification");
    962           modF.setValue(mod.getName());
    963           modF.setDisabled(true);
    964           propertiesFS.add(modF);
    965         }
    966       }
    967     }
    968     /*
    969      * File name field.
    970      */
    971     TextField<String> fileNameF = new TextField<String>(new VString(
    972       "FileName", 0, 255));
    973     fileNameF.setLabel("PeakListFileName");
    974     String peakListFileName = new String("null");
    975     if (peakListFile != null)
    976     {
    977       peakListFileName = peakListFile.getName();
    978     }
    979     fileNameF.setValue(peakListFileName);
    980     fileNameF.setDisabled(true);
    981     propertiesFS.add(fileNameF);
    982     /*
    983      * SpectrumId field.
    984      */
    985     // TextField<Integer> spectrumIdF = new TextField<Integer>(new VInteger(
    986     // "spectrumId", 1, true));
    987     TextField<String> spectrumIdF = new TextField<String>(new VString(
    988       "spectrumIdString", 0, 255));
    989     spectrumIdF.setLabel("SpectrumId");
    990     Integer spectrumId = hit.getSpectrumId();
    991     String spectrumIdStr = hit.getSpectrumStringId();
    992     if (spectrumIdStr == null && spectrumId != null)
    993     {
    994       spectrumIdStr = spectrumId.toString();
    995     }
    996     spectrumIdF.setValue(spectrumIdStr);
    997     spectrumIdF.setDisabled(true);
    998     propertiesFS.add(spectrumIdF);
    999     /*
    1000      * Retention time in minutes
    1001      */
    1002     TextField<String> timeInMinutesF = new TextField<String>(new VString(
    1003       "timeInMinutesString", 0, 255));
    1004     timeInMinutesF.setLabel("RetentionTimeInMinutes");
    1005     String timeInMinutesStr = new String("null");
    1006     if (peaklist != null)
    1007     {
    1008       Float retentionTimeInMinutes = peaklist.getTimeInMinutes();
    1009       if (retentionTimeInMinutes != null)
    1010       {
    1011         timeInMinutesStr = retentionTimeInMinutes.toString();
    1012       }
    1013       log
    1014         .debug("FormFactory::getHitPeakListForm(): retentionTimeInMinutes = " + retentionTimeInMinutes);
    1015     }
    1016     timeInMinutesF.setValue(timeInMinutesStr);
    1017     timeInMinutesF.setDisabled(true);
    1018     propertiesFS.add(timeInMinutesF);
    1019     /***********************************************************************
    1020      * Optional PeakList fieldsets
    1021      */
    1022     Fieldset precursorFS = null;
    1023     Fieldset peaklistsetFS = null;
    1024     if (peaklist != null)
    1025     {
    1026       /*******************************************************************
    1027        * Precursor
    1028        */
    1029       precursorFS = new Fieldset();
    1030       precursorFS.setTitle("Precursor");
    1031       /*******************************************************************
    1032        * Peaklistset fieldset
    1033        */
    1034       peaklistsetFS = new Fieldset();
    1035       peaklistsetFS.setTitle("ParentPeakListSet");
    1036       PeakListSet pls = peaklist.getPeakListSet();
    1037       TextField<String> plsNameF = new NameField();
    1038       plsNameF.setDisabled(true);
    1039       peaklistsetFS.add(plsNameF);
    1040       /*******************************************************************
    1041        * Init fields
    1042        */
    1043       // spectrumIdF.setValue(peaklist.getSpectrumId());
    1044       // spectrumIdF.setDisabled(true);
    1045       if (pls != null)
    1046       {
    1047         plsNameF.setValue(pls.getName());
    1048         // Annotations
    1049         AnnotationSet as = anna.getAnnotationSet(pls);
    1050         for (Annotation a : as.getAnnotations().list(dc))
    1051         {
    1052           // Only add annotations that contain something
    1053           String value = joinAnnotationValues(a);
    1054           if (value != null && !value.equals(""))
    1055             peaklistsetFS.add(newTextField(a.getAnnotationType()
    1056               .getName(), value));
    1057         }
    1058       }
    1059       else
    1060       {
    1061         /*
    1062          * Do not display empty PeakListSet field set.
    1063          */
    1064         peaklistsetFS = null;
    1065       }
    1066       /*******************************************************************
    1067        * Precursors
    1068        */
    1069       for (Precursor pc : peaklist.getPrecursorList())
    1070       {
    1071         precursorFS.add(newTextField("charge state", pc
    1072           .getChargeState()));
    1073         //       
    1074         precursorFS.add(newTextField("m/z", pc.getMassToChargeRatio()));
    1075         precursorFS.add(newTextField("intensity", pc.getIntensity()));
    1076         // ion selection
    1077         InstrumentConfiguration<?> ionSelection = pc.getIonSelection();
    1078         if (ionSelection != null)
    1079         {
    1080           AnnotationSet ionAS = anna.getAnnotationSet(ionSelection);
    1081           for (Annotation a : ionAS.getAnnotations().list(dc))
    1082           {
    1083             precursorFS.add(newTextField(a.getAnnotationType()
    1084               .getName(), a.getValues().get(0)));
    1085           }
    1086         }
    1087         // Activation
    1088         InstrumentConfiguration<?> activation = pc.getActivation();
    1089         if (activation != null)
    1090         {
    1091           AnnotationSet actAS = anna.getAnnotationSet(activation);
    1092           for (Annotation a : actAS.getAnnotations().list(dc))
    1093           {
    1094             precursorFS.add(newTextField(a.getAnnotationType()
    1095               .getName(), a.getValues().get(0)));
    1096           }
    1097         }
    1098       }
    1099       if (peaklist.getPrecursorList() == null || peaklist
    1100         .getPrecursorList().size() == 0)
    1101       {
    1102         /*
    1103          * Do not display empty Precursor field set.
    1104          */
    1105         precursorFS = null;
    1106       }
    1107     }
    1108     /***********************************************************************
    1109      * Form
    1110      */
    1111     Form form = new Form("HitPeaklist");
    1112     form.addFieldset(propertiesFS);
    1113     if (precursorFS != null)
    1114     {
    1115       form.addFieldset(precursorFS);
    1116     }
    1117     if (peaklistsetFS != null)
    1118     {
    1119       form.addFieldset(peaklistsetFS);
    1120     }
    1121     return form;
    1122   }
    1123 
    1124 
    1125   /**
    1126    * @param a annotation
    1127    * @return String
    1128    */
    1129   private String joinAnnotationValues(Annotation a)
    1130   {
    1131     List<?> values = a.getValues();
    1132     StringBuilder sb = new StringBuilder();
    1133     for (Object o : values)
    1134       sb.append(o);
    1135     return sb.toString();
    1136   }
    1137 
    1138 
    1139   /**
    1140    * Returns a form for selecting spectrum mass range limits.
    1141    *
    1142    * @param massCutoffLow String The lower cutoff mass value.
    1143    * @param massCutoffHigh String The upper cutoff mass value.
    1144    * @param spectrumId String The spectrum Id string.
    1145    * @return Form for selecting mass range limits.
    1146    */
    1147   public Form getSpectrumMassRangeSelectionForm(String massCutoffLow,
    1148       String massCutoffHigh, String spectrumId)
    1149   {
    1150     /***********************************************************************
    1151      * Mass range fieldset
    1152      */
    1153     Fieldset massRangeFS = new Fieldset();
    1154     massRangeFS.setTitle("SpectrumMassRangeSelection");
    1155     //
    1156     TextField<String> cutoffLowF = new TextField<String>(
    1157       PlotFileSpectrum.VMASSCUTOFFLOWSTR);
    1158     cutoffLowF.setLabel("SpectrumMassCutoffLow");
    1159     if (massCutoffLow != null)
    1160     {
    1161       cutoffLowF.setValue(massCutoffLow);
    1162     }
    1163     massRangeFS.add(cutoffLowF);
    1164     //
    1165     TextField<String> cutoffHighF = new TextField<String>(
    1166       PlotFileSpectrum.VMASSCUTOFFHIGHSTR);
    1167     cutoffHighF.setLabel("SpectrumMassCutoffHigh");
    1168     if (massCutoffHigh != null)
    1169     {
    1170       cutoffHighF.setValue(massCutoffHigh);
    1171     }
    1172     massRangeFS.add(cutoffHighF);
    1173     //
    1174     TextField<String> spectrumIdF = new TextField<String>(
    1175       PlotFileSpectrum.VSPECTRUMID);
    1176     spectrumIdF.setHidden(true);
    1177     spectrumIdF.setValue(spectrumId);
    1178     massRangeFS.add(spectrumIdF);
    1179     /***********************************************************************
    1180      * Form
    1181      */
    1182     Form form = new Form("MassRangeSelectionForm");
    1183     form.setTitle("MassRangeSelectionForm");
    1184     form.addFieldset(massRangeFS);
    1185     return form;
    1186   }
    1187 
    1188 
    1189   /**
    1190    * Returns a form with spectrum properties for a spectrum obtained from a
    1191    * spectrum file.
    1192    *
    1193    * @param spectrumFile File Core file with spectrum.
    1194    * @param spectrumId String Spectrum id string.
    1195    * @param spectrum SpectrumInterface spectrum data.
    1196    * @return Form for displaying spectrum properties
    1197    */
    1198   public Form getSpectrumPropertiesForm(File spectrumFile, String spectrumId,
    1199       SpectrumInterface spectrum)
    1200   {
    1201     /***********************************************************************
    1202      * Properties fieldset
    1203      */
    1204     Fieldset propertiesFS = new Fieldset();
    1205     //
    1206     Table propertiesTable = new Table("Properties");
    1207     propertiesTable.setTitle("Properties");
    1208     propertiesTable.add(new Column<String>("Property"));
    1209     propertiesTable.add(new Column<String>("Value"));
    1210     propertiesFS.add(propertiesTable);
    1211     /*
    1212      * File name
    1213      */
    1214     String peakListFileName = null;
    1215     if (spectrumFile != null)
    1216     {
    1217       peakListFileName = spectrumFile.getName();
    1218     }
    1219     addTableRow(propertiesTable, "Filename", peakListFileName, null, 0);
    1220     /*
    1221      * File type
    1222      */
    1223     String spectrumFileType = null;
    1224     if (spectrumFile != null)
    1225     {
    1226       if (spectrumFile.getFileType() != null)
    1227       {
    1228         spectrumFileType = spectrumFile.getFileType().getName();
    1229       }
    1230     }
    1231     addTableRow(propertiesTable, "FileType", spectrumFileType, null, 0);
    1232     /*
    1233      * SpectrumId
    1234      */
    1235     String spectrumIdStr = null;
    1236     if (spectrumId != null)
    1237     {
    1238       spectrumIdStr = spectrumId;
    1239     }
    1240     addTableRow(propertiesTable, "SpectrumId", spectrumIdStr, null, 0);
    1241     /*
    1242      * Retention time in minutes
    1243      */
    1244     String timeInMinutesStr = null;
    1245     if (spectrum != null)
    1246     {
    1247       Float retentionTimeInMinutes = null;
    1248       if (spectrum.getRetentionTimeInMinutes() != null)
    1249       {
    1250         retentionTimeInMinutes = spectrum.getRetentionTimeInMinutes()
    1251           .floatValue();
    1252       }
    1253       if (retentionTimeInMinutes != null)
    1254       {
    1255         timeInMinutesStr = retentionTimeInMinutes.toString();
    1256       }
    1257     }
    1258     addTableRow(propertiesTable, "RetentionTimeInMinutes",
    1259       timeInMinutesStr, null, 0);
    1260     /***********************************************************************
    1261      * Optional spectrum fieldset
    1262      */
    1263     Table precursorTable = null;
    1264     if (spectrum != null)
    1265     {
    1266       if (spectrum.getPrecursors() != null)
    1267       {
    1268         /***************************************************************
    1269          * Precursors
    1270          */
    1271         int precursorNo = 0;
    1272         for (SpectrumPrecursor pc : spectrum.getPrecursors())
    1273         {
    1274           precursorNo++;
    1275           precursorTable = new Table("Precursor");
    1276           // Only print table header for first table
    1277           if (precursorNo == 1)
    1278           {
    1279             precursorTable.setTitle("Precursor");
    1280           }
    1281           precursorTable.add(new Column<String>("Property"));
    1282           precursorTable.add(new Column<String>("Value"));
    1283           // Get precursor ion data from selected ion list, if
    1284           // existing
    1285           List<PrecursorSelectedIon> selectedIonList = pc
    1286             .getSelectedIonList();
    1287           if (selectedIonList != null && selectedIonList.size() > 0)
    1288           {
    1289             for (PrecursorSelectedIon selectedIon : selectedIonList)
    1290             {
    1291               addTableRow(precursorTable, "charge state",
    1292                 selectedIon.getCharge(), null, 0);
    1293               addTableRow(precursorTable, "m/z", selectedIon
    1294                 .getMassToChargeRatio(), null, 0);
    1295               addTableRow(precursorTable, "intensity",
    1296                 selectedIon.getIntensity(), null, 0);
    1297               // Selected ion extra data
    1298               List<StringPairInterface> dataList = selectedIon
    1299                 .getExtraDataList();
    1300               if (dataList != null)
    1301               {
    1302                 for (int i = 0; i < dataList.size(); i++)
    1303                 {
    1304                   StringPairInterface data = dataList.get(i);
    1305                   if (data != null)
    1306                   {
    1307                     String name = data.getName();
    1308                     String value = data.getValue();
    1309                     if (name != null && !name.equals(""))
    1310                     {
    1311                       addTableRow(precursorTable, name,
    1312                         value, null, 0);
    1313                     }
    1314                   }
    1315                 }
    1316               }
    1317             }
    1318           }
    1319           else
    1320           {
    1321             addTableRow(precursorTable, "charge state", pc
    1322               .getCharge(), null, 0);
    1323             addTableRow(precursorTable, "m/z", pc
    1324               .getMassToChargeRatio(), null, 0);
    1325             addTableRow(precursorTable, "intensity", pc
    1326               .getIntensity(), null, 0);
    1327           }
    1328           /*
    1329            * Precursor extra data
    1330            */
    1331           List<StringPairInterface> dataList = pc.getExtraDataList();
    1332           if (dataList != null)
    1333           {
    1334             for (int i = 0; i < dataList.size(); i++)
    1335             {
    1336               StringPairInterface data = dataList.get(i);
    1337               if (data != null)
    1338               {
    1339                 String name = data.getName();
    1340                 String value = data.getValue();
    1341                 if (name != null && !name.equals(""))
    1342                 {
    1343                   addTableRow(precursorTable, name, value,
    1344                     null, 0);
    1345                 }
    1346               }
    1347             }
    1348           }
    1349           /*
    1350            * Precursor fragmentation type
    1351            */
    1352           SpectrumPrecursor.FragmentationType fragmentationType = pc
    1353             .getFragmentationType();
    1354           String fragmentationTypeStr = new String(
    1355             "FragmentationType");
    1356           addTableRow(precursorTable, fragmentationTypeStr,
    1357             fragmentationType, null, 0);
    1358           //
    1359           propertiesFS.add(precursorTable);
    1360         }
    1361       }
    1362       if (spectrum.getExtraDataList() != null && spectrum
    1363         .getExtraDataList().size() > 0)
    1364       {
    1365         /*
    1366          * Extra data.
    1367          */
    1368         Table extraDataTable = new Table("AdditionalInformation");
    1369         extraDataTable.setTitle("AdditionalInformation");
    1370         extraDataTable.add(new Column<String>("Property"));
    1371         extraDataTable.add(new Column<String>("Value"));
    1372         List<StringPairInterface> dataList = spectrum
    1373           .getExtraDataList();
    1374         if (dataList != null)
    1375         {
    1376           for (int i = 0; i < dataList.size(); i++)
    1377           {
    1378             StringPairInterface data = dataList.get(i);
    1379             if (data != null)
    1380             {
    1381               String name = data.getName();
    1382               String value = data.getValue();
    1383               if (name != null && !name.equals(""))
    1384               {
    1385                 addTableRow(extraDataTable, name, value, null,
    1386                   0);
    1387               }
    1388             }
    1389           }
    1390         }
    1391         propertiesFS.add(extraDataTable);
    1392       }
    1393     }
    1394     /***********************************************************************
    1395      * Form
    1396      */
    1397     Form form = new Form("SpectrumProperties");
    1398     form.addFieldset(propertiesFS);
    1399     return form;
    1400   }
    1401 
    1402 
    1403   /**
    1404    * Returns a form with spectrum file instrument data for a spectrum file.
    1405    *
    1406    * @param spectrumFileInstrumentList List<SpectrumFileInstrumentInterface>
    1407    *        Spectrum file instrument list.
    1408    * @return Form for displaying spectrum file instrument data.
    1409    */
    1410   public Form getSpectrumFileInstrumentForm(
    1411       List<SpectrumFileInstrumentInterface> spectrumFileInstrumentList)
    1412   {
    1413     if (spectrumFileInstrumentList == null || spectrumFileInstrumentList
    1414       .size() == 0)
    1415     {
    1416       return null;
    1417     }
    1418     /***********************************************************************
    1419      * Instrument fieldset
    1420      */
    1421     Fieldset instrumentFS = new Fieldset();
    1422     int instrumentNo = 0;
    1423     for (SpectrumFileInstrumentInterface spectrumFileInstrument : spectrumFileInstrumentList)
    1424     {
    1425       instrumentNo++;
    1426       List<StringPairInterface> dataList;
    1427       /*
    1428        * Name field.
    1429        */
    1430       Table instrumentGeneralTable = new Table(
    1431         "InstrumentGeneralInformation");
    1432       // Only print table header for first table
    1433       if (instrumentNo == 1)
    1434       {
    1435         instrumentGeneralTable.setTitle("InstrumentInformation");
    1436       }
    1437       // instrumentGeneralTable.add(new Column<String>("Property"));
    1438       instrumentGeneralTable.add(new Column<String>("InstrumentGeneral"));
    1439       instrumentGeneralTable.add(new Column<String>("Value"));
    1440       String instrumentName = null;
    1441       if (spectrumFileInstrument != null)
    1442       {
    1443         instrumentName = spectrumFileInstrument.getInstrumentName();
    1444       }
    1445       addTableRow(instrumentGeneralTable, "InstrumentName",
    1446         instrumentName, null, 0);
    1447       // instrumentFS.add(instrumentGeneralTable);
    1448       /*
    1449        * Serial No field.
    1450        */
    1451       String instrumentSerialNo = null;
    1452       if (spectrumFileInstrument != null)
    1453       {
    1454         instrumentSerialNo = spectrumFileInstrument
    1455           .getInstrumentSerialNo();
    1456       }
    1457       addTableRow(instrumentGeneralTable, "InstrumentSerialNo",
    1458         instrumentSerialNo, null, 0);
    1459       instrumentFS.add(instrumentGeneralTable);
    1460       /*
    1461        * Source field.
    1462        */
    1463       Table sourceTable = new Table("SourceInformation");
    1464       // sourceTable.setTitle("SourceInformation");
    1465       // sourceTable.add(new Column<String>("Property"));
    1466       sourceTable.add(new Column<String>("SourceInformation"));
    1467       sourceTable.add(new Column<String>("Value"));
    1468       dataList = spectrumFileInstrument.getSource();
    1469       if (dataList != null)
    1470       {
    1471         for (int i = 0; i < dataList.size(); i++)
    1472         {
    1473           StringPairInterface data = dataList.get(i);
    1474           if (data != null)
    1475           {
    1476             String name = data.getName();
    1477             String value = data.getValue();
    1478             if (name != null && !name.equals(""))
    1479             {
    1480               addTableRow(sourceTable, name, value, null, 0);
    1481             }
    1482           }
    1483         }
    1484       }
    1485       instrumentFS.add(sourceTable);
    1486       /*
    1487        * AnalyzerList field.
    1488        */
    1489       List<SpectrumFileAnalyzerInterface> analyzerList = spectrumFileInstrument
    1490         .getAnalyzers();
    1491       if (analyzerList != null)
    1492       {
    1493         for (int j = 0; j < analyzerList.size(); j++)
    1494         {
    1495           Table analyzerTable = new Table("AnalyzerListInformation");
    1496           /*
    1497            * // Only add table title header for first table if (j ==
    1498            * 0) { analyzerTable.setTitle("AnalyzerListInformation"); }
    1499            */
    1500           // analyzerTable.add(new Column<String>("Property"));
    1501           analyzerTable
    1502             .add(new Column<String>("AnalyzerInformation"));
    1503           analyzerTable.add(new Column<String>("Value"));
    1504           SpectrumFileAnalyzerInterface analyzer = analyzerList
    1505             .get(j);
    1506           if (analyzer != null)
    1507           {
    1508             dataList = analyzer.getAnalyzer();
    1509             if (dataList != null)
    1510             {
    1511               for (int i = 0; i < dataList.size(); i++)
    1512               {
    1513                 StringPairInterface data = dataList.get(i);
    1514                 if (data != null)
    1515                 {
    1516                   String name = data.getName();
    1517                   String value = data.getValue();
    1518                   if (name != null && !name.equals(""))
    1519                   {
    1520                     addTableRow(analyzerTable, name, value,
    1521                       null, 0);
    1522                   }
    1523                 }
    1524               }
    1525             }
    1526           }
    1527           instrumentFS.add(analyzerTable);
    1528         }
    1529       }
    1530       /*
    1531        * Detector field.
    1532        */
    1533       Table detectorTable = new Table("DetectorInformation");
    1534       // detectorTable.setTitle("DetectorInformation");
    1535       // detectorTable.add(new Column<String>("Property"));
    1536       detectorTable.add(new Column<String>("DetectorInformation"));
    1537       detectorTable.add(new Column<String>("Value"));
    1538       dataList = spectrumFileInstrument.getDetector();
    1539       if (dataList != null)
    1540       {
    1541         for (int i = 0; i < dataList.size(); i++)
    1542         {
    1543           StringPairInterface data = dataList.get(i);
    1544           if (data != null)
    1545           {
    1546             String name = data.getName();
    1547             String value = data.getValue();
    1548             if (name != null && !name.equals(""))
    1549             {
    1550               addTableRow(detectorTable, name, value, null, 0);
    1551             }
    1552           }
    1553         }
    1554       }
    1555       instrumentFS.add(detectorTable);
    1556       /*
    1557        * Additional field.
    1558        */
    1559       Table additionalTable = new Table("AdditionalInformation");
    1560       // additionalTable.setTitle("AdditionalInformation");
    1561       // additionalTable.add(new Column<String>("Property"));
    1562       additionalTable.add(new Column<String>("AdditionalInformation"));
    1563       additionalTable.add(new Column<String>("Value"));
    1564       dataList = spectrumFileInstrument.getAdditional();
    1565       if (dataList != null)
    1566       {
    1567         for (int i = 0; i < dataList.size(); i++)
    1568         {
    1569           StringPairInterface data = dataList.get(i);
    1570           if (data != null)
    1571           {
    1572             String name = data.getName();
    1573             String value = data.getValue();
    1574             if (name != null && !name.equals(""))
    1575             {
    1576               addTableRow(additionalTable, name, value, null, 0);
    1577             }
    1578           }
    1579         }
    1580       }
    1581       instrumentFS.add(additionalTable);
    1582     }
    1583     /***********************************************************************
    1584      * Form
    1585      */
    1586     Form form = new Form("InstrumentInformation");
    1587     form.addFieldset(instrumentFS);
    1588     return form;
    1589   }
    1590 
    1591 
    1592   /**
    1593    * Adds a table row to a table. A "value" argument that is null will be
    1594    * represented as an empty string, otherwise by its toString() value.
    1595    *
    1596    * @param table Table The table to add a row to.
    1597    * @param nameKey String Property key string.
    1598    * @param value Object Property value object.
    1599    * @param actionClass Class<E extends ProteiosAction> Optional value cell
    1600    *        action.
    1601    * @param itemId int The item id to use for an optional action.
    1602    */
    1603   private void addTableRow(Table table, String nameKey, Object value,
    1604       Class<? extends ProteiosAction> actionClass, int itemId)
    1605   {
    1606     // Convert value to string, with empty string for null value
    1607     String valueStr = new String("");
    1608     if (value != null)
    1609     {
    1610       // Convert value to string
    1611       valueStr = "" + value;
    1612     }
    1613     //
    1614     // Construct row
    1615     String rowTitle = new String(nameKey);
    1616     Row row = new Row(rowTitle);
    1617     Cell<String> nameCell = new Cell<String>(locale.get(nameKey));
    1618     Cell<String> valueCell = new Cell<String>(valueStr);
    1619     // Check if value cell should be coupled to action
    1620     if (actionClass != null)
    1621     {
    1622       // Add action link to value cell
    1623       ActionLink cellAction = actionFactory.getActionLink(
    1624         actionClass, actionClass.getName());
    1625       cellAction.addParameter(ItemIdField.VPARAM, itemId);
    1626       valueCell.setActionLink(cellAction);
    1627     }
    1628     row.addCell(nameCell);
    1629     row.addCell(valueCell);
    1630     table.addRow(row);
    1631   }
    1632 
    1633 
    1634   /**
    1635    * Returns a form with spectrum file contact data for a spectrum file.
    1636    *
    1637    * @param spectrumContact Spectrum file contact
    1638    *        data.
    1639    * @return Form for displaying spectrum file contact data.
    1640    */
    1641   public Form getSpectrumFileContactForm(
    1642       SpectrumFileContactInterface spectrumContact)
    1643   {
    1644     if (spectrumContact == null)
    1645     {
    1646       return null;
    1647     }
    1648     /***********************************************************************
    1649      * Contact fieldset
    1650      */
    1651     Fieldset contactFS = new Fieldset();
    1652     //
    1653     Table contactTable = new Table("ContactInformation");
    1654     contactTable.setTitle("ContactInformation");
    1655     contactTable.add(new Column<String>("Property"));
    1656     contactTable.add(new Column<String>("Value"));
    1657     contactFS.add(contactTable);
    1658     /*
    1659      * Name
    1660      */
    1661     String name = null;
    1662     if (spectrumContact != null)
    1663     {
    1664       name = spectrumContact.getName();
    1665     }
    1666     addTableRow(contactTable, "Name", name, null, 0);
    1667     /*
    1668      * Institution
    1669      */
    1670     String institution = null;
    1671     if (spectrumContact != null)
    1672     {
    1673       institution = spectrumContact.getInstitution();
    1674     }
    1675     addTableRow(contactTable, "Institution", institution, null, 0);
    1676     /*
    1677      * ContactInfo
    1678      */
    1679     String contactInfo = null;
    1680     if (spectrumContact != null)
    1681     {
    1682       contactInfo = spectrumContact.getContactInfo();
    1683     }
    1684     addTableRow(contactTable, "ContactInfo", contactInfo, null, 0);
    1685     /*
    1686      * Address
    1687      */
    1688     String address = null;
    1689     if (spectrumContact != null)
    1690     {
    1691       address = spectrumContact.getAddress();
    1692     }
    1693     addTableRow(contactTable, "Address", address, null, 0);
    1694     /*
    1695      * URL
    1696      */
    1697     String url = null;
    1698     if (spectrumContact != null)
    1699     {
    1700       url = spectrumContact.getUrl();
    1701     }
    1702     addTableRow(contactTable, "URL", url, null, 0);
    1703     /*
    1704      * Email
    1705      */
    1706     String email = null;
    1707     if (spectrumContact != null)
    1708     {
    1709       email = spectrumContact.getEmail();
    1710     }
    1711     addTableRow(contactTable, "Email", email, null, 0);
    1712     /***********************************************************************
    1713      * Form
    1714      */
    1715     Form form = new Form("ContactInformation");
    1716     form.addFieldset(contactFS);
    1717     return form;
    1718   }
    1719 
    1720 
    1721   /**
    1722    * Returns a form for adding spectrum file contact data for a spectrum file.
    1723    *
    1724    * @param project Project The project in whose directory a new output
    1725    *        directory is created.
    1726    * @param outputDirNameDefault String The default name of the output
    1727    *        directory.
    1728    * @param user User The user from whose profile default contact information
    1729    *        should be taken.
    1730    * @return Form for displaying spectrum file contact data.
    1731    */
    1732   public Form getSpectrumFileContactInputForm(Project project,
    1733       String outputDirNameDefault, User user)
    1734   {
    1735     Form form = new Form("spectrumFileContactInputForm");
    1736     // Get potential default contact information from user profile
    1737     String defaultName = new String("");
    1738     String defaultInstitution = new String("");
    1739     String defaultAddress = new String("");
    1740     String defaultEmail = new String("");
    1741     String defaultContactInfo = new String("");
    1742     if (user != null)
    1743     {
    1744       // Default name
    1745       if (user.getName() != null)
    1746       {
    1747         defaultName = user.getName();
    1748       }
    1749       // Default institution
    1750       if (user.getOrganisation() != null)
    1751       {
    1752         defaultInstitution = user.getOrganisation();
    1753       }
    1754       // Default address
    1755       if (user.getAddress() != null)
    1756       {
    1757         defaultAddress = user.getAddress();
    1758       }
    1759       // Default e-mail
    1760       if (user.getEmail() != null)
    1761       {
    1762         defaultEmail = user.getEmail();
    1763       }
    1764       // Default contact info
    1765       defaultContactInfo = addContactInfoElement(defaultContactInfo,
    1766         "Name", defaultName);
    1767       defaultContactInfo = addContactInfoElement(defaultContactInfo,
    1768         "Institution", defaultInstitution);
    1769       defaultContactInfo = addContactInfoElement(defaultContactInfo,
    1770         "Address", defaultAddress);
    1771       defaultContactInfo = addContactInfoElement(defaultContactInfo,
    1772         "Phone", user.getPhone());
    1773       defaultContactInfo = addContactInfoElement(defaultContactInfo,
    1774         "Fax", user.getFax());
    1775       defaultContactInfo = addContactInfoElement(defaultContactInfo,
    1776         "e-mail", defaultEmail);
    1777     }
    1778     //
    1779     Fieldset contactInputFS = new Fieldset();
    1780     contactInputFS.setTitle("SpectrumFileContactInput");
    1781     form.addFieldset(contactInputFS);
    1782     //
    1783     TextField<String> nameF = new TextField<String>(VNONREQUIRED_NAME);
    1784     nameF.setValue(defaultName);
    1785     nameF.setLabel("Name");
    1786     contactInputFS.add(nameF);
    1787     //
    1788     TextField<String> institutionF = new TextField<String>(
    1789       VNONREQUIRED_INSTITUTION);
    1790     institutionF.setValue(defaultInstitution);
    1791     institutionF.setLabel("Institution");
    1792     contactInputFS.add(institutionF);
    1793     //
    1794     TextField<String> contactInfoF = new TextField<String>(
    1795       VNONREQUIRED_CONTACT_INFO);
    1796     contactInfoF.setValue(defaultContactInfo);
    1797     contactInfoF.setLabel("ContactInfo");
    1798     contactInputFS.add(contactInfoF);
    1799     //
    1800     TextField<String> addressF = new TextField<String>(VNONREQUIRED_ADDRESS);
    1801     addressF.setValue(defaultAddress);
    1802     addressF.setLabel("Address");
    1803     contactInputFS.add(addressF);
    1804     //
    1805     TextField<String> urlF = new TextField<String>(VNONREQUIRED_URL);
    1806     urlF.setValue("");
    1807     urlF.setLabel("URL");
    1808     contactInputFS.add(urlF);
    1809     //
    1810     TextField<String> emailF = new TextField<String>(VNONREQUIRED_EMAIL);
    1811     emailF.setValue(defaultEmail);
    1812     emailF.setLabel("email");
    1813     contactInputFS.add(emailF);
    1814     //
    1815     Fieldset contactOutputFS = new Fieldset();
    1816     contactOutputFS.setTitle("SpectrumFileContactOutput");
    1817     form.addFieldset(contactOutputFS);
    1818     //
    1819     TextField<String> outputDirNameF = new TextField<String>(
    1820       VNONREQUIRED_FILENAME);
    1821     outputDirNameF.setValue(outputDirNameDefault);
    1822     outputDirNameF.setLabel("OutputDirectoryName");
    1823     contactOutputFS.add(outputDirNameF);
    1824     //
    1825     /*
    1826      * Checkbox<VBoolean> overwriteExistingContactDataCB = new Checkbox<VBoolean>(
    1827      * SpectrumFileContactDataAdder.VOVERWRITEEXISTINGCONTACTDATAFLAG);
    1828      * overwriteExistingContactDataCB.setLabel("OverwriteExistingContactData");
    1829      * overwriteExistingContactDataCB.setValue("true");
    1830      * overwriteExistingContactDataCB.isChecked(true);
    1831      * contactOutputFS.add(overwriteExistingContactDataCB);
    1832      */
    1833     //
    1834     return form;
    1835   }
    1836 
    1837 
    1838   /**
    1839    * Adds an element of data to contact info string.
    1840    *
    1841    * @param contactInfo String Current contact info string.
    1842    * @param elementName String Name of contact info element.
    1843    * @param elementValue String Contents of contact info element.
    1844    * @return String Contact info string with the added info data.
    1845    */
    1846   private String addContactInfoElement(String contactInfo,
    1847       String elementName, String elementValue)
    1848   {
    1849     if (elementValue != null && !elementValue.equals(""))
    1850     {
    1851       if (!contactInfo.equals(""))
    1852       {
    1853         contactInfo += ", ";
    1854       }
    1855       contactInfo += elementName + ": " + elementValue;
    1856     }
    1857     return contactInfo;
    1858   }
    1859 
    1860 
    1861   /**
    1862    * Returns a form for adding spectrum file sample data for a spectrum file.
    1863    *
    1864    * @param project Project The project in whose directory a new output
    1865    *        directory is created.
    1866    * @param outputDirNameDefault String The default name of the output
    1867    *        directory.
    1868    * @return Form for displaying spectrum file contact data.
    1869    */
    1870   public Form getSpectrumFileSampleInputForm(Project project,
    1871       String outputDirNameDefault)
    1872   {
    1873     Form form = new Form("spectrumFileSampleInputForm");
    1874     //
    1875     Fieldset sampleInputFS = new Fieldset();
    1876     sampleInputFS.setTitle("SpectrumFileSampleInput");
    1877     form.addFieldset(sampleInputFS);
    1878     //
    1879     TextField<String> nameF = new TextField<String>(
    1880       VNONREQUIRED_SAMPLE_NAME);
    1881     nameF.setValue("");
    1882     nameF.setLabel("SampleName");
    1883     sampleInputFS.add(nameF);
    1884     //
    1885     TextField<String> numberF = new TextField<String>(
    1886       VNONREQUIRED_SAMPLE_NUMBER);
    1887     numberF.setValue("");
    1888     numberF.setLabel("SampleNumber");
    1889     sampleInputFS.add(numberF);
    1890     //
    1891     /*
    1892      * TextField<String> stateF = new TextField<String>(VNONREQUIRED_SAMPLE_STATE);
    1893      * stateF.setValue(""); stateF.setLabel("SampleState");
    1894      * sampleInputFS.add(stateF);
    1895      */
    1896     // Sample state select box
    1897     VString validStringParam = VNONREQUIRED_SAMPLE_STATE;
    1898     List<Option> optionList = new ArrayList<Option>();
    1899     optionList.add(new Option("emulsion", "emulsion").setSelected(true));
    1900     optionList.add(new Option("gas", "gas"));
    1901     optionList.add(new Option("liquid", "liquid"));
    1902     optionList.add(new Option("solid", "solid"));
    1903     optionList.add(new Option("solution", "solution"));
    1904     optionList.add(new Option("suspension", "suspension"));
    1905     String selected = new String("emulsion");
    1906     Select<VString> stateSelectBox = new Select<VString>(validStringParam,  optionList);
    1907   stateSelectBox.selectOption(selected);
    1908     stateSelectBox.setLabel("SampleState");
    1909     sampleInputFS.add(stateSelectBox);
    1910     //
    1911     TextField<String> massF = new TextField<String>(
    1912       VNONREQUIRED_SAMPLE_MASS_IN_GRAMS);
    1913     massF.setValue("");
    1914     massF.setLabel("SampleMassInGrams");
    1915     sampleInputFS.add(massF);
    1916     //
    1917     TextField<String> volumeF = new TextField<String>(
    1918       VNONREQUIRED_SAMPLE_VOLUME_IN_MILLILITERS);
    1919     volumeF.setValue("");
    1920     volumeF.setLabel("SampleVolumeInMilliliters");
    1921     sampleInputFS.add(volumeF);
    1922     //
    1923     TextField<String> concentrationF = new TextField<String>(
    1924       VNONREQUIRED_SAMPLE_CONCENTRATION_IN_GRAMS_PER_LITER);
    1925     concentrationF.setValue("");
    1926     concentrationF.setLabel("SampleConcentrationInGramsPerLiter");
    1927     sampleInputFS.add(concentrationF);
    1928     //
    1929     TextField<String> batchF = new TextField<String>(
    1930       VNONREQUIRED_SAMPLE_BATCH);
    1931     batchF.setValue("");
    1932     batchF.setLabel("SampleBatch");
    1933     sampleInputFS.add(batchF);
    1934     //
    1935     TextField<String> commentF = new TextField<String>(
    1936       VNONREQUIRED_SAMPLE_COMMENT);
    1937     commentF.setValue("");
    1938     commentF.setLabel("SampleComment");
    1939     sampleInputFS.add(commentF);
    1940     //
    1941     Fieldset sampleOutputFS = new Fieldset();
    1942     sampleOutputFS.setTitle("SpectrumFileSampleOutput");
    1943     form.addFieldset(sampleOutputFS);
    1944     //
    1945     TextField<String> outputDirNameF = new TextField<String>(
    1946       VNONREQUIRED_FILENAME);
    1947     outputDirNameF.setValue(outputDirNameDefault);
    1948     outputDirNameF.setLabel("OutputDirectoryName");
    1949     sampleOutputFS.add(outputDirNameF);
    1950     //
    1951     /*
    1952      * Checkbox<VBoolean> overwriteExistingSampleDataCB = new Checkbox<VBoolean>(
    1953      * SpectrumFileSampleDataAdder.VOVERWRITEEXISTINGSAMPLEDATAFLAG);
    1954      * overwriteExistingSampleDataCB.setLabel("OverwriteExistingSampleData");
    1955      * overwriteExistingSampleDataCB.setValue("true");
    1956      * overwriteExistingSampleDataCB.isChecked(true);
    1957      * sampleOutputFS.add(overwriteExistingSampleDataCB);
    1958      */
    1959     //
    1960     return form;
    1961   }
    1962 
    1963 
    1964   private <D extends Object> TextField<D> newTextField(String name, D value)
    1965   {
    1966     TextField<D> field = new TextField<D>(new VInteger(name, 0, false));
    1967     field.setLabel(name);
    1968     field.setValue(value);
    1969     field.setDisabled(true);
    1970     return field;
    1971   }
    1972 
    1973 
    1974 
    1975 
    1976 
    1977   public Form getPeakListSetForm(PeakListSet pls)
    1978   {
    1979     /***********************************************************************
    1980      * Properties fieldset
    1981      */
    1982     Fieldset properties = new Fieldset();
    1983     properties.setTitle("Properties");
    1984     // id
    1985     TextField<Integer> itemIdF = newHiddenItemIdField();
    1986     properties.add(itemIdF);
    1987     // Name field
    1988     TextField<String> nameF = new NameField();
    1989     properties.add(nameF);
    1990     // Description field
    1991     TextArea descrF = new DescriptionField();
    1992     properties.add(descrF);
    1993     /***********************************************************************
    1994      * Hardware configuration
    1995      */
    1996     Fieldset instrumentFS = new Fieldset();
    1997     instrumentFS.setTitle("Instrument");
    1998     /***********************************************************************
    1999      * Analyzers
    2000      */
    2001     Fieldset analyzersFS = new Fieldset();
    2002     analyzersFS.setTitle("Analyzers");
    2003     /***********************************************************************
    2004      * Set field values
    2005      */
    2006     if (pls != null)
    2007     {
    2008       DbControl dc = pls.getDbControl();
    2009       Hardware hw = pls.getInstrument();
    2010       if (hw != null)
    2011         instrumentFS.add(newTextField("Hardware", hw.getName()));
    2012       /*******************************************************************
    2013        * Analyzer annotation values
    2014        */
    2015       List<HardwareConfiguration> analyzerList = pls.getAnalyzers();
    2016       if (analyzerList != null)
    2017       {
    2018         Iterator<HardwareConfiguration> iter = analyzerList.iterator();
    2019         while (iter.hasNext())
    2020         {
    2021           HardwareConfiguration hwc = iter.next();
    2022           addAnnotationsAsFields(analyzersFS, hwc, dc);
    2023           if (iter.hasNext())
    2024             analyzersFS.add(new Separator());
    2025         }
    2026       }
    2027       /*******************************************************************
    2028        * PeakListSet values
    2029        */
    2030       itemIdF.setValue(pls.getId());
    2031       nameF.setValue(pls.getName());
    2032       descrF.setValue(pls.getDescription());
    2033     }
    2034     /***********************************************************************
    2035      * Form
    2036      */
    2037     Form form = new Form("peakListSetForm");
    2038     form.setTitle("Peaklistset");
    2039     form.addFieldset(properties);
    2040     form.addFieldset(instrumentFS);
    2041     form.addFieldset(analyzersFS);
    2042     return form;
    2043   }
    2044 
    2045 
    2046   public Form getExportPeakListSetForm(PeakListSet pls)
    2047   {
    2048     /***********************************************************************
    2049      * Properties
    2050      */
    2051     Fieldset fs = new Fieldset();
    2052     fs.setTitle("ExportProperties");
    2053     // Peaklist name field
    2054     if (pls != null)
    2055     {
    2056       TextField<String> plsNameF = newTextField("Peaklistset", pls
    2057         .getName());
    2058       fs.add(plsNameF);
    2059     }
    2060     // id
    2061     TextField<Integer> itemIdF = newHiddenItemIdField();
    2062     fs.add(itemIdF);
    2063     // Select plugin field
    2064     Select<VInteger> typeS = new PluginSelect();
    2065     if (pls != null)
    2066     {
    2067       itemIdF.setValue(pls.getId());
    2068       // TODO gregory query only file plugins
    2069       ItemQuery<PluginDefinition> query = PluginDefinition.getQuery();
    2070       query.include(Include.SHARED);
    2071       for (PluginDefinition pd : query.list(pls.getDbControl()))
    2072       {
    2073         if (pd.getMainType().equals(Plugin.MainType.EXPORT))
    2074         {
    2075           Option o = new Option(pd.getId(), pd.getName());
    2076           typeS.addOption(o);
    2077         }
    2078       }
    2079     }
    2080     fs.add(typeS);
    2081     // Name field
    2082     TextField<String> nameF = new NameField();
    2083     nameF.setLabel("FileName");
    2084     fs.add(nameF);
    2085     /***********************************************************************
    2086      * Form
    2087      */
    2088     Form form = new Form("exportPeakListSetForm");
    2089     form.addFieldset(fs);
    2090     return form;
    2091   }
    2092 
    2093 
    2094   private void addAnnotationsAsFields(Fieldset to, Annotatable item,
    2095       DbControl dc)
    2096   {
    2097     // This should probably not be here, a global ItemFactory might be
    2098     // better, investigate!
    2099     ItemFactory factory = new ItemFactory(dc);
    2100     Annotator anna = new Annotator(factory);
    2101     AnnotationSet ionAS = anna.getAnnotationSet(item);
    2102     for (Annotation a : ionAS.getAnnotations().list(dc))
    2103     {
    2104       to.add(newTextField(a.getAnnotationType().getName(), a.getValues()
    2105         .get(0)));
    2106     }
    2107   }
    2108 
    2109 
    2110 
    2111   public Fieldset getProteinAssemblyFieldset(Project project)
    2112   {
    2113     DbControl dc = project.getDbControl();
    2114     Fieldset properties = new Fieldset();
    2115     if (dc != null && dc.isConnected())
    2116     {
    2117       //
    2118       TextField<String> forwardF = new ForwardField();
    2119       forwardF.setValue(CreateProteinAssemblyJob.class.getName());
    2120       properties.add(forwardF);
    2121       //
    2122       properties.add(new ExternalGelIdSelect(dc, project));
    2123       properties.add(
    2124 new LocalSampleSelect(Hit.getUniqueLocalSampleIds(project, dc))
    2125 );
    2126       TextField<String> nameF = new FileNameField();
    2127       nameF.setValue("ProteinReport.tsv");
    2128       nameF.setLabel("OutputFileName");
    2129       properties.add(nameF);
    2130     }
    2131     return properties;
    2132   }
    2133 
    2134 
    2135 
    2136 
    2137   public Select<VString> selectLocalSampleIdWithAllOption(DbControl dc,
    2138       Project project)
    2139   {
    2140     Select<VString> select = new LocalSampleSelect(Hit.getUniqueLocalSampleIds(project, dc));
    2141     // Will be disabled if no options available
    2142     if (!select.isDisabled())
    2143     {
    2144       Option allSampleIds = new Option("all");
    2145       allSampleIds.setContent("All in project");
    2146       select.addOption(allSampleIds);
    2147     }
    2148     return select;
    2149   }
    2150 
    2151 
    2152 
    2153   private Select<VInteger> newSelectLabel(LabeledExtract le, DbControl dc)
    2154   {
    2155     Select<VInteger> select = new Select<VInteger>(VLABELID);
    2156     select.setLabel("Label");
    2157     if (dc != null && dc.isConnected())
    2158     {
    2159       ItemQuery<Label> query = Label.getQuery();
    2160       query.include(Include.SHARED);
    2161       for (Label label : query.list(dc))
    2162       {
    2163         Option o = new Option("" + label.getId());
    2164         o.setContent(label.getName());
    2165         select.addOption(o);
    2166         if (le != null && le.getLabel() != null && le.getLabel()
    2167           .equals(label))
    2168           o.setSelected(true);
    2169       }
    2170     }
    2171     return select;
    2172   }
    2173 
    2174 
    2175   @SuppressWarnings("unused")
    2176   private Select<VInteger> selectDirectory(Directory dir)
    2177   {
    2178     Select<VInteger> select = new Select<VInteger>(VDIRID);
    2179     select.setLabel("Directory");
    2180     DbControl dc = dir.getDbControl();
    2181     if (dc != null && dc.isConnected())
    2182     {
    2183       directoryOptions(select, dir, 0);
    2184     }
    2185     return select;
    2186   }
    2187 
    2188 
    2189   private void directoryOptions(Select<VInteger> s, Directory parent,
    2190       int indent)
    2191   {
    2192     Option o = new Option(parent.getId(), parent.getName());
    2193     o.setIndent(indent);
    2194     s.addOption(o);
    2195     for (Directory child : parent.getSubDirectories().list(
    2196       parent.getDbControl()))
    2197     {
    2198       directoryOptions(s, child, indent + 1);
    2199     }
    2200   }
    2201 
    2202 
    2203 
    2204 
    2205 
    2206 
    2207 
    2208   /**
    2209    * Creates and adds a hidden field with an Integer value to the given form.
    2210    * Introduced to solve problem in #623
    2211    */
    2212   public void addHiddenField(Form form, VInteger param, Integer value)
    2213   {
    2214     TextField<Integer> field = new TextField<Integer>(param);
    2215     field.setValue(value);
    2216     field.setHidden(true);
    2217     form.getFieldsets().get(0).add(field);
    2218   }
    2219 
    2220 
    2221   /**
    2222    * Creates and adds a hidden field with an Integer value to the given table.
    2223    * Introduced to solve problem in #623
    2224    */
    2225   public void addHiddenField(Table table, VInteger param, Integer value)
    2226   {
    2227     TextField<Integer> field = new TextField<Integer>(param);
    2228     field.setValue(value);
    2229     field.setHidden(true);
    2230     table.add(field);
    2231   }
    2232 
    2233 
    2234   public Fieldset getUsedSampleFieldset(Sample sample)
    2235   {
    2236     Fieldset fs = new Fieldset();
    2237     fs.setTitle("UsedSample");
    2238     TextField<String> sampleIdF = new DummyField();
    2239     sampleIdF.setDisabled(true);
    2240     sampleIdF.setLabel("SampleExternalId");
    2241     sampleIdF.setValue(sample.getExternalId());
    2242     TextField<Float> usedExtractQuantityF = new TextField<Float>(VQUANTITY);
    2243     usedExtractQuantityF
    2244       .setLabel(getLocale().get("UsedSampleAvailable") + ":" + sample
    2245         .getRemainingQuantityInMicroLiters() + ")");
    2246     usedExtractQuantityF.setValue(sample
    2247       .getRemainingQuantityInMicroLiters());
    2248     fs.add(usedExtractQuantityF);
    2249     return fs;
    2250   }
    2251 
    2252 
    2253   public Fieldset getUsedExtractFieldset(Extract extract)
    2254   {
    2255     Fieldset fs = new Fieldset();
    2256     fs.setTitle("UsedExtract");
    2257     TextField<String> extractIdF = new DummyField();
    2258     extractIdF.setDisabled(true);
    2259     extractIdF.setLabel("ExtractExternalId");
    2260     extractIdF.setValue(extract.getExternalId());
    2261     TextField<Float> usedExtractQuantityF = new TextField<Float>(VQUANTITY);
    2262     usedExtractQuantityF
    2263       .setLabel(getLocale().get("UsedExtractAvailable") + ":" + extract
    2264         .getRemainingQuantityInMicroLiters() + ")");
    2265     usedExtractQuantityF.setValue(extract
    2266       .getRemainingQuantityInMicroLiters());
    2267     fs.add(usedExtractQuantityF);
    2268     return fs;
    2269   }
    2270 
    2271 
    2272   public Fieldset getUsedLabeledExtractFieldset(LabeledExtract extract)
    2273   {
    2274     Fieldset fs = new Fieldset();
    2275     fs.setTitle("UsedLabeledExtract");
    2276     TextField<String> extractIdF = new DummyField();
    2277     extractIdF.setDisabled(true);
    2278     extractIdF.setLabel("ExtractExternalId");
    2279     extractIdF.setValue(extract.getExternalId());
    2280     TextField<Float> usedExtractQuantityF = new TextField<Float>(VQUANTITY);
    2281     usedExtractQuantityF.setLabel(getLocale().get(
    2282       "UsedLabeledExtractAvailable") + ":" + extract
    2283       .getRemainingQuantityInMicroLiters() + ")");
    2284     usedExtractQuantityF.setValue(extract
    2285       .getRemainingQuantityInMicroLiters());
    2286     fs.add(usedExtractQuantityF);
    2287     return fs;
    2288   }
    2289 
    2290  //Cleaning up from here
    2291 
    2292 
    2293   public Form getSecondaryExtractForm(Extract extract, Extract fromExtract)
    2294   {
    2295     Form form = new Form("secondaryExtractForm");
    2296     form.setTitle("NewSecondaryExtract");
    2297     Fieldset fs = new Fieldset();
    2298     fs.setTitle("Properties");
    2299     form.addFieldset(fs);
    2300     //
    2301     TextField<String> nameF = new NameField();
    2302     fs.add(nameF);
    2303     //
    2304     TextField<String> externalIdF = new ExternalIdField();
    2305     fs.add(externalIdF);
    2306     //
    2307     TextArea descriptionF = new DescriptionField();
    2308     fs.add(descriptionF);
    2309     //
    2310     TextField<String> storageLocationF = new StorageLocationField();
    2311     fs.add(storageLocationF);
    2312     //
    2313     Fieldset quantityFS = new Fieldset();
    2314     quantityFS.setTitle("QuantityInMicroLiters");
    2315     form.addFieldset(quantityFS);
    2316     //
    2317     TextField<Float> quantityF = newOriginalQuantityField();
    2318     quantityF.setLabel("ExtractOriginalQuantity");
    2319     quantityFS.add(quantityF);
    2320     //
    2321     TextField<Float> concF = new ConcentrationField();
    2322     quantityFS.add(concF);
    2323     //
    2324     if (fromExtract != null)
    2325     {
    2326       nameF.setValue(fromExtract.getName());
    2327       externalIdF.setValue(fromExtract.getExternalId());
    2328       descriptionF.setValue(fromExtract.getDescription());
    2329       // storageLocationF.setValue(fromExtract.getStorageLocation());
    2330       quantityF.setValue(fromExtract.getRemainingQuantityInMicroLiters());
    2331       concF.setValue(fromExtract.getConcentrationInGramsPerLiter());
    2332     }
    2333     if (extract != null)
    2334     {
    2335       TextField<Integer> itemIdF = newHiddenItemIdField();
    2336       fs.add(itemIdF);
    2337       itemIdF.setValue(extract.getId());
    2338       nameF.setValue(extract.getName());
    2339       externalIdF.setValue(extract.getExternalId());
    2340       descriptionF.setValue(extract.getDescription());
    2341       storageLocationF.setValue(extract.getStorageLocation());
    2342       quantityF.setValue(extract.getOriginalQuantityInMicroLiters());
    2343       quantityFS.add(newRemainingQuantityField(extract
    2344         .getRemainingQuantityInMicroLiters()));
    2345       concF.setValue(extract.getConcentrationInGramsPerLiter());
    2346     }
    2347     return form;
    2348   }
    2349 
    2350 
    2351 
    2352   public Form getSecondaryLabeledExtractForm(LabeledExtract extract,
    2353       DbControl dc, LabeledExtract fromExtract)
    2354   {
    2355     Form form = new Form("secondaryLabeledExtractForm");
    2356     form.setTitle("NewSecondaryLabeledExtract");
    2357     Fieldset fs = new Fieldset();
    2358     modifyForPopup(fs);
    2359     fs.setTitle("Properties");
    2360     form.addFieldset(fs);
    2361     //
    2362     TextField<String> nameF = new NameField();
    2363     fs.add(nameF);
    2364     //
    2365     TextField<String> externalIdF = new ExternalIdField();
    2366     fs.add(externalIdF);
    2367     //
    2368     // Disallow change of label from that of source labeled extract
    2369     Select<VInteger> labelF = newSelectLabel(fromExtract, dc);
    2370     labelF.setDisabled(true);
    2371     fs.add(labelF);
    2372     //
    2373     TextArea descriptionF = new DescriptionField();
    2374     fs.add(descriptionF);
    2375     //
    2376     TextField<String> storageLocationF = new StorageLocationField();
    2377     fs.add(storageLocationF);
    2378     //
    2379     Fieldset quantityFS = new Fieldset();
    2380     quantityFS.setTitle("QuantityInMicroLiters");
    2381     form.addFieldset(quantityFS);
    2382     //
    2383     TextField<Float> quantityF = newOriginalQuantityField();
    2384     quantityF.setLabel("ExtractOriginalQuantity");
    2385     quantityFS.add(quantityF);
    2386     //
    2387     TextField<Float> concF = new ConcentrationField();
    2388     quantityFS.add(concF);
    2389     //
    2390     if (fromExtract != null)
    2391     {
    2392       nameF.setValue(fromExtract.getName());
    2393       externalIdF.setValue(fromExtract.getExternalId());
    2394       descriptionF.setValue(fromExtract.getDescription());
    2395       // storageLocationF.setValue(fromExtract.getStorageLocation());
    2396       quantityF.setValue(fromExtract.getRemainingQuantityInMicroLiters());
    2397       concF.setValue(fromExtract.getConcentrationInGramsPerLiter());
    2398     }
    2399     if (extract != null)
    2400     {
    2401       TextField<Integer> itemIdF = newHiddenItemIdField();
    2402       fs.add(itemIdF);
    2403       itemIdF.setValue(extract.getId());
    2404       nameF.setValue(extract.getName());
    2405       externalIdF.setValue(extract.getExternalId());
    2406       descriptionF.setValue(extract.getDescription());
    2407       storageLocationF.setValue(extract.getStorageLocation());
    2408       quantityF.setValue(extract.getOriginalQuantityInMicroLiters());
    2409       quantityFS.add(newRemainingQuantityField(extract
    2410         .getRemainingQuantityInMicroLiters()));
    2411       concF.setValue(extract.getConcentrationInGramsPerLiter());
    2412     }
    2413     return form;
    2414   }
    2415 
    2416 
    2417   public Form getSetFilterForm(String filterName, String filterClass,
    2418       String filterCondition, String filterValue)
    2419   {
    2420     log
    2421       .debug("FormFactory::getSetFilterForm(): Start - filterName = \"" + filterName + "\" filterClass = \"" + filterClass + "\" filterCondition = \"" + filterCondition + "\" filterValue = \"" + filterValue + "\"");
    2422     Form form = new Form("setFilterForm");
    2423     // Properties field set
    2424     Fieldset properties = new Fieldset();
    2425     properties.setTitle("ColumnFilterSettings");
    2426     form.addFieldset(properties);
    2427     // Filter name field (hidden - for transfer of value to other classes)
    2428     TextField<String> filterNameF = newHiddenStringField(VFILTERNAME);
    2429     filterNameF.setLabel(filterName);
    2430     filterNameF.setValue(filterName);
    2431     properties.add(filterNameF);
    2432     // Filter name display field (disabled - for display of value as label)
    2433     TextField<String> filterNameDisplayF = new DummyField();
    2434     filterNameDisplayF.setLabel(filterName);
    2435     filterNameDisplayF.setValue("");
    2436     filterNameDisplayF.setDisabled(true);
    2437     properties.add(filterNameDisplayF);
    2438     // Filter class field (disabled)
    2439     TextField<String> filterClassF = new TextField<String>(VFILTERCLASS);
    2440     filterClassF.setLabel("Type");
    2441     filterClassF.setValue(filterClass);
    2442     filterClassF.setDisabled(true);
    2443     properties.add(filterClassF);
    2444     // Filter condition select field
    2445     Select<VString> filterConditionS = new Select<VString>(VFILTERCONDITION);
    2446     filterConditionS.setLabel("Condition");
    2447     // Filter value field
    2448     TextField<String> filterValueF = new TextField<String>(VFILTERVALUE);
    2449     filterValueF.setLabel("FilterValue");
    2450     filterValueF.setValue(filterValue);
    2451     List<Option> optionList = new ArrayList<Option>(0);
    2452     // Set option content
    2453     if (filterClass != null && (filterClass.equals("boolean") || filterClass
    2454       .equals("Boolean")))
    2455     {
    2456       optionList.add(new Option("="));
    2457       optionList.add(new Option("!="));
    2458     }
    2459     else
    2460     {
    2461       optionList.add(new Option("="));
    2462       if (filterClass != null && (filterClass.equals("string") || filterClass
    2463         .equals("String")))
    2464       {
    2465         filterValueF.setLabel("FilterValueWildCard");
    2466       }
    2467       optionList.add(new Option("!="));
    2468       optionList.add(new Option("<="));
    2469       optionList.add(new Option("<"));
    2470       optionList.add(new Option(">"));
    2471       optionList.add(new Option(">="));
    2472     }
    2473     // Set default option
    2474     for (int i = 0; i < optionList.size(); i++)
    2475     {
    2476       if (filterCondition.equals(optionList.get(i).getContent()))
    2477       {
    2478         optionList.get(i).setSelected(true);
    2479       }
    2480     }
    2481     // Add options to select box
    2482     for (int i = 0; i < optionList.size(); i++)
    2483     {
    2484       filterConditionS.addOption(optionList.get(i));
    2485     }
    2486     properties.add(filterConditionS);
    2487     properties.add(filterValueF);
    2488     /*
    2489      * The following section stores information on previous settings in
    2490      * hidden fields, to be retrieved when the form is verified.
    2491      */
    2492     // Add forward action id
    2493     String forwardActId = getForwardActionId();
    2494     log
    2495       .debug("FormFactory::getSetFilterForm(): forwardActionId = \"" + forwardActId + "\"");
    2496     TextField<String> fwdF = newHiddenStringField(ForwardField.VPARAM);
    2497     fwdF.setValue(forwardActId);
    2498     properties.add(fwdF);
    2499     // Add sort column key
    2500     String sortClmKey = getSortColumnKey();
    2501     log
    2502       .debug("FormFactory::getSetFilterForm(): sortColumnKey = \"" + sortClmKey + "\"");
    2503     TextField<String> sortClmF = newHiddenStringField(VSORTCOLUMNKEY);
    2504     sortClmF.setValue(sortClmKey);
    2505     properties.add(sortClmF);
    2506     // Add filter setting hashmap data
    2507     addFilterSettingsToFieldset(properties);
    2508     return form;
    2509   }
    2510 
    2511 
    2512   private void addFilterSettingsToFieldset(Fieldset fs)
    2513   {
    2514     // Add filter setting hashmap data
    2515     Integer filterLstSize = getFilterListSize();
    2516     log
    2517       .debug("FormFactory::addFilterSettingsToFieldset(): filterListSize = " + filterLstSize);
    2518     if (filterLstSize != null)
    2519     {
    2520       for (int keyNum = 0; keyNum < filterLstSize; keyNum++)
    2521       {
    2522         String filterKey = null;
    2523         String filterCls = null;
    2524         String filterCnd = null;
    2525         String filterVal = null;
    2526         /*
    2527          * Note that the list and hash maps may be null here, even
    2528          * though filter list size > 0. This happens after the form has
    2529          * been displayed, and a following action verifies the form to
    2530          * have the form fields filled in with data stored in the
    2531          * request.
    2532          */
    2533         if (getFilterKeyColumnList() != null)
    2534         {
    2535           filterKey = getFilterKeyColumnList().get(keyNum);
    2536         }
    2537         if (filterKey != null && getFilterClassColumnHashMap() != null)
    2538         {
    2539           filterCls = getFilterClassColumnHashMap().get(filterKey);
    2540         }
    2541         if (filterKey != null && getFilterConditionColumnHashMap() != null)
    2542         {
    2543           filterCnd = getFilterConditionColumnHashMap()
    2544             .get(filterKey);
    2545         }
    2546         if (filterKey != null && getFilterValueColumnHashMap() != null)
    2547         {
    2548           filterVal = getFilterValueColumnHashMap().get(filterKey);
    2549         }
    2550         log
    2551           .debug(this.getClass().getSimpleName() + "::addFilterSettingsToFieldset(): keyNum = " + keyNum + " filterKey = \"" + filterKey + "\" filterClass = \"" + filterCls + "\" filterCnd = \"" + filterCnd + "\" filterVal = \"" + filterVal + "\"");
    2552         TextField<String> filterKeyF = newValueField(
    2553           "filterKey-" + keyNum, String.class);
    2554         TextField<String> filterClsF = newValueField(
    2555           "filterCls-" + keyNum, String.class);
    2556         TextField<String> filterCndF = newValueField(
    2557           "filterCnd-" + keyNum, String.class);
    2558         TextField<String> filterValF = newValueField(
    2559           "filterVal-" + keyNum, String.class);
    2560         filterKeyF.setValue(filterKey);
    2561         filterClsF.setValue(filterCls);
    2562         filterCndF.setValue(filterCnd);
    2563         filterValF.setValue(filterVal);
    2564         filterKeyF.setHidden(true);
    2565         filterClsF.setHidden(true);
    2566         filterCndF.setHidden(true);
    2567         filterValF.setHidden(true);
    2568         fs.add(filterKeyF);
    2569         fs.add(filterClsF);
    2570         fs.add(filterCndF);
    2571         fs.add(filterValF);
    2572       }
    2573     }
    2574   }
    2575 
    2576 
    2577   public TextField<Float> newOriginalQuantityField()
    2578   {
    2579     TextField<Float> field = new TextField<Float>(VORIGINALQUANTITY);
    2580     field.setLabel("Original");
    2581   field.setHelp("Micro liter");
    2582     return field;
    2583   }
    2584 
    2585 
    2586   public TextField<Float> newRemainingQuantityField(Float remainingQuantity)
    2587   {
    2588     TextField<Float> field = new TextField<Float>(VREMAININGQUANTITY);
    2589     field.setLabel("Remaining");
    2590     if (remainingQuantity != null)
    2591     {
    2592       field.setValue(remainingQuantity);
    2593     }
    2594     return field;
    2595   }
    2596 
    2597 
    2598   public TextField<Float> newQuantityField()
    2599   {
    2600     TextField<Float> field = new TextField<Float>(VQUANTITY);
    2601     field.setLabel("Quantity");
    2602     return field;
    2603   }
    2604 
    2605 
    2606   /**
    2607    * Get generic form for object.
    2608    *
    2609    * @param template template for generic form
    2610    * @return Form for editing the object
    2611    */
    2612   public Form getForm(Template template)
    2613   {
    2614     /***********************************************************************
    2615      * Analyze template
    2616      */
    2617     Form form = null;
    2618     if (template instanceof FormTemplateImpl)
    2619     {
    2620       FormTemplateImpl formTemplate = (FormTemplateImpl) template;
    2621       form = getFormImpl(formTemplate);
    2622     }
    2623     return form;
    2624   }
    2625 
    2626 
    2627   /**
    2628    * Get generic form for object.
    2629    *
    2630    * @param template template for generic form
    2631    * @return Form for editing the object
    2632    */
    2633   private Form getFormImpl(FormTemplateInterface formTemplate)
    2634   {
    2635     /***********************************************************************
    2636      * Analyze object class
    2637      */
    2638 
    2639     /*
    2640      * Get class from formTemplate itemObject or itemClass.
    2641      */
    2642     Object itemObject = null;
    2643     Class<? extends Object> itemClass = null;
    2644     if (formTemplate.getItemObject() != null)
    2645     {
    2646       itemObject = formTemplate.getItemObject();
    2647       itemClass = itemObject.getClass();
    2648     }
    2649     else if (formTemplate.getItemClass() != null)
    2650     {
    2651       itemClass = formTemplate.getItemClass();
    2652     }
    2653     /*
    2654      * Add optional extra formTemplate list of methods to be excluded.
    2655      */
    2656     if (formTemplate != null && formTemplate.getExcludedDeclMethods() != null)
    2657     {
    2658       addExcludedDeclMethods(formTemplate.getExcludedDeclMethods());
    2659     }
    2660     String clsName = new String("");
    2661     if (itemClass != null)
    2662     {
    2663       clsName = itemClass.getSimpleName();
    2664     }
    2665 
    2666     /***********************************************************************
    2667      * Main fieldset
    2668      */
    2669     Fieldset mainFS = new Fieldset();
    2670     String mainFsName = new String("Properties");
    2671     mainFS.setTitle(mainFsName);
    2672     /*
    2673      * Add forward actionId field as first field, for external use.
    2674      */
    2675     TextField<String> fwdactionF = new ForwardField();
    2676     mainFS.add(fwdactionF);
    2677     /*
    2678      * Get item id, if any.
    2679      */
    2680     int itemId = 0;
    2681     String getIdMethodName = "getId";
    2682     Method getIdMethod = fetchPublicMethodForObject(getIdMethodName,
    2683       itemClass);
    2684     if (getIdMethod != null && itemObject != null)
    2685     {
    2686       try
    2687       {
    2688         Object[] arguments = new Object[] {};
    2689         Object retobj = getIdMethod.invoke(itemObject, arguments);
    2690         String idStr = retobj.toString();
    2691         itemId = Integer.parseInt(idStr);
    2692       }
    2693       catch (InvocationTargetException e)
    2694       {
    2695         itemId = 0;
    2696       }
    2697       catch (IllegalAccessException e)
    2698       {
    2699         itemId = 0;
    2700       }
    2701       catch (java.lang.NumberFormatException e)
    2702       {
    2703         itemId = 0;
    2704       }
    2705     }
    2706     /*
    2707      * Add itemId field idF (hidden) if itemId value ok.
    2708      */
    2709     if (itemId > 0)
    2710     {
    2711       TextField<Integer> idF = newHiddenItemIdField();
    2712       mainFS.add(idF);
    2713       idF.setLabel("ItemId");
    2714       idF.setValue(itemId);
    2715       idF.setDisabled(true);
    2716     }
    2717     /*
    2718      * Add class name field cnF.
    2719      */
    2720     String classNameFull = new String("");
    2721     if (itemClass != null)
    2722     {
    2723       classNameFull = itemClass.getName();
    2724     }
    2725     TextField<String> cnF = new ClassNameField();
    2726     mainFS.add(cnF);
    2727     cnF.setHidden(true);
    2728     cnF.setLabel("ClassName");
    2729     cnF.setValue(classNameFull);
    2730     cnF.setDisabled(true);
    2731     /*
    2732      * Add readOnlyForm field rofF (hidden).
    2733      */
    2734     TextField<Boolean> rofF = newHiddenReadOnlyFormField();
    2735     mainFS.add(rofF);
    2736     rofF.setLabel("ReadOnlyForm");
    2737     rofF.setValue(formTemplate.isReadOnlyForm());
    2738     rofF.setDisabled(true);
    2739     /*
    2740      * Keep track on whether public setter methods exist, in order to know
    2741      * if a "Save" button should be added.
    2742      */
    2743     boolean hasSetterMethods = false;
    2744     /*
    2745      * Methods, declared and inherited
    2746      */
    2747     Method[] methodArr = new Method[0];
    2748     if (itemClass != null)
    2749     {
    2750       methodArr = itemClass.getMethods();
    2751     }
    2752 
    2753     /*
    2754      * Methods declared in object class (not inherited)
    2755      */
    2756     Method[] declaredMethodArr = new Method[0];
    2757     if (itemClass != null)
    2758     {
    2759       declaredMethodArr = itemClass.getDeclaredMethods();
    2760     }
    2761     for (int i = 0; i < declaredMethodArr.length; i++)
    2762     {
    2763       Method method = declaredMethodArr[i];
    2764       String modStr = methodModifierString(method);
    2765       String methodName = method.getName();
    2766       String methodReturnType = method.getReturnType().getName();
    2767       /*
    2768        * Only process declared methods not in exclude list.
    2769        */
    2770       if (!getExcludedDeclMethods().contains(methodName))
    2771       {
    2772         String attrName = new String("");
    2773         String attrValueStr = new String("");
    2774         String returnTypeStr = new String("");
    2775         boolean returnTypeOK = false;
    2776         Class<?> returnTypeOfGetterMethod = null;
    2777         /*
    2778          * Check if getter access method.
    2779          */
    2780         if (methodName.startsWith("get"))
    2781         {
    2782           /*
    2783            * Assume that attribute name can optained by skipping "get"
    2784            * in method name.
    2785            */
    2786           attrName = methodName.substring(3);
    2787           // int methodMod = declaredMethodArr[i].getModifiers();
    2788           if (method.getReturnType().getName().equals("int") || method
    2789             .getReturnType().getName().equals("java.lang.Integer") || method
    2790             .getReturnType().getName().equals("float") || method
    2791             .getReturnType().getName().equals("java.lang.Float") || method
    2792             .getReturnType().getName().equals("double") || method
    2793             .getReturnType().getName().equals("java.lang.Double") || method
    2794             .getReturnType().getName().equals("java.lang.String") || method
    2795             .getReturnType().getName().equals("java.util.Date"))
    2796           {
    2797             returnTypeOfGetterMethod = method.getReturnType();
    2798             returnTypeStr = method.getReturnType().getName();
    2799             returnTypeOK = true;
    2800           }
    2801         }
    2802         else if (methodName.startsWith("is"))
    2803         {
    2804           /*
    2805            * Assume that attribute name can optained by skipping "is"
    2806            * in method name.
    2807            */
    2808           attrName = methodName.substring(2);
    2809           // int methodMod = declaredMethodArr[i].getModifiers();
    2810           if (method.getReturnType().getName().equals("boolean") || method
    2811             .getReturnType().getName().equals("java.lang.Boolean"))
    2812           {
    2813             returnTypeOfGetterMethod = method.getReturnType();
    2814             returnTypeStr = method.getReturnType().getName();
    2815             returnTypeOK = true;
    2816           }
    2817         }
    2818         if (returnTypeOK)
    2819         {
    2820           if (itemObject != null)
    2821           {
    2822             try
    2823             {
    2824               Object[] arguments = new Object[] {};
    2825               Object retobj = method
    2826                 .invoke(itemObject, arguments);
    2827               if (retobj != null)
    2828               {
    2829                 /*
    2830                  * Return date values in "YYYY-MM-DD HH:mm:ss"
    2831                  * 24-hour format.
    2832                  */
    2833                 if (method.getReturnType().getName().equals(
    2834                   "java.util.Date"))
    2835                 {
    2836                   SimpleDateFormat dateFormat = Format.TIMESTAMP
    2837                     .getPattern();
    2838                   attrValueStr = dateFormat
    2839                     .format((Date) retobj);
    2840                 }
    2841                 else
    2842                 {
    2843                   attrValueStr = retobj.toString();
    2844                 }
    2845               }
    2846             }
    2847             catch (InvocationTargetException e)
    2848             {
    2849               log
    2850                 .warn("FormFactory::getFormImpl(): InvocationTargetException when invoking method \"" + methodName + "\":" + e);
    2851             }
    2852             catch (IllegalAccessException e)
    2853             {
    2854               log
    2855                 .warn("FormFactory::getFormImpl(): IllegalAccessException when invoking method \"" + methodName + "\":" + e);
    2856             }
    2857             log
    2858               .debug("FormFactory::getFormImpl(): methodName = \"" + methodName + "\"  returnTypeOfGetterMethod = \"" + returnTypeOfGetterMethod + "\" attrValueStr = \"" + attrValueStr + "\"");
    2859           }
    2860           /*
    2861            * Check if public accessor method for setting value exists.
    2862            */
    2863           boolean isSettable = false;
    2864           String publMethodName = new String("set" + attrName);
    2865           if (!formTemplate.isReadOnlyForm())
    2866           {
    2867             if (fetchPublicMethodForObject(publMethodName,
    2868               itemClass) != null)
    2869             {
    2870               isSettable = true;
    2871             }
    2872           }
    2873           log
    2874             .debug("FormFactory::getFormImpl(): attrName = \"" + attrName + "\" publMethodName = \"" + publMethodName + "\" isSettable = " + isSettable);
    2875           /*
    2876            * Use TextArea for Description, else TextField
    2877            */
    2878           if (attrName.equals("Description"))
    2879           {
    2880             /*
    2881              * Value text area
    2882              */
    2883             TextArea valueF = null;
    2884             if (!isSettable)
    2885             {
    2886               valueF = newValueTextArea("", String.class);
    2887             }
    2888             else
    2889             {
    2890               hasSetterMethods = true;
    2891               valueF = newValueTextArea(publMethodName,
    2892                 returnTypeOfGetterMethod);
    2893             }
    2894             mainFS.add(valueF);
    2895             valueF.setLabel(attrName);
    2896             valueF.setValue(attrValueStr);
    2897           }
    2898           else
    2899           {
    2900             /*
    2901              * Value field
    2902              */
    2903             TextField<String> valueF = null;
    2904             if (!isSettable)
    2905             {
    2906               valueF = newValueField("", String.class);
    2907             }
    2908             else
    2909             {
    2910               hasSetterMethods = true;
    2911               valueF = newValueField(publMethodName,
    2912                 returnTypeOfGetterMethod);
    2913             }
    2914             mainFS.add(valueF);
    2915             valueF.setLabel(attrName);
    2916             valueF.setValue(attrValueStr);
    2917           }
    2918         }
    2919       }
    2920     }
    2921 
    2922     /*
    2923      * Check if object supports method getAnnotationSet().
    2924      */
    2925     Fieldset annotationFS = null;
    2926     Method[] methodGeneralArr = new Method[0];
    2927     if (itemClass != null)
    2928     {
    2929       methodGeneralArr = itemClass.getMethods();
    2930     }
    2931     for (int i = 0; i < methodGeneralArr.length; i++)
    2932     {
    2933       Method method = methodGeneralArr[i];
    2934       // String modStr = methodModifierString(method);
    2935       String methodName = method.getName();
    2936       if (methodName.equals("getAnnotationSet"))
    2937       {
    2938         /***************************************************************
    2939          * Annotation fieldset
    2940          */
    2941         annotationFS = new Fieldset();
    2942         annotationFS.setTitle("Annotations");
    2943         /*
    2944          * Get DbControl
    2945          */
    2946         DbControl dc = getDbControlForObject(itemObject);
    2947         /*
    2948          * Fetch annotations
    2949          */
    2950         if (itemObject != null)
    2951         {
    2952           try
    2953           {
    2954             Object[] arguments = new Object[] {};
    2955             Object retobj = method.invoke(itemObject, arguments);
    2956             AnnotationSet as = (AnnotationSet) retobj;
    2957             for (Annotation a : as.getAnnotations().list(dc))
    2958             {
    2959               /*
    2960                * Only add annotations that contain something.
    2961                */
    2962               String value = joinAnnotationValues(a);
    2963               if (value != null && !value.equals(""))
    2964               {
    2965                 /*
    2966                  * Value (description) field - optional scroll
    2967                  * bar
    2968                  */
    2969                 TextArea descrF = new DescriptionField();
    2970                 descrF.setDisabled(true);
    2971                 descrF
    2972                   .setLabel(a.getAnnotationType().getName());
    2973                 descrF.setValue(value);
    2974                 annotationFS.add(descrF);
    2975               }
    2976             }
    2977           }
    2978           catch (InvocationTargetException e)
    2979           {
    2980             log
    2981               .warn("FormFactory::getFormImpl(): InvocationTargetException when invoking method \"" + methodName + "\":" + e);
    2982           }
    2983           catch (IllegalAccessException e)
    2984           {
    2985             log
    2986               .warn("FormFactory::getFormImpl(): IllegalAccessException when invoking method \"" + methodName + "\":" + e);
    2987           }
    2988         }
    2989       }
    2990     }
    2991     /***********************************************************************
    2992      * Form
    2993      */
    2994     String formName = new String("newForm");
    2995     if (clsName != null && clsName.length() > 0)
    2996     {
    2997       formName = clsName.substring(0, 1).toLowerCase() + clsName
    2998         .substring(1, clsName.length()) + "Form";
    2999     }
    3000     Form form = new Form(formName);
    3001     form.setTitle(clsName);
    3002     /***********************************************************************
    3003      * Add fieldsets to form
    3004      */
    3005     form.addFieldset(mainFS);
    3006     if (annotationFS != null)
    3007     {
    3008       form.addFieldset(annotationFS);
    3009     }
    3010     /*
    3011      * Return generated form.
    3012      */
    3013     return form;
    3014   }
    3015 
    3016 
    3017   /**
    3018    * Get DbControl for object.
    3019    *
    3020    * @return DbControl for the object
    3021    */
    3022   public DbControl getDbControlForObject(Object itemObject)
    3023   {
    3024     /*
    3025      * Get class from itemObject.
    3026      */
    3027     Class<? extends Object> cls = null;
    3028     if (itemObject != null)
    3029     {
    3030       cls = itemObject.getClass();
    3031     }
    3032     if (cls == null)
    3033     {
    3034       return null;
    3035     }
    3036     String clsName = cls.getSimpleName();
    3037     /*
    3038      * Check if object supports method getDbControl().
    3039      */
    3040     DbControl dc = null;
    3041     Method[] methodGeneralArr = cls.getMethods();
    3042     for (int i = 0; i < methodGeneralArr.length; i++)
    3043     {
    3044       Method method = methodGeneralArr[i];
    3045       String methodName = method.getName();
    3046       if (methodName.equals("getDbControl"))
    3047       {
    3048         /*
    3049          * Get DbControl for object
    3050          */
    3051         try
    3052         {
    3053           Object[] arguments = new Object[] {};
    3054           Object retobj = method.invoke(itemObject, arguments);
    3055           dc = (DbControl) retobj;
    3056         }
    3057         catch (InvocationTargetException e)
    3058         {
    3059           log
    3060             .warn("FormFactory::getDbControlForObject(): InvocationTargetException when invoking method \"" + methodName + "\":" + e);
    3061         }
    3062         catch (IllegalAccessException e)
    3063         {
    3064           log
    3065             .warn("FormFactory::getDbControlForObject(): IllegalAccessException when invoking method \"" + methodName + "\":" + e);
    3066         }
    3067       }
    3068     }
    3069     /*
    3070      * Return DbControl.
    3071      */
    3072     return dc;
    3073   }
    3074 
    3075 
    3076   /**
    3077    * Fetch public method for object, or null if not found.
    3078    *
    3079    * @param publMethodName String Name of public method to search for.
    3080    * @return Method public method for object with desired name, or null if not
    3081    *         found.
    3082    */
    3083   private Method fetchPublicMethodForObject(String publMethodName,
    3084       Class<? extends Object> cls)
    3085   {
    3086     if (cls == null)
    3087     {
    3088       return null;
    3089     }
    3090     String clsName = cls.getSimpleName();
    3091     /*
    3092      * Check if object supports public method with desired name.
    3093      */
    3094     Method publMethod = null;
    3095     Method[] methodGeneralArr = cls.getMethods();
    3096     for (int i = 0; i < methodGeneralArr.length; i++)
    3097     {
    3098       Method method = methodGeneralArr[i];
    3099       String methodName = method.getName();
    3100       if (methodName.equals(publMethodName))
    3101       {
    3102         /*
    3103          * Check if method is public.
    3104          */
    3105         int methodMod = method.getModifiers();
    3106         if (Modifier.isPublic(methodMod))
    3107         {
    3108           publMethod = method;
    3109         }
    3110       }
    3111     }
    3112     return publMethod;
    3113   }
    3114 
    3115 
    3116   /**
    3117    * Returns a String corresponding to the method modifier: "static",
    3118    * "public", "protected", or "private".
    3119    *
    3120    * @param method
    3121    * @return String for method modifier
    3122    */
    3123   private String methodModifierString(Method method)
    3124   {
    3125     String modStr = new String("");
    3126     int methodMod = method.getModifiers();
    3127     if (Modifier.isStatic(methodMod))
    3128     {
    3129       modStr = new String("static");
    3130     }
    3131     else if (Modifier.isPublic(methodMod))
    3132     {
    3133       modStr = new String("public");
    3134     }
    3135     else if (Modifier.isProtected(methodMod))
    3136     {
    3137       modStr = new String("protected");
    3138     }
    3139     else if (Modifier.isPrivate(methodMod))
    3140     {
    3141       modStr = new String("private");
    3142     }
    3143     return modStr;
    3144   }
    3145 
    3146 
    3147   private Localizer getLocale()
    3148   {
    3149     return locale;
    3150   }
    3151 
    3152 
    3153   public void setLocale(Localizer locale)
    3154   {
    3155     this.locale = locale;
    3156   }
    3157 
    3158 
    3159   public Form getTrashCanForm(Integer dirCount, Integer fileCount,
    3160       Integer jobCount, Integer spectrumSearchCount)
    3161   {
    3162     Form form = new Form("trashCanForm");
    3163     Fieldset fs = new Fieldset();
    3164     fs.setTitle("Trash");
    3165     form.addFieldset(fs);
    3166     // Get total number of items to delete
    3167     Integer count = 0;
    3168     if (dirCount != null)
    3169     {
    3170       count += dirCount;
    3171     }
    3172     if (fileCount != null)
    3173     {
    3174       count += fileCount;
    3175     }
    3176     if (jobCount != null)
    3177     {
    3178       count += jobCount;
    3179     }
    3180     if (spectrumSearchCount != null)
    3181     {
    3182       count += spectrumSearchCount;
    3183     }
    3184     // Add info line(s) on number of items of each class to delete
    3185     if (count == 0)
    3186     {
    3187       TextField<String> itemsCount = new DummyField();
    3188       itemsCount.setLabel("Empty");
    3189       itemsCount.setValue("");
    3190       itemsCount.setDisabled(true);
    3191       fs.add(itemsCount);
    3192     }
    3193     if (dirCount != null && dirCount > 0)
    3194     {
    3195       TextField<Integer> dirItemsCount = new TextField<Integer>(VDIRCOUNT);
    3196       dirItemsCount.setLabel("Directories");
    3197       dirItemsCount.setValue(dirCount);
    3198       dirItemsCount.setDisabled(true);
    3199       fs.add(dirItemsCount);
    3200     }
    3201     if (fileCount != null && fileCount > 0)
    3202     {
    3203       TextField<Integer> fileItemsCount = new TextField<Integer>(VCOUNT);
    3204       fileItemsCount.setLabel("Files");
    3205       fileItemsCount.setValue(fileCount);
    3206       fileItemsCount.setDisabled(true);
    3207       fs.add(fileItemsCount);
    3208     }
    3209     if (jobCount != null && jobCount > 0)
    3210     {
    3211       TextField<Integer> jobItemsCount = new TextField<Integer>(VJOBCOUNT);
    3212       jobItemsCount.setLabel("Jobs");
    3213       jobItemsCount.setValue(jobCount);
    3214       jobItemsCount.setDisabled(true);
    3215       fs.add(jobItemsCount);
    3216     }
    3217     if (spectrumSearchCount != null && spectrumSearchCount > 0)
    3218     {
    3219       TextField<Integer> spectrumSearchItemsCount = new TextField<Integer>(
    3220         VSPECTRUMSEARCHCOUNT);
    3221       spectrumSearchItemsCount.setLabel("SpectrumSearches");
    3222       spectrumSearchItemsCount.setValue(spectrumSearchCount);
    3223       spectrumSearchItemsCount.setDisabled(true);
    3224       fs.add(spectrumSearchItemsCount);
    3225     }
    3226     return form;
    3227   }
    3228 
    3229 
    3230   public TextField<Float> newExtractQuantityField(Extract extract)
    3231   {
    3232     VFloat quantity = new VFloat("extractQuantity", true);
    3233     TextField<Float> field = new TextField<Float>(quantity);
    3234     field.setLabel(extract.getName() + "[" + extract.getExternalId() + "]");
    3235     return field;
    3236   }
    3237 
    3238 
    3239   public VFloat newExtractQuantityParameter(Integer extractId)
    3240   {
    3241     VFloat quantity = new VFloat("extractQuantity" + extractId, true);
    3242     return quantity;
    3243   }
    3244 
    3245 
    3246   public Form getSeparationForm()
    3247   {
    3248     Form form = new Form("separationEvent");
    3249     form.setTitle("SeparationMethods");
    3250     Fieldset fs = new Fieldset();
    3251     modifyForPopup(fs);
    3252     fs.setTitle("SelectMethod");
    3253     form.addFieldset(fs);
    3254     // Selectbox for separation events
    3255     Select<VString> method = new Select<VString>(VCLASSNAME);
    3256     method.setLabel("SeparationMethod");
    3257     //
    3258     Option electrophoresis = new Option(GelElectrophoresis.class.getName());
    3259     electrophoresis.setContent("Gel Electrophoresis");
    3260     electrophoresis.setSelected(true);
    3261     method.addOption(electrophoresis);
    3262     //
    3263     Option ipg = new Option(IPG.class.getName());
    3264     ipg.setContent("Isoelectric focusing");
    3265     method.addOption(ipg);
    3266     //
    3267     Option chrom = new Option(null);
    3268     chrom.setContent("Liquid chromatography");
    3269     method.addOption(chrom);
    3270     fs.add(method);
    3271     //
    3272     TextField<Date> eventDateF = new TextField<Date>(VENTRYDATE);
    3273     eventDateF.setValue(new Date());
    3274     fs.add(eventDateF);
    3275     return form;
    3276   }
    3277 
    3278 
    3279   public Form getFileProtocolTypeForm(ProtocolType protocolType)
    3280   {
    3281     Form form = new Form("ProtocolType");
    3282     form.setTitle("ProtocolType");
    3283     Fieldset fs = new Fieldset();
    3284     fs.setTitle("ProtocolType");
    3285     // Protocol Type Select Box
    3286     Select<VString> typeS = new Select<VString>(VTYPE);
    3287     typeS.setLabel("ProtocolType");
    3288     DbControl dc = sc.newDbControl();
    3289     ItemQuery<ProtocolType> query = ProtocolType.getQuery();
    3290     query.order(Orders.asc(Hql.property("name")));
    3291     ItemResultList<ProtocolType> types = query.list(dc);
    3292     //
    3293     for (ProtocolType type : types)
    3294     {
    3295       Option o = new Option(type.getSystemId());
    3296       o.setContent(type.getName());
    3297       typeS.addOption(o);
    3298       if (protocolType != null)
    3299       {
    3300         if (type.equals(protocolType))
    3301         {
    3302           o.setSelected(true);
    3303         }
    3304       }
    3305     }
    3306     dc.close();
    3307     fs.add(typeS);
    3308     form.addFieldset(fs);
    3309     return form;
    3310   }
    3311 
    3312 
    3313   /**
    3314    * Form for new Protocol item. The difference between calling
    3315    * getNewProtocolForm(protocol) and getForm(Protocol.class, protocol) when
    3316    * protocol != null, is that getForm(Protocol.class, protocol) assumes that
    3317    * the protocol argument is stored in the database, i.e. that
    3318    * protocol.getId() is a valid item id, that can be used as value for a
    3319    * newIdField(), without an exception being thrown. Method
    3320    * getNewProtocolForm() on the other hand only uses the protocol argument as
    3321    * a convenient place holder for default values for the Protocol form
    3322    * fields.
    3323    *
    3324    * @param protocol Protocol object (need not be stored in database) with
    3325    *        default field values.
    3326    * @return Form A form for setting protocol values.
    3327    */
    3328   public Form getNewProtocolForm(Protocol protocol)
    3329   {
    3330     Form form = new Form("NewProtocol");
    3331     form.setTitle("NewProtocol");
    3332     Fieldset fs = new Fieldset();
    3333     fs.setTitle("NewProtocol");
    3334     // Protocol Name
    3335     TextField<String> nameF = new NameField();
    3336     fs.add(nameF);
    3337     if (protocol != null)
    3338     {
    3339       nameF.setValue(protocol.getName());
    3340     }
    3341     // Protocol Description
    3342     TextArea descF = new DescriptionField();
    3343     fs.add(descF);
    3344     if (protocol != null)
    3345     {
    3346       descF.setValue(protocol.getDescription());
    3347     }
    3348     // Protocol Type Select Box
    3349     Select<VString> typeS = new Select<VString>(VTYPE);
    3350     typeS.setLabel("ProtocolType");
    3351     DbControl dc = sc.newDbControl();
    3352     ItemQuery<ProtocolType> query = ProtocolType.getQuery();
    3353     query.order(Orders.asc(Hql.property("name")));
    3354     ItemResultList<ProtocolType> types = query.list(dc);
    3355     //
    3356     for (ProtocolType type : types)
    3357     {
    3358       Option o = new Option(type.getSystemId());
    3359       o.setContent(type.getName());
    3360       typeS.addOption(o);
    3361       if (protocol != null)
    3362       {
    3363         if (type.equals(protocol.getProtocolType()))
    3364         {
    3365           o.setSelected(true);
    3366         }
    3367       }
    3368     }
    3369     dc.close();
    3370     fs.add(typeS);
    3371     // Protocol File
    3372     TextField<String> fileF = new FileNameField();
    3373     fs.add(fileF);
    3374     fileF.setLabel("ProtocolFile");
    3375     fileF.setValue(getLocale().get("NotSpecified"));
    3376     if (protocol != null)
    3377     {
    3378       if (protocol.getFile() != null)
    3379       {
    3380         fileF.setValue(protocol.getFile().getName());
    3381       }
    3382     }
    3383     else
    3384     {
    3385       fileF.setValue(getLocale().get("NewProtocolFileAttachmentNote"));
    3386     }
    3387     fileF.setDisabled(true);
    3388     // Protocol File id
    3389     TextField<Integer> fileIdF = new TextField<Integer>(VPROTOCOLFILEID);
    3390     fs.add(fileIdF);
    3391     fileIdF.setHidden(true);
    3392     fileIdF.setLabel("ProtocolFileId");
    3393     fileIdF.setValue(0);
    3394     if (protocol != null)
    3395     {
    3396       if (protocol.getFile() != null)
    3397       {
    3398         fileIdF.setValue(protocol.getFile().getId());
    3399       }
    3400     }
    3401     // Hidden text field for file selection form title
    3402     TextField<String> titleF = new TitleField();
    3403     fs.add(titleF);
    3404     titleF.setValue("SelectProtocolFile");
    3405     form.addFieldset(fs);
    3406     return form;
    3407   }
    3408 
    3409 
    3410   /**
    3411    * Returnes a form for the given class. If obj is supplied the form is
    3412    * filled out with values from that object. obj.class must match cls. This
    3413    * method should only return forms for item classes. If cls is null or
    3414    * obj.class doesn't match cls it returnes the NullForm. Also if the given
    3415    * cls is not handled it returnes a NullForm.
    3416    */
    3417   public Form getForm(Class<?> cls, Object obj)
    3418   {
    3419     if (cls == null)
    3420       return new NullForm();
    3421     if (obj != null && !cls.equals(obj.getClass()))
    3422       return new NullForm();
    3423     // Create forms with prefilled values from the given object
    3424     if (cls.equals(LabeledExtract.class))
    3425     {
    3426       DbControl dc = sc.newDbControl();
    3427       Select<VInteger> labelF = new LabelField(dc);
    3428       dc.close();
    3429       Form form;
    3430       if (obj == null)
    3431       {
    3432         form = new LabeledExtractForm(labelF);
    3433       }
    3434       else
    3435       {
    3436         form = new LabeledExtractForm(labelF, (LabeledExtract) obj);
    3437       }
    3438       modifyForPopup(form.getFieldsets().get(0));
    3439       return form;
    3440     }
    3441     String clsName = cls.getSimpleName();
    3442     Form form = new Form(clsName);
    3443     form.setTitle(clsName);
    3444     //
    3445     Fieldset fs = new Fieldset();
    3446     org.proteios.gui.Title title = fs.getTitle();
    3447     title.setTitle(clsName);
    3448     modifyForPopup(fs);
    3449     if (BasicItem.class.isAssignableFrom(cls))
    3450     {
    3451       TextField<Integer> itemId = new TextField<Integer>(VID);
    3452       if (obj != null)
    3453       {
    3454         fs.add(itemId);
    3455         BasicItem<?> item = (BasicItem<?>) obj;
    3456         itemId.setValue(item.getId());
    3457         itemId.setDisabled(true);
    3458         itemId.setLabel("ItemId");
    3459       }
    3460     }
    3461     if (Ownable.class.isAssignableFrom(cls))
    3462     {
    3463       if (obj != null)
    3464       {
    3465         TextField<String> ownerF = new TextField<String>(VOWNER);
    3466         fs.add(ownerF);
    3467         ownerF.setDisabled(true);
    3468         ownerF.setLabel("Owner");
    3469         Ownable n = (Ownable) obj;
    3470         ownerF.setValue(n.getOwner().getLogin());
    3471       }
    3472     }
    3473     if (Nameable.class.isAssignableFrom(cls))
    3474     {
    3475       TextField<String> nameF = new NameField();
    3476       fs.add(nameF);
    3477       TextArea descF = new DescriptionField();
    3478       fs.add(descF);
    3479       if (obj != null)
    3480       {
    3481         Nameable n = (Nameable) obj;
    3482         nameF.setValue(n.getName());
    3483         descF.setValue(n.getDescription());
    3484       }
    3485     }
    3486     if (User.class.isAssignableFrom(cls))
    3487     {
    3488       TextField<String> emailF = new EmailField();
    3489       fs.add(fs.size()-1, emailF);
    3490 
    3491    TextField<String> phoneF = new PhoneField();
    3492    fs.add(phoneF);
    3493 
    3494    TextField<String> addressF = new AddressField();
    3495    fs.add(addressF);
    3496 
    3497    TextField<String> organisationF = new OrganisationField();
    3498    fs.add(organisationF);
    3499 
    3500       if (obj != null)
    3501       {
    3502         User n = (User) obj;
    3503         emailF.setValue(n.getEmail());
    3504     phoneF.setValue(n.getPhone());
    3505     addressF.setValue(n.getAddress());
    3506     organisationF.setValue(n.getOrganisation());
    3507       }
    3508     }
    3509     if (Project.class.isAssignableFrom(cls))
    3510     {
    3511       {
    3512         Select<VInteger> field = new Select<VInteger>(VPROJECTTYPE);
    3513         field.setLabel("ProjectType");
    3514         Option option0 = new Option("0");
    3515         Option option1 = new Option("1");
    3516         Option option2 = new Option("2");
    3517         option0.setContent("");
    3518         option1.setContent("GelBased");
    3519         option2.setContent("NonGelBased");
    3520         field.addOption(option0);
    3521         field.addOption(option1);
    3522         field.addOption(option2);
    3523         fs.add(field);
    3524         if (obj != null)
    3525         {
    3526           Project p = (Project) obj;
    3527           switch (p.getProjectType())
    3528           {
    3529             case (1):
    3530               option1.setSelected(true);
    3531               break;
    3532             case (2):
    3533               option2.setSelected(true);
    3534               break;
    3535             default:
    3536               option0.setSelected(true);
    3537           }
    3538         }
    3539       }
    3540       if (obj != null)
    3541       {
    3542         Select<VInteger> field = new Select<VInteger>(VPROJECTSTATUS);
    3543         field.setLabel("Status");
    3544         Option option0 = new Option("0");
    3545         Option option1 = new Option("1");
    3546         option0.setContent("Open");
    3547         option1.setContent("Closed");
    3548         field.addOption(option0);
    3549         field.addOption(option1);
    3550         fs.add(field);
    3551         Project p = (Project) obj;
    3552         if (p.isClosed())
    3553         {
    3554           option1.setSelected(true);
    3555         }
    3556         else
    3557         {
    3558           option0.setSelected(true);
    3559         }
    3560       }
    3561     }
    3562     if (File.class.equals(cls))
    3563     {
    3564       DbControl dc = sc.newDbControl();
    3565       File file = null;
    3566       if (obj != null)
    3567       {
    3568         file = (File) obj;
    3569       }
    3570       // File type selector
    3571       Select<VInteger> fileTypeS = new FileTypeSelect(dc, file);
    3572       fs.add(fileTypeS);
    3573       TextField<String> uriF = new TextField<String>(VURI);
    3574       fs.add(uriF);
    3575       uriF.setLabel("URI");
    3576       uriF.setDisabled(true);
    3577       if (file != null)
    3578       {
    3579         uriF.setValue(file.getUniformResourceIdentifier());
    3580       }
    3581       // Forward field
    3582       /*
    3583        * This hidden forward field sets action id used by the directory
    3584        * selection action called by MoveFile1.
    3585        */
    3586       TextField<String> forwardF = new ForwardField();
    3587       forwardF.setValue(MoveFile2.class.getName());
    3588       fs.add(forwardF);
    3589     }
    3590     if (News.class.isAssignableFrom(cls))
    3591     {
    3592       TextField<Date> newsDate = new TextField<Date>(VNEWSDATE);
    3593       newsDate.setLabel("NewsDate");
    3594       fs.add(newsDate);
    3595       TextField<Date> startDate = new TextField<Date>(VSTARTDATE);
    3596       startDate.setLabel("StartDate");
    3597       fs.add(startDate);
    3598       TextField<Date> endDate = new TextField<Date>(VENDDATE);
    3599       endDate.setLabel("EndDate");
    3600       fs.add(endDate);
    3601       if (obj != null)
    3602       {
    3603         News n = (News) obj;
    3604         newsDate.setValue(n.getNewsDate());
    3605         startDate.setValue(n.getStartDate());
    3606         endDate.setValue(n.getEndDate());
    3607       }
    3608     }
    3609     if (BioMaterialEvent.class.isAssignableFrom(cls))
    3610     {
    3611       // Select box for biomaterial event protocol
    3612       Select<VInteger> protocolS = getProtocolSelectBox(cls, obj);
    3613       fs.add(protocolS);
    3614       //
    3615       TextField<Date> eventDateF = new TextField<Date>(VEVENTDATE);
    3616       eventDateF.setValue(new Date()); // Default
    3617       if (UpdateEvent.class.isAssignableFrom(cls))
    3618       {
    3619         eventDateF.setDisabled(true);
    3620       }
    3621       fs.add(eventDateF);
    3622       //
    3623       TextArea commentF = new TextArea(VCOMMENT);
    3624       commentF.setLabel("Comment");
    3625       fs.add(commentF);
    3626       //
    3627       if (obj != null)
    3628       {
    3629         BioMaterialEvent<?> o = (BioMaterialEvent<?>) obj;
    3630         eventDateF.setValue(o.getEventDate());
    3631         commentF.setValue(o.getComment());
    3632       }
    3633     }
    3634     if (SeparationEvent.class.isAssignableFrom(cls))
    3635     {
    3636       //
    3637       //
    3638       TextField<Float> usedQuantityF = new TextField<Float>(VUSEDQUANTITYINMICROLITERS);
    3639       fs.add(usedQuantityF);
    3640       if (obj != null)
    3641       {
    3642         SeparationEvent o = (SeparationEvent) obj;
    3643         usedQuantityF.setValue(o.getUsedQuantityInMicroLiters());
    3644         // We should not be able to change the used quantity. Enabling
    3645         // this would requre us to recalculate remaining quantities.
    3646         usedQuantityF.setDisabled(true);
    3647       }
    3648     }
    3649     if (StainingEvent.class.equals(cls))
    3650     {
    3651       TextField<String> stainF = new TextField<String>(VSTAIN);
    3652       fs.add(stainF);
    3653       if (obj != null)
    3654       {
    3655         StainingEvent o = (StainingEvent) obj;
    3656         stainF.setValue(o.getStain());
    3657       }
    3658     }
    3659     //
    3660     if (GelScanEvent.class.equals(cls))
    3661     {
    3662       TextField<String> fileF = new FileNameField();
    3663       fs.add(fileF);
    3664       fileF.setValue("not specified");
    3665       if (obj != null)
    3666       {
    3667         GelScanEvent o = (GelScanEvent) obj;
    3668         if (o.getImageFile() != null)
    3669         {
    3670           fileF.setValue(o.getImageFile().getName());
    3671         }
    3672       }
    3673       fileF.setDisabled(true);
    3674     }
    3675     //
    3676     if (SeparationMethod.class.isAssignableFrom(cls))
    3677     {
    3678       TextField<String> externalId = new ExternalIdField();
    3679       fs.add(externalId);
    3680       if (obj != null)
    3681       {
    3682         SeparationMethod<?> o = (SeparationMethod<?>) obj;
    3683         externalId.setValue(o.getExternalId());
    3684       }
    3685     }
    3686     //
    3687     if (GelElectrophoresis.class.equals(cls))
    3688     {
    3689       //
    3690       TextField<Integer> massStartF = new TextField<Integer>(VMASSSTART);
    3691       fs.add(massStartF);
    3692       //
    3693       TextField<Integer> massEndF = new TextField<Integer>(VMASSEND);
    3694       fs.add(massEndF);
    3695       //
    3696       TextField<Integer> sizeXF = new TextField<Integer>(VSIZEX);
    3697       fs.add(sizeXF);
    3698       //
    3699       TextField<Integer> sizeYF = new TextField<Integer>(VSIZEY);
    3700       fs.add(sizeYF);
    3701       //
    3702       TextField<Integer> percentAacrylAmidF = new TextField<Integer>(VPERCENTACRYLAMID);
    3703       fs.add(percentAacrylAmidF);
    3704       //
    3705       TextField<String> denaturatingAgent = new TextField<String>(VDENATURATINGAGENT);
    3706       fs.add(denaturatingAgent);
    3707       //
    3708       TextField<String> proteinAssayF = new TextField<String>(VPROTEINASSAY);
    3709       fs.add(proteinAssayF);
    3710       //
    3711       TextField<String> solubilizationBuffer = new TextField<String>(VSOLUBILIZATIONBUFFER);
    3712       fs.add(solubilizationBuffer);
    3713       if (obj != null)
    3714       {
    3715         // Set values from given object
    3716         GelElectrophoresis o = (GelElectrophoresis) obj;
    3717         massStartF.setValue(o.getMassStartInKiloDaltons());
    3718         massEndF.setValue(o.getMassEndInKiloDaltons());
    3719         sizeXF.setValue(o.getSizeXInCentiMeters());
    3720         sizeYF.setValue(o.getSizeYInCentiMeters());
    3721         percentAacrylAmidF.setValue(o.getPercentAcrylamide());
    3722         denaturatingAgent.setValue(o.getDenaturatingAgent());
    3723         proteinAssayF.setValue(o.getProteinAssay());
    3724         solubilizationBuffer.setValue(o.getSolubilizationBuffer());
    3725       }
    3726     }
    3727     //
    3728     if (ProtocolType.class.equals(cls))
    3729     {
    3730       Select<VString> typeS = new Select<VString>(VTYPE);
    3731       typeS.setLabel("ProtocolType");
    3732       DbControl dc = sc.newDbControl();
    3733       ItemQuery<ProtocolType> query = ProtocolType.getQuery();
    3734       query.order(Orders.asc(Hql.property("name")));
    3735       ItemResultList<ProtocolType> types = query.list(dc);
    3736       //
    3737       for (ProtocolType type : types)
    3738       {
    3739         Option o = new Option(type.getSystemId());
    3740         o.setContent(type.getName());
    3741         typeS.addOption(o);
    3742       }
    3743       dc.close();
    3744       typeS.getOptions().get(0).setSelected(true);
    3745       fs.add(typeS);
    3746     }
    3747     //
    3748     if (Protocol.class.equals(cls))
    3749     {
    3750       // Protocol Type Select Box
    3751       Select<VString> typeS = new Select<VString>(VTYPE);
    3752       typeS.setLabel("ProtocolType");
    3753       DbControl dc = sc.newDbControl();
    3754       ItemQuery<ProtocolType> query = ProtocolType.getQuery();
    3755       query.order(Orders.asc(Hql.property("name")));
    3756       ItemResultList<ProtocolType> types = query.list(dc);
    3757       //
    3758       for (ProtocolType type : types)
    3759       {
    3760         Option o = new Option(type.getSystemId());
    3761         o.setContent(type.getName());
    3762         typeS.addOption(o);
    3763         if (obj != null)
    3764         {
    3765           Protocol protocol = (Protocol) obj;
    3766           if (type.equals(protocol.getProtocolType()))
    3767           {
    3768             o.setSelected(true);
    3769           }
    3770         }
    3771       }
    3772       dc.close();
    3773       fs.add(typeS);
    3774       // Protocol File
    3775       TextField<String> fileF = new FileNameField();
    3776       fs.add(fileF);
    3777       fileF.setLabel("ProtocolFile");
    3778       fileF.setValue(getLocale().get("NotSpecified"));
    3779       if (obj != null)
    3780       {
    3781         Protocol protocol = (Protocol) obj;
    3782         if (protocol.getFile() != null)
    3783         {
    3784           fileF.setValue(protocol.getFile().getName());
    3785         }
    3786       }
    3787       else
    3788       {
    3789         fileF
    3790           .setValue(getLocale().get("NewProtocolFileAttachmentNote"));
    3791       }
    3792       fileF.setDisabled(true);
    3793       // Protocol File id
    3794       TextField<Integer> fileIdF = new TextField<Integer>(VPROTOCOLFILEID);
    3795       fs.add(fileIdF);
    3796       fileIdF.setHidden(true);
    3797       fileIdF.setLabel("ProtocolFileId");
    3798       fileIdF.setValue(0);
    3799       if (obj != null)
    3800       {
    3801         Protocol protocol = (Protocol) obj;
    3802         if (protocol.getFile() != null)
    3803         {
    3804           fileIdF.setValue(protocol.getFile().getId());
    3805         }
    3806       }
    3807       // Optional 'Removed' flag
    3808       if (obj != null)
    3809       {
    3810         TextField<String> removedF = new DummyField();
    3811         fs.add(removedF);
    3812         removedF.setDisabled(true);
    3813         removedF.setLabel("Removed");
    3814         removedF.setValue("no");
    3815         Protocol protocol = (Protocol) obj;
    3816         if (protocol.isRemoved())
    3817         {
    3818           removedF.setValue("yes");
    3819         }
    3820       }
    3821       // Hidden text field for file selection form title
    3822       TextField<String> titleF = new TitleField();
    3823       fs.add(titleF);
    3824       titleF.setValue("SelectProtocolFile");
    3825     }
    3826     form.addFieldset(fs);
    3827     return form;
    3828   }
    3829 
    3830 
    3831   /**
    3832    * Creates a select box for protocols. If the class for which the protocol
    3833    * is intended is supported by the method, only protocols with correct
    3834    * protocol type are included. If an input object with attached protocol
    3835    * exists, the latter protocol should appear in the list and be selected, if
    3836    * if the protocol is tagged to be removed. However, no other protocols
    3837    * tagged to be removed should be included in the list.
    3838    *
    3839    * @param cls Class Class for which a protocol should be selected.
    3840    * @param obj Object Optional object with attached protocol for setting
    3841    *        default protocol.
    3842    * @return Select<VInteger> Select box for protocol selection
    3843    */
    3844   private Select<VInteger> getProtocolSelectBox(Class cls, Object obj)
    3845   {
    3846     Select<VInteger> protocolS = new Select<VInteger>(VPROTOCOLID);
    3847     protocolS.setLabel("Protocol");
    3848     //
    3849     Option noProtocol = new Option("");
    3850     noProtocol.setContent("None");
    3851     noProtocol.setValue("0");
    3852     protocolS.addOption(noProtocol);
    3853     // Get relevant protocol types, if any
    3854     List<String> pTypeList = new ArrayList<String>(0);
    3855     if (SeparationEvent.class.isAssignableFrom(cls))
    3856     {
    3857       pTypeList.add(ProtocolType.SEPARATION);
    3858     }
    3859     if (StainingEvent.class.equals(cls))
    3860     {
    3861       pTypeList.add(ProtocolType.STAINING);
    3862     }
    3863     if (GelScanEvent.class.equals(cls))
    3864     {
    3865       pTypeList.add(ProtocolType.SCANNING);
    3866     }
    3867     if (CreationEvent.class.equals(cls))
    3868     {
    3869       if (obj != null)
    3870       {
    3871         CreationEvent ce = (CreationEvent) obj;
    3872         Iterator<MeasuredBioMaterial> bioit = ce
    3873           .getCreatedMeasuredBioMaterials().iterator();
    3874         if (bioit.hasNext())
    3875         {
    3876           MeasuredBioMaterial mbm = bioit.next();
    3877           if (mbm instanceof Extract)
    3878           {
    3879             pTypeList.add(ProtocolType.EXTRACTION);
    3880           }
    3881           if (mbm instanceof LabeledExtract)
    3882           {
    3883             pTypeList.add(ProtocolType.LABELING);
    3884           }
    3885           if (mbm instanceof Sample)
    3886           {
    3887             pTypeList.add(ProtocolType.SAMPLING);
    3888           }
    3889           if (mbm.isPooled())
    3890           {
    3891             pTypeList.add(ProtocolType.POOLING);
    3892           }
    3893         }
    3894       }
    3895     }
    3896     // Get optional input protocol
    3897     Protocol inProtocol = null;
    3898     if (BioMaterialEvent.class.isAssignableFrom(cls) && obj != null)
    3899     {
    3900       BioMaterialEvent<?> bme = (BioMaterialEvent<?>) obj;
    3901       inProtocol = bme.getProtocol();
    3902     }
    3903     // Get protocols
    3904     ItemQuery<Protocol> query = Protocol.getQuery();
    3905     // Include removed items in query if input protocol is removed
    3906     if (inProtocol != null && inProtocol.isRemoved())
    3907     {
    3908       query.include(Include.REMOVED);
    3909     }
    3910     DbControl dc = sc.newDbControl();
    3911     ItemResultList<Protocol> listOfProtocols = query.list(dc);
    3912     if (listOfProtocols.size() > 0)
    3913     {
    3914       for (Protocol p : listOfProtocols)
    3915       {
    3916         // Only include protocols with relevant protocol type
    3917         for (String pType : pTypeList)
    3918         {
    3919           if (pType == null || pType.equals(p.getProtocolType()
    3920             .getSystemId()))
    3921           {
    3922             // Only include removed protocol if it is selected
    3923             if (!p.isRemoved() || p.equals(inProtocol))
    3924             {
    3925               Option o = new Option("" + p.getId());
    3926               o.setContent(p.getName() + " - " + p
    3927                 .getProtocolType().getName());
    3928               protocolS.addOption(o);
    3929               if (p.equals(inProtocol))
    3930               {
    3931                 o.setSelected(true);
    3932               }
    3933             }
    3934           }
    3935         }
    3936       }
    3937     }
    3938     if (obj == null)
    3939     {
    3940       protocolS.getOptions().get(0).setSelected(true);
    3941     }
    3942     dc.close();
    3943     return protocolS;
    3944   }
    3945 
    3946 
    3947 
    3948   public void setSc(SessionControl sc)
    3949   {
    3950     // Only alow setting of SessionControl once, and this is done by the
    3951     // ActionFactory
    3952     if (this.sc == null)
    3953       this.sc = sc;
    3954   }
    3955 
    3956 
    3957   /**
    3958    * Converts a list String to a list with String elements. If the list string
    3959    * contains two delimiter strings directly after each other, an empty string
    3960    * element will be added to the list in the corresponding place. Example:
    3961    * List string "one, two, three" will be converted to a list with the three
    3962    * String elements "one", "two", and "three" using delimiter regular
    3963    * expression ",\\ ".
    3964    *
    3965    * @param listString String A string with a list
    3966    * @param delimiterRegex String A regular expression for the delimiter
    3967    *        between list elements
    3968    * @return List<String> A list of String elements
    3969    */
    3970   private List<String> listStringToStringList(String listString,
    3971       String delimiterRegex)
    3972   {
    3973     List<String> stringList = null;
    3974     if (listString != null)
    3975     {
    3976       stringList = new ArrayList<String>(0);
    3977       for (String part : listString.split(delimiterRegex, -1))
    3978       {
    3979         // Add list part if not already in list
    3980         if (part != null && !stringList.contains(part))
    3981         {
    3982           stringList.add(part);
    3983         }
    3984       }
    3985     }
    3986     return stringList;
    3987   }
     67    private ActionFactory actionFactory = null;
     68    private HttpServletRequest request = null;
     69    private SessionControl sc = null;
     70    /**
     71        * List<String> of excluded getter methods declared in current class. If a
     72        * getter accessor method is included in this list, when a generic form for
     73        * an object is created with getForm(), no field will be added to the form
     74        * for an instance variable (if any) corresponding to the getter method.
     75    */
     76    private List<String> excludedDeclMethods = new ArrayList<String>();
     77    private Localizer locale = null;
     78    private String forwardActionId = null;
     79    private String sortColumnKey = null;
     80    private Integer filterListSize = null;
     81    private List<String> filterKeyColumnList = null;
     82    private HashMap<String, String> filterClassColumnHashMap = null;
     83    private HashMap<String, String> filterConditionColumnHashMap = null;
     84    private HashMap<String, String> filterValueColumnHashMap = null;
     85    // Valid parameters
     86    public static final VInteger VID = new DBID();
     87    public static final VInteger VPROTOCOLID = new ProtocolID();
     88    public static final VInteger VPROJECTTYPE = new ProjectTypeID();
     89    public static final VInteger VPROJECTSTATUS = new ProjectStatus();
     90    public static final VInteger VPROTOCOLFILEID = new VInteger("protocolfileId", 0, true);
     91    public static final VBoolean VPROTOCOLFILERESET = new VBoolean("protocolFileReset", false);
     92    public static final VInteger VANNOTYPEID = new VInteger("annotationTypeId",0, true);
     93    public static final VInteger VGROUPID = new VInteger("groupId", 1, false);
     94    public static final VString VANNONAME = new VString("annotationName", 1,64, false);
     95    public static final VString VPWD1 = new VString("pwd1", 1, 32, true);
     96    public static final VString VPWD2 = new VString("pwd2", 1, 32, true);
     97    public static final VString VANNOVALUE = new VString("value", 0, 255);
     98    public static final VString VTYPE = new VString("type", 1, 64, true);
     99    public static final VString VFILE = new VString("file", 1, 512); // Allow
     100    public static final VString VNONREQUIRED_FILENAME = new VString("fileName",0, 255, false);
     101    public static final VString VREQUIRED_FILENAME = new VString("fileName", 1,255, true);
     102    public static final VString VFWD2ACTION = new VString("forward2ActionId",1, 255, false);
     103    public static final VString VCLASSNAME = new VString("className", 1, 255,true);
     104    public static final VString VURI = new VString("fileURI", 0, 255, false);
     105    public static final VString VROLEPERMISSIONID = new VString("rolePermId",1, 64, true);
     106    public static final VString VWELLPOSITION = new VString("wellPosition", 0,8, false);
     107    public static final VInteger VDIRID = new VInteger("dirId", 1, true);
     108    public static final VInteger VSPOTID = new VInteger("spotId", 0, false);
     109    public static final VInteger VFILETYPEID = new VInteger("fileTypeId", 0,true);
     110    public static final VString VPERCENT = new VString("percent", 0, 4, false);
     111    public static final VInteger VMASSSTART = new VInteger("massStartInKiloDaltons", 0, false);
     112    public static final VInteger VMASSEND = new VInteger("massEndInKiloDaltons", 0, false);
     113    public static final VInteger VSIZEX = new VInteger("sizeXInCentiMeters", 0,false);
     114    public static final VInteger VSIZEY = new VInteger("sizeYInCentiMeters", 0,false);
     115    public static final VInteger VPERCENTACRYLAMID = new VInteger("percentAcrylAmid", 0, 100, false);
     116    public static final VString VDENATURATINGAGENT = new VString("denaturatingAgent", 0, 255, false);
     117    public static final VString VPROTEINASSAY = new VString("proteinAssay", 0,255, false);
     118    public static final VString VSOLUBILIZATIONBUFFER = new VString("solubilizationBuffer", 0, 255, false);
     119    public static final VFloat VORIGINALQUANTITY = new VFloat("originalQuantity", true);
     120    public static final VFloat VREMAININGQUANTITY = new VFloat("remainingQuantity", false);
     121    public static final VFloat VQUANTITY = new VFloat("quantity", true);
     122    public static final VFloat VUSEDQUANTITYINMICROLITERS = new VFloat("UsedQuantityInMicroLiters", true);
     123    public static final VBoolean VPEPTIDECOMPARE = new VBoolean("isPeptideCompare", false);
     124    public static final VBoolean VISMICROTITREPLATE = new VBoolean("isMicrotitrePlate", false);
     125    public static final VString VRANDOMSTRING = new VString("randomString", 1,15, true);
     126    public static final VInteger VCOUNT = new VInteger("count", 0, true);
     127    public static final VInteger VDIRCOUNT = new VInteger("dirCount", 0, true);
     128    public static final VInteger VJOBCOUNT = new VInteger("jobCount", 0, true);
     129    public static final VInteger VSPECTRUMSEARCHCOUNT = new VInteger("spectrumSearchCount", 0, true);
     130    public static final VBoolean VREADONLYFORM = new VBoolean("readOnlyForm",false);
     131    public static final VBoolean VCONFIRM = new VBoolean("confirm", false);
     132    public static final VString VCONFIRMMESSAGE = new VString("confirmMessage",0, 255, false);
     133    public static final VString VCANCELACTION = new VString("cancelActionId",1, 255, false);
     134    public static final VString VFILTERNAME = new VString("filterName", 0, 255,false);
     135    public static final VString VFILTERCLASS = new VString("filterClass", 0,255, false);
     136    public static final VString VFILTERCONDITION = new VString("filterCondition", 0, 255, false);
     137    public static final VString VFILTERVALUE = new VString("filterValue", 0,255, false);
     138    public static final VInteger VLISTSIZE = new VInteger("listSize", 0, false);
     139    public static final VString VFILTERKEYLIST = new VString("filterKeyList",0, 255, false);
     140    public static final VString VFILTERCLASSLIST = new VString("filterClassList", 0, 255, false);
     141    public static final VString VFILTERCONDITIONLIST = new VString("filterConditionList", 0, 255, false);
     142    public static final VString VFILTERVALUELIST = new VString("filterValueList", 0, 255, false);
     143    public static final VString VSORTCOLUMNKEY = new VString("sortColumnKey",0, 255, false);
     144    public static final VString VCOMMENT = new VString("comment", 0, 255, false);
     145    public static final VDate VENTRYDATE = new VDate("entryDate", false,Format.DATETIME);
     146    public static final VDate VEVENTDATE = new VDate("eventDate", false,Format.DATETIME, Format.DATE);
     147    public static final VDate VNEWSDATE = new VDate("newsDate", true,Format.DATETIME, Format.DATE);
     148    public static final VDate VSTARTDATE = new VDate("startDate", true,Format.DATETIME, Format.DATE);
     149    public static final VDate VENDDATE = new VDate("endDate", true,Format.DATETIME, Format.DATE);
     150   
     151    public static final VInteger VBIOMATERIALID = new VInteger("bioMaterialId",1, false);
     152    // TODO what are valid values for the pistart parameter
     153   
     154    public static final VString VSTAIN = new VString("stain", 0, 255, false);
     155    public static final VInteger VLABELID = new VInteger("labelId", 0, true);
     156    // public static final VInteger VCOLUMNROWID = new VInteger("columnRowId",// 0, true);
     157    public static final VInteger VCOLUMNROWID = new VInteger("columnRowId", 0,false);
     158    public static final VInteger VCOLUMNLISTSIZE = new VInteger("columnListSize", 0, false);
     159    public static final VInteger VCOLUMNSELECTID = new VInteger("columnSelectId", 0, false);
     160    public static final VInteger VCOLUMNSELECTLISTSIZE = new VInteger("columnSelectListSize", 0, false);
     161    public static final VString VTABLECONFACTION = new VString("tableConfigurationActionId", 0, 255, false);
     162    private static final VString VOWNER = new VString("owner", 1, 32, false);
     163    public static final VString VNONREQUIRED_NAME = new VString("name", 0, 255,false);
     164    public static final VString VNONREQUIRED_INSTITUTION = new VString("institution", 0, 255, false);
     165    public static final VString VNONREQUIRED_ADDRESS = new VString("address",0, 255, false);
     166    public static final VString VNONREQUIRED_URL = new VString("url", 0, 255,false);
     167    public static final VString VNONREQUIRED_EMAIL = new VString("email", 0,255, false);
     168    public static final VString VNONREQUIRED_CONTACT_INFO = new VString("contactInfo", 0, 255, false);
     169    public static final VString VNONREQUIRED_SAMPLE_NAME = new VString("sampleName", 0, 255, false);
     170    public static final VString VNONREQUIRED_SAMPLE_NUMBER = new VString("sampleNumber", 0, 255, false);
     171    public static final VString VNONREQUIRED_SAMPLE_STATE = new VString("sampelState", 0, 255, false);
     172    public static final VString VNONREQUIRED_SAMPLE_MASS_IN_GRAMS = new VString("sampleMassInGrams", 0, 255, false);
     173    public static final VString VNONREQUIRED_SAMPLE_VOLUME_IN_MILLILITERS = new VString("sampleVolumeInMilliliters", 0, 255, false);
     174    public static final VString VNONREQUIRED_SAMPLE_CONCENTRATION_IN_GRAMS_PER_LITER = new VString("sampleConcentrationInGramsPerLiter", 0, 255, false);
     175    public static final VString VNONREQUIRED_SAMPLE_BATCH = new VString("sampleBatch", 0, 255, false);
     176    public static final VString VNONREQUIRED_SAMPLE_COMMENT = new VString("sampleComment", 0, 255, false);
     177    /**
     178        * logger to use
     179    */
     180    private static final org.apache.log4j.Logger log = org.apache.log4j.LogManager
     181    .getLogger("org.proteios.gui.form");
     182   
     183    /**
     184        * Default constructor. Initializes list excludedDeclMethods.
     185    */
     186    public FormFactory()
     187    {
     188        /*
     189            * Initialize list excludedDeclMethods.
     190        */
     191        initExcludedDeclMethods();
     192    }
     193   
     194    /**
     195        * Get list of excluded getter methods declared in current class.
     196        *
     197        * @return List<String> of excluded getter methods.
     198    */
     199    public List<String> getExcludedDeclMethods()
     200    {
     201        return this.excludedDeclMethods;
     202    }
     203   
     204    /**
     205        * Set list of excluded getter methods declared in current class.
     206        *
     207        * @param excludedDeclMethods List<String> of excluded getter methods to
     208        *        set.
     209    */
     210    public void setExcludedDeclMethods(List<String> excludedDeclMethods)
     211    {
     212        this.excludedDeclMethods = excludedDeclMethods;
     213    }
     214   
     215    /**
     216        * Add list of excluded getter methods declared in current class.
     217        *
     218        * @param excludedDeclMethods List<String> of excluded getter methods to to
     219        *        add.
     220    */
     221    public void addExcludedDeclMethods(List<String> excludedDeclMethods)
     222    {
     223        for (String exclMethod : excludedDeclMethods)
     224        {
     225            /*
     226                * Add excluded method if not already in list.
     227            */
     228            if (!getExcludedDeclMethods().contains(exclMethod))
     229            {
     230                getExcludedDeclMethods().add(exclMethod);
     231            }
     232        }
     233    }
     234   
     235    public void setActionFactory(ActionFactory af)
     236    {
     237        this.actionFactory = af;
     238    }
     239   
     240    public String getForwardActionId()
     241    {
     242        return this.forwardActionId;
     243    }
     244   
     245    public void setForwardActionId(String forwardActionId)
     246    {
     247        this.forwardActionId = forwardActionId;
     248    }
     249   
     250    public String getSortColumnKey()
     251    {
     252        return this.sortColumnKey;
     253    }
     254   
     255    public void setSortColumnKey(String sortColumnKey)
     256    {
     257        this.sortColumnKey = sortColumnKey;
     258    }
     259   
     260    public Integer getFilterListSize()
     261    {
     262        return this.filterListSize;
     263    }
     264   
     265    public void setFilterListSize(Integer filterListSize)
     266    {
     267        this.filterListSize = filterListSize;
     268    }
     269   
     270    public List<String> getFilterKeyColumnList()
     271    {
     272        return this.filterKeyColumnList;
     273    }
     274   
     275    public void setFilterKeyColumnList(List<String> filterKeyColumnList)
     276    {
     277        this.filterKeyColumnList = filterKeyColumnList;
     278    }
     279   
     280    public HashMap<String, String> getFilterClassColumnHashMap()
     281    {
     282        return this.filterClassColumnHashMap;
     283    }
     284   
     285    public void setFilterClassColumnHashMap(
     286    HashMap<String, String> filterClassColumnHashMap)
     287    {
     288        this.filterClassColumnHashMap = filterClassColumnHashMap;
     289    }
     290   
     291    public HashMap<String, String> getFilterConditionColumnHashMap()
     292    {
     293        return this.filterConditionColumnHashMap;
     294    }
     295   
     296    public void setFilterConditionColumnHashMap(
     297    HashMap<String, String> filterConditionColumnHashMap)
     298    {
     299        this.filterConditionColumnHashMap = filterConditionColumnHashMap;
     300    }
     301   
     302    public HashMap<String, String> getFilterValueColumnHashMap()
     303    {
     304        return this.filterValueColumnHashMap;
     305    }
     306   
     307    public void setFilterValueColumnHashMap(
     308    HashMap<String, String> filterValueColumnHashMap)
     309    {
     310        this.filterValueColumnHashMap = filterValueColumnHashMap;
     311    }
     312   
     313    /**
     314        * Initializes list of excluded getter methods declared in current class.
     315    */
     316    public void initExcludedDeclMethods()
     317    {
     318        /*
     319            * Initialize list of excluded declared methods.
     320        */
     321        getExcludedDeclMethods().add("getType");
     322        getExcludedDeclMethods().add("getQuery");
     323        getExcludedDeclMethods().add("getNew");
     324        getExcludedDeclMethods().add("getById");
     325        getExcludedDeclMethods().add("isUsed");
     326        getExcludedDeclMethods().add("isRemoved");
     327        getExcludedDeclMethods().add("getAnnotatableParents");
     328    }
     329   
     330    public HttpServletRequest getRequest()
     331    {
     332        return request;
     333    }
     334   
     335    public void setRequest(HttpServletRequest request)
     336    {
     337        this.request = request;
     338    }
     339   
     340    public void modifyForPopup(Fieldset fs)
     341    {
     342        actionFactory.modifyForPopup(fs);
     343    }
     344   
     345    private FileField newFileField()
     346    {
     347        FileField fileF = new FileField(VFILE);
     348        fileF.setLabel("File");
     349        return fileF;
     350    }
     351   
     352    public TextField<Integer> newIdField()
     353    {
     354        TextField<Integer> idF = new TextField<Integer>(VID);
     355        idF.setHidden(true);
     356        idF.setLabel("Id");
     357        return idF;
     358    }
     359   
     360    private TextField<String> newValueField(String setValueMethodName,
     361    Class<?> valueClass)
     362    {
     363        String setValueMethodSignature = null;
     364        if (setValueMethodName != null && !setValueMethodName.equals(""))
     365        {
     366            /*
     367                * Set valid parameter name to signature of single-argument setter
     368                * method, if existing, in order to separate between arguments of
     369                * primitive types like boolean, int, float, and double, from those
     370                * of wrapper class types like Boolean, Integer, Float, and Double.
     371            */
     372            setValueMethodSignature = setValueMethodName + ":" + valueClass
     373            .getSimpleName();
     374            if (valueClass == String.class)
     375            {
     376                VString vSetterMethodParam = new VString(
     377                setValueMethodSignature, 0, 255, false);
     378                TextField<String> valueF = new TextField<String>(
     379                vSetterMethodParam);
     380                valueF.setLabel("");
     381                valueF.setDisabled(false);
     382                return valueF;
     383            }
     384        }
     385        VString vSetterMethodParam = new VString("null", 0, 255, false);
     386        TextField<String> valueF = new TextField<String>(vSetterMethodParam);
     387        valueF.setLabel("");
     388        valueF.setDisabled(true);
     389        return valueF;
     390    }
     391   
     392    private TextArea newValueTextArea(String setValueMethodName,
     393    Class<?> valueClass)
     394    {
     395        log
     396        .debug("FormFactory::newValueTextArea(): setValueMethodName = \"" + setValueMethodName + "\" valueClass.getSimpleName() = \"" + valueClass
     397        .getSimpleName() + "\"");
     398        String setValueMethodSignature = null;
     399        if (setValueMethodName != null && !setValueMethodName.equals(""))
     400        {
     401            /*
     402                * Set valid parameter name to signature of single-argument setter
     403                * method, if existing, in order to separate between arguments of
     404                * primitive types like boolean, int, float, and double, from those
     405                * of wrapper class types like Boolean, Integer, Float, and Double.
     406            */
     407            setValueMethodSignature = setValueMethodName + ":" + valueClass
     408            .getSimpleName();
     409            if (valueClass == String.class)
     410            {
     411                VString vSetterMethodParam = new VString(
     412                setValueMethodSignature, 0, 65535, false);
     413                TextArea valueF = new TextArea(vSetterMethodParam);
     414                valueF.setLabel("");
     415                valueF.setDisabled(false);
     416                return valueF;
     417            }
     418            VString vSetterMethodParam = new VString("null", 0, 65535, false);
     419            TextArea valueF = new TextArea(vSetterMethodParam);
     420            valueF.setLabel("");
     421            valueF.setDisabled(false);
     422            return valueF;
     423        }
     424        VString vSetterMethodParam = new VString("null", 0, 65535, false);
     425        TextArea valueF = new TextArea(vSetterMethodParam);
     426        valueF.setLabel("");
     427        valueF.setDisabled(true);
     428        return valueF;
     429    }
     430   
     431    public Form getMyProfilePropertiesForm(User user)
     432    {
     433        return getForm(User.class, user);
     434    }
     435   
     436    public TextField<Integer> newHiddenItemIdField()
     437    {
     438        TextField<Integer> field = new TextField<Integer>(VID).setHidden(true);
     439        return field;
     440    }
     441   
     442    private TextField<Boolean> newHiddenReadOnlyFormField()
     443    {
     444        TextField<Boolean> field = new TextField<Boolean>(VREADONLYFORM)
     445        .setHidden(true);
     446        return field;
     447    }
     448   
     449    private TextField<Integer> newHiddenIntegerField(VInteger vInteger)
     450    {
     451        TextField<Integer> field = new TextField<Integer>(vInteger)
     452        .setHidden(true);
     453        return field;
     454    }
     455   
     456    private TextField<String> newHiddenStringField(VString vString)
     457    {
     458        TextField<String> field = new TextField<String>(vString)
     459        .setHidden(true);
     460        return field;
     461    }
     462   
     463    @SuppressWarnings("unchecked")
     464    public void populateForm(Form form, HttpServletRequest request2)
     465    {
     466        if (request2 != null)
     467        {
     468            for (Fieldset fs : form.getFieldsets())
     469            {
     470                for (Iterator iter = fs.getFields().iterator(); iter.hasNext();)
     471                {
     472                    Field f = (Field) iter.next();
     473                    VParameter param = f.getParam();
     474                    String value = null;
     475                    if (param != null)
     476                    {
     477                        value = request.getParameter(param.getName());
     478                        if (value == null)
     479                        {
     480                            // Try the attributes
     481                            value = (String) request.getAttribute(param
     482                            .getName());
     483                        }
     484                    }
     485                    if (f instanceof TextField)
     486                    {
     487                        TextField<String> textField = (TextField<String>) f;
     488                        // FIXME implement methods to check if field contains
     489                        // String, Float or other
     490                        textField.setValue(value);
     491                        continue;
     492                    }
     493                    if (f instanceof TextArea)
     494                    {
     495                        TextArea textArea = (TextArea) f;
     496                        textArea.setValue(value);
     497                        continue;
     498                    }
     499                    if (f instanceof Checkbox)
     500                    {
     501                        if (value != null && value.equals(((Checkbox) f)
     502                        .getValue()))
     503                        ((Checkbox) f).isChecked(true);
     504                    }
     505                    if (f instanceof Select)
     506                    {
     507                        Select tmp = (Select) f;
     508                        List<Option> options = tmp.getOptions();
     509                        for (Option o : options)
     510                        {
     511                            if (value != null && value.equals(o.getValue()))
     512                            {
     513                                o.setSelected(true);
     514                                break;
     515                            }
     516                            o.setSelected(false);
     517                        }
     518                        continue;
     519                    }
     520                }
     521            }
     522        }
     523    }
     524   
     525    public <D extends BasicItem<?>, E extends ProteiosAction<?>> Form getAnnotationsForm(
     526    DbControl dc, D item, Class<E> forwardAction)
     527    {
     528        Form form = new Form("annotationForm");
     529        form.setTitle("Annotations");
     530        Fieldset fs = new Fieldset();
     531        form.addFieldset(fs);
     532        fs.setTitle("Annotation");
     533        // id field
     534        TextField<Integer> idF = newIdField();
     535        fs.add(idF);
     536        // type field
     537        TextField<String> typeF = newTypeField();
     538        fs.add(typeF);
     539        // Forward action field
     540        TextField<String> fwdactionF = new ForwardField();
     541        fs.add(fwdactionF);
     542        // Select field
     543        Select<VInteger> typeS = new Select<VInteger>(VANNOTYPEID);
     544        typeS.setLabel("Type");
     545        typeS.addOption(new Option("0").setContent("-- New --"));
     546        if (dc != null)
     547        {
     548            ItemQuery<AnnotationType> query = AnnotationType.getQuery(item
     549            .getType());
     550            for (AnnotationType at : query.list(dc))
     551            {
     552                typeS.addOption(new Option(new Integer(at.getId()).toString(),
     553                at.getName()));
     554            }
     555        }
     556        typeS.setLabel("Type");
     557        fs.add(typeS);
     558        // new field
     559        TextField<String> nameF = new TextField<String>(VANNONAME);
     560        nameF.setLabel("Name");
     561        fs.add(nameF);
     562        // value field
     563        TextField<String> valueF = new TextField<String>(VANNOVALUE);
     564        valueF.setLabel("Value");
     565        fs.add(valueF);
     566        if (item != null)
     567        {
     568            idF.setValue(item.getId());
     569            typeF.setValue(Item.fromClass(item.getClass()).name());
     570            fwdactionF.setValue(forwardAction.getName());
     571        }
     572        return form;
     573    }
     574   
     575    /**
     576        * @return Hidden
     577        *         <code>TextField<String> using the valid parameter {@link #VTYPE}.
     578    */
     579    private TextField<String> newTypeField()
     580    {
     581        TextField<String> field = new TextField<String>(VTYPE).setHidden(true);
     582        return field;
     583    }
     584   
     585    public Form getViewUserPropertiesForm(User user)
     586    {
     587        return getForm(User.class, user);
     588    }
     589   
     590    /**
     591        * Form for user preferences configuration settings. Arguments
     592        * NotificationConfiguration and TablePreferencesConfiguration are place
     593        * holders for current values for the notification configuration and table
     594        * preferences configuration form fields.
     595        *
     596        * @param nc NotificationConfiguration object (need not be stored in
     597        *        database) with default field values.
     598        * @return Form A form for setting user preferences configuration values.
     599    */
     600    public Form getUserPreferencesConfigurationForm(
     601    NotificationConfiguration nc, TablePreferencesConfiguration tpc)
     602    {
     603        Form form = new Form("userPreferencesConfigurationForm");
     604        // Notification configuration field set
     605        Fieldset notificationConfigurationFS = getNotificationConfigurationFieldset(nc);
     606        form.addFieldset(notificationConfigurationFS);
     607        // Table preferences configuration field set
     608        Fieldset tablePreferencesConfigurationFS = getTablePreferencesConfigurationFieldset(tpc);
     609        form.addFieldset(tablePreferencesConfigurationFS);
     610        //
     611        return form;
     612    }
     613   
     614    /**
     615        * Fieldset for notification configuration settings. Argument
     616        * NotificationConfiguration is place holder for current values for the
     617        * notification configuration form fields.
     618        *
     619        * @param nc NotificationConfiguration object (need not be stored in
     620        *        database) with default field values.
     621        * @return Fieldset A fieldset for setting NotificationConfiguration values.
     622    */
     623    public Fieldset getNotificationConfigurationFieldset(
     624    NotificationConfiguration nc)
     625    {
     626        // properties
     627        Fieldset properties = new Fieldset();
     628        properties.setTitle("NotificationConfiguration");
     629        // SMTP host field
     630        TextField<String> smtpHostF = new TextField<String>(
     631        SavePreferences.VSMTPHOSTREADONLY);
     632        smtpHostF.setLabel("MailServer");
     633        smtpHostF.setDisabled(true);
     634        properties.add(smtpHostF);
     635        // "From" address field
     636        TextField<String> fromAddressF = new TextField<String>(
     637        SavePreferences.VFROMADDRESSREADONLY);
     638        fromAddressF.setLabel("FromAddress");
     639        fromAddressF.setDisabled(true);
     640        properties.add(fromAddressF);
     641        // "From" name field
     642        TextField<String> fromNameF = new TextField<String>(
     643        SavePreferences.VFROMNAME);
     644        fromNameF.setLabel("FromName");
     645        properties.add(fromNameF);
     646        // "To" address field
     647        TextField<String> toAddressF = new TextField<String>(
     648        SavePreferences.VTOADDRESS);
     649        toAddressF.setLabel("ToAddress");
     650        properties.add(toAddressF);
     651        // Notification mode select box
     652        int initialMode = -1;
     653        if (nc != null)
     654        {
     655            initialMode = nc.getMode();
     656        }
     657        Select<VInteger> modeS = getNotificationModeSelectBox(initialMode);
     658        properties.add(modeS);
     659        //
     660        if (nc != null)
     661        {
     662            smtpHostF.setValue(nc.getSmtpHost());
     663            fromAddressF.setValue(nc.getFromAddress());
     664            fromNameF.setValue(nc.getFromName());
     665            toAddressF.setValue(nc.getToAddress());
     666        }
     667        //
     668        return properties;
     669    }
     670   
     671    /**
     672        * Creates a select box for notification mode.
     673        *
     674        * @param modeValue int Mode value for default selection.
     675        * @return Select<VInteger> Select box for notification mode selection
     676    */
     677    private Select<VInteger> getNotificationModeSelectBox(int modeValue)
     678    {
     679        Select<VInteger> modeS = new Select<VInteger>(
     680        SavePreferences.VNOTIFICATIONMODE);
     681        modeS.setLabel("NotificationMode");
     682        //
     683        NotificationConfiguration.Mode modeArray[] = NotificationConfiguration.Mode
     684        .values();
     685        int numOptions = modeArray.length;
     686        for (int i = 0; i < numOptions; i++)
     687        {
     688            Option o = new Option("" + modeArray[i].getValue());
     689            o.setContent("" + modeArray[i]);
     690            if (modeArray[i].getValue() == modeValue)
     691            {
     692                o.setSelected(true);
     693            }
     694            modeS.addOption(o);
     695        }
     696        return modeS;
     697    }
     698   
     699    /**
     700        * Fieldset for table preferences configuration settings. Argument
     701        * TablePreferencesConfiguration is place holder for current values for the
     702        * table preferences configuration form fields.
     703        *
     704        * @param tpc TablePreferencesConfiguration object (need not be stored in
     705        *        database) with default field values.
     706        * @return Fieldset A field set for setting TablePreferencesConfiguration
     707        *         values.
     708    */
     709    public Fieldset getTablePreferencesConfigurationFieldset(
     710    TablePreferencesConfiguration tpc)
     711    {
     712        // properties
     713        Fieldset properties = new Fieldset();
     714        properties.setTitle("TablePreferencesConfiguration");
     715        // Table preferences reset check-box
     716        Checkbox<VBoolean> tablePreferencesResetCB = new Checkbox<VBoolean>(
     717        SavePreferences.VTABLEPREFERENCESRESET);
     718        tablePreferencesResetCB.setLabel("TablePreferencesReset");
     719        tablePreferencesResetCB.setValue("true");
     720        tablePreferencesResetCB.isChecked(false);
     721        properties.add(tablePreferencesResetCB);
     722        // Table preferences mode select box
     723        int initialMode = -1;
     724        if (tpc != null)
     725        {
     726            initialMode = tpc.getMode();
     727        }
     728        Select<VInteger> modeS = getTablePreferencesModeSelectBox(initialMode);
     729        properties.add(modeS);
     730        //
     731        return properties;
     732    }
     733   
     734    /**
     735        * Creates a select box for table preferences mode.
     736        *
     737        * @param modeValue int Mode value for default selection.
     738        * @return Select<VInteger> Select box for table preferences mode selection
     739    */
     740    private Select<VInteger> getTablePreferencesModeSelectBox(int modeValue)
     741    {
     742        Select<VInteger> modeS = new Select<VInteger>(
     743        SavePreferences.VTABLEPREFERENCESMODE);
     744        modeS.setLabel("TablePreferencesMode");
     745        //
     746        TablePreferencesConfiguration.Mode modeArray[] = TablePreferencesConfiguration.Mode
     747        .values();
     748        int numOptions = modeArray.length;
     749        for (int i = 0; i < numOptions; i++)
     750        {
     751            Option o = new Option("" + modeArray[i].getValue());
     752            o.setContent("" + modeArray[i]);
     753            if (modeArray[i].getValue() == modeValue)
     754            {
     755                o.setSelected(true);
     756            }
     757            modeS.addOption(o);
     758        }
     759        return modeS;
     760    }
     761   
     762    /**
     763        * This will probably be removed when fixint #691
     764        * @param peaklist to edit, or null if an empty form is needed
     765        * @return Form for editing a peaklist
     766    */
     767    public Form getPeakListForm(PeakList peaklist)
     768    {
     769        DbControl dc = peaklist.getDbControl();
     770        ItemFactory factory = new ItemFactory(dc);
     771        Annotator anna = new Annotator(factory);
     772        /***********************************************************************
     773            * Properties fieldset
     774        */
     775        Fieldset propertiesFS = new Fieldset();
     776        propertiesFS.setTitle("Properties");
     777        TextField<Integer> spectrumIdF = new TextField<Integer>(new VInteger(
     778        "spectrumId", 1, true));
     779        spectrumIdF.setLabel("SpectrumId");
     780        propertiesFS.add(spectrumIdF);
     781        /***********************************************************************
     782            * Precursor
     783        */
     784        Fieldset precursorFS = new Fieldset();
     785        precursorFS.setTitle("Precursor");
     786        /***********************************************************************
     787            * Peaklistset fieldset
     788        */
     789        Fieldset peaklistsetFS = new Fieldset();
     790        peaklistsetFS.setTitle("ParentPeakListSet");
     791        PeakListSet pls = peaklist.getPeakListSet();
     792        TextField<String> plsNameF = new NameField();
     793        plsNameF.setDisabled(true);
     794        // Annotations
     795        peaklistsetFS.add(plsNameF);
     796        AnnotationSet as = anna.getAnnotationSet(pls);
     797        for (Annotation a : as.getAnnotations().list(dc))
     798        {
     799            // Only add annotations that contain something
     800            String value = joinAnnotationValues(a);
     801            if (value != null && !value.equals(""))
     802            peaklistsetFS.add(newTextField(a.getAnnotationType().getName(),
     803            value));
     804        }
     805        /***********************************************************************
     806            * Init fields
     807        */
     808        if (peaklist != null)
     809        {
     810            spectrumIdF.setValue(peaklist.getSpectrumId());
     811            spectrumIdF.setDisabled(true);
     812            if (pls != null)
     813            {
     814                plsNameF.setValue(pls.getName());
     815            }
     816            /*******************************************************************
     817                * Precursors
     818            */
     819            for (Precursor pc : peaklist.getPrecursorsQuery().list(
     820            peaklist.getDbControl()))
     821            {
     822                precursorFS.add(newTextField("charge state", pc
     823                .getChargeState()));
     824                //       
     825                precursorFS.add(newTextField("m/z", pc.getMassToChargeRatio()));
     826                precursorFS.add(newTextField("intensity", pc.getIntensity()));
     827                // ion selection
     828                InstrumentConfiguration<?> ionSelection = pc.getIonSelection();
     829                if (ionSelection != null)
     830                {
     831                    AnnotationSet ionAS = anna.getAnnotationSet(ionSelection);
     832                    for (Annotation a : ionAS.getAnnotations().list(dc))
     833                    {
     834                        precursorFS.add(newTextField(a.getAnnotationType()
     835                        .getName(), a.getValues().get(0)));
     836                    }
     837                }
     838                // Activation
     839                InstrumentConfiguration<?> activation = pc.getActivation();
     840                if (activation != null)
     841                {
     842                    AnnotationSet actAS = anna.getAnnotationSet(activation);
     843                    for (Annotation a : actAS.getAnnotations().list(dc))
     844                    {
     845                        precursorFS.add(newTextField(a.getAnnotationType()
     846                        .getName(), a.getValues().get(0)));
     847                    }
     848                }
     849            }
     850        }
     851        /***********************************************************************
     852            * Form
     853        */
     854        Form form = new Form("Peaklist");
     855        form.addFieldset(propertiesFS);
     856        form.addFieldset(precursorFS);
     857        form.addFieldset(peaklistsetFS);
     858        return form;
     859    }
     860   
     861    /**
     862        * @param hit Current Hit
     863        * @param peakListFile Core file with peakList, or null
     864        * @param peaklist to display, or null
     865        * @return Form for displaying peaklist for hit
     866    */
     867    public Form getHitPeakListForm(Hit hit, File peakListFile,
     868    PeakList peaklist, SpectrumSearch spectrumSearch)
     869    {
     870        DbControl dc = hit.getDbControl();
     871        ItemFactory factory = new ItemFactory(dc);
     872        Annotator anna = new Annotator(factory);
     873        /***********************************************************************
     874            * Properties fieldset
     875        */
     876        Fieldset propertiesFS = new Fieldset();
     877        propertiesFS.setTitle("Properties");
     878        /*
     879            * Hit id field.
     880        */
     881        TextField<String> hitDescription = new TextField<String>(new VString(
     882        "description", 0, 255));
     883        if (hit.isProtein() == null || hit.isProtein())
     884        {
     885            hitDescription.setLabel("Description");
     886        }
     887        else
     888        {
     889            hitDescription.setLabel("Sequence");
     890        }
     891        hitDescription.setValue(hit.getDescription());
     892        hitDescription.setDisabled(true);
     893        propertiesFS.add(hitDescription);
     894        TextField<String> hitId = new TextField<String>(new VString("hitId", 0,
     895        255));
     896        hitId.setLabel("Accession");
     897        hitId.setValue(hit.getExternalId());
     898        hitId.setDisabled(true);
     899        propertiesFS.add(hitId);
     900        /*
     901            * If there is a SpectrumSearch in the DB we can find modifications etc.
     902        */
     903        if (spectrumSearch != null)
     904        {
     905            Iterator<SearchModification> smIt = spectrumSearch
     906            .getSearchModifications().iterator();
     907            while (smIt.hasNext())
     908            {
     909                SearchModification mod = smIt.next();
     910                if (mod.isFixed())
     911                {
     912                    TextField<String> modF = new TextField<String>(new VString(
     913                    "mod", 0, 255));
     914                    modF.setLabel("FixedModification");
     915                    modF.setValue(mod.getName());
     916                    modF.setDisabled(true);
     917                    propertiesFS.add(modF);
     918                }
     919            }
     920        }
     921        /*
     922            * File name field.
     923        */
     924        TextField<String> fileNameF = new TextField<String>(new VString(
     925        "FileName", 0, 255));
     926        fileNameF.setLabel("PeakListFileName");
     927        String peakListFileName = new String("null");
     928        if (peakListFile != null)
     929        {
     930            peakListFileName = peakListFile.getName();
     931        }
     932        fileNameF.setValue(peakListFileName);
     933        fileNameF.setDisabled(true);
     934        propertiesFS.add(fileNameF);
     935        /*
     936            * SpectrumId field.
     937        */
     938        // TextField<Integer> spectrumIdF = new TextField<Integer>(new VInteger(
     939        // "spectrumId", 1, true));
     940        TextField<String> spectrumIdF = new TextField<String>(new VString(
     941        "spectrumIdString", 0, 255));
     942        spectrumIdF.setLabel("SpectrumId");
     943        Integer spectrumId = hit.getSpectrumId();
     944        String spectrumIdStr = hit.getSpectrumStringId();
     945        if (spectrumIdStr == null && spectrumId != null)
     946        {
     947            spectrumIdStr = spectrumId.toString();
     948        }
     949        spectrumIdF.setValue(spectrumIdStr);
     950        spectrumIdF.setDisabled(true);
     951        propertiesFS.add(spectrumIdF);
     952        /*
     953            * Retention time in minutes
     954        */
     955        TextField<String> timeInMinutesF = new TextField<String>(new VString(
     956        "timeInMinutesString", 0, 255));
     957        timeInMinutesF.setLabel("RetentionTimeInMinutes");
     958        String timeInMinutesStr = new String("null");
     959        if (peaklist != null)
     960        {
     961            Float retentionTimeInMinutes = peaklist.getTimeInMinutes();
     962            if (retentionTimeInMinutes != null)
     963            {
     964                timeInMinutesStr = retentionTimeInMinutes.toString();
     965            }
     966            log
     967            .debug("FormFactory::getHitPeakListForm(): retentionTimeInMinutes = " + retentionTimeInMinutes);
     968        }
     969        timeInMinutesF.setValue(timeInMinutesStr);
     970        timeInMinutesF.setDisabled(true);
     971        propertiesFS.add(timeInMinutesF);
     972        /***********************************************************************
     973            * Optional PeakList fieldsets
     974        */
     975        Fieldset precursorFS = null;
     976        Fieldset peaklistsetFS = null;
     977        if (peaklist != null)
     978        {
     979            /*******************************************************************
     980                * Precursor
     981            */
     982            precursorFS = new Fieldset();
     983            precursorFS.setTitle("Precursor");
     984            /*******************************************************************
     985                * Peaklistset fieldset
     986            */
     987            peaklistsetFS = new Fieldset();
     988            peaklistsetFS.setTitle("ParentPeakListSet");
     989            PeakListSet pls = peaklist.getPeakListSet();
     990            TextField<String> plsNameF = new NameField();
     991            plsNameF.setDisabled(true);
     992            peaklistsetFS.add(plsNameF);
     993            /*******************************************************************
     994                * Init fields
     995            */
     996            // spectrumIdF.setValue(peaklist.getSpectrumId());
     997            // spectrumIdF.setDisabled(true);
     998            if (pls != null)
     999            {
     1000                plsNameF.setValue(pls.getName());
     1001                // Annotations
     1002                AnnotationSet as = anna.getAnnotationSet(pls);
     1003                for (Annotation a : as.getAnnotations().list(dc))
     1004                {
     1005                    // Only add annotations that contain something
     1006                    String value = joinAnnotationValues(a);
     1007                    if (value != null && !value.equals(""))
     1008                    peaklistsetFS.add(newTextField(a.getAnnotationType()
     1009                    .getName(), value));
     1010                }
     1011            }
     1012            else
     1013            {
     1014                /*
     1015                    * Do not display empty PeakListSet field set.
     1016                */
     1017                peaklistsetFS = null;
     1018            }
     1019            /*******************************************************************
     1020                * Precursors
     1021            */
     1022            for (Precursor pc : peaklist.getPrecursorList())
     1023            {
     1024                precursorFS.add(newTextField("charge state", pc
     1025                .getChargeState()));
     1026                //       
     1027                precursorFS.add(newTextField("m/z", pc.getMassToChargeRatio()));
     1028                precursorFS.add(newTextField("intensity", pc.getIntensity()));
     1029                // ion selection
     1030                InstrumentConfiguration<?> ionSelection = pc.getIonSelection();
     1031                if (ionSelection != null)
     1032                {
     1033                    AnnotationSet ionAS = anna.getAnnotationSet(ionSelection);
     1034                    for (Annotation a : ionAS.getAnnotations().list(dc))
     1035                    {
     1036                        precursorFS.add(newTextField(a.getAnnotationType()
     1037                        .getName(), a.getValues().get(0)));
     1038                    }
     1039                }
     1040                // Activation
     1041                InstrumentConfiguration<?> activation = pc.getActivation();
     1042                if (activation != null)
     1043                {
     1044                    AnnotationSet actAS = anna.getAnnotationSet(activation);
     1045                    for (Annotation a : actAS.getAnnotations().list(dc))
     1046                    {
     1047                        precursorFS.add(newTextField(a.getAnnotationType()
     1048                        .getName(), a.getValues().get(0)));
     1049                    }
     1050                }
     1051            }
     1052            if (peaklist.getPrecursorList() == null || peaklist
     1053            .getPrecursorList().size() == 0)
     1054            {
     1055                /*
     1056                    * Do not display empty Precursor field set.
     1057                */
     1058                precursorFS = null;
     1059            }
     1060        }
     1061        /***********************************************************************
     1062            * Form
     1063        */
     1064        Form form = new Form("HitPeaklist");
     1065        form.addFieldset(propertiesFS);
     1066        if (precursorFS != null)
     1067        {
     1068            form.addFieldset(precursorFS);
     1069        }
     1070        if (peaklistsetFS != null)
     1071        {
     1072            form.addFieldset(peaklistsetFS);
     1073        }
     1074        return form;
     1075    }
     1076   
     1077    /**
     1078        * @param a annotation
     1079        * @return String
     1080    */
     1081    private String joinAnnotationValues(Annotation a)
     1082    {
     1083        List<?> values = a.getValues();
     1084        StringBuilder sb = new StringBuilder();
     1085        for (Object o : values)
     1086        sb.append(o);
     1087        return sb.toString();
     1088    }
     1089   
     1090    /**
     1091        * Returns a form for selecting spectrum mass range limits.
     1092        *
     1093        * @param massCutoffLow String The lower cutoff mass value.
     1094        * @param massCutoffHigh String The upper cutoff mass value.
     1095        * @param spectrumId String The spectrum Id string.
     1096        * @return Form for selecting mass range limits.
     1097    */
     1098    public Form getSpectrumMassRangeSelectionForm(String massCutoffLow,
     1099    String massCutoffHigh, String spectrumId)
     1100    {
     1101        /***********************************************************************
     1102            * Mass range fieldset
     1103        */
     1104        Fieldset massRangeFS = new Fieldset();
     1105        massRangeFS.setTitle("SpectrumMassRangeSelection");
     1106        //
     1107        TextField<String> cutoffLowF = new TextField<String>(
     1108        PlotFileSpectrum.VMASSCUTOFFLOWSTR);
     1109        cutoffLowF.setLabel("SpectrumMassCutoffLow");
     1110        if (massCutoffLow != null)
     1111        {
     1112            cutoffLowF.setValue(massCutoffLow);
     1113        }
     1114        massRangeFS.add(cutoffLowF);
     1115        //
     1116        TextField<String> cutoffHighF = new TextField<String>(
     1117        PlotFileSpectrum.VMASSCUTOFFHIGHSTR);
     1118        cutoffHighF.setLabel("SpectrumMassCutoffHigh");
     1119        if (massCutoffHigh != null)
     1120        {
     1121            cutoffHighF.setValue(massCutoffHigh);
     1122        }
     1123        massRangeFS.add(cutoffHighF);
     1124        //
     1125        TextField<String> spectrumIdF = new TextField<String>(
     1126        PlotFileSpectrum.VSPECTRUMID);
     1127        spectrumIdF.setHidden(true);
     1128        spectrumIdF.setValue(spectrumId);
     1129        massRangeFS.add(spectrumIdF);
     1130        /***********************************************************************
     1131            * Form
     1132        */
     1133        Form form = new Form("MassRangeSelectionForm");
     1134        form.setTitle("MassRangeSelectionForm");
     1135        form.addFieldset(massRangeFS);
     1136        return form;
     1137    }
     1138   
     1139    /**
     1140        * Returns a form with spectrum properties for a spectrum obtained from a
     1141        * spectrum file.
     1142        *
     1143        * @param spectrumFile File Core file with spectrum.
     1144        * @param spectrumId String Spectrum id string.
     1145        * @param spectrum SpectrumInterface spectrum data.
     1146        * @return Form for displaying spectrum properties
     1147    */
     1148    public Form getSpectrumPropertiesForm(File spectrumFile, String spectrumId,
     1149    SpectrumInterface spectrum)
     1150    {
     1151        /***********************************************************************
     1152            * Properties fieldset
     1153        */
     1154        Fieldset propertiesFS = new Fieldset();
     1155        //
     1156        Table propertiesTable = new Table("Properties");
     1157        propertiesTable.setTitle("Properties");
     1158        propertiesTable.add(new Column<String>("Property"));
     1159        propertiesTable.add(new Column<String>("Value"));
     1160        propertiesFS.add(propertiesTable);
     1161        /*
     1162            * File name
     1163        */
     1164        String peakListFileName = null;
     1165        if (spectrumFile != null)
     1166        {
     1167            peakListFileName = spectrumFile.getName();
     1168        }
     1169        addTableRow(propertiesTable, "Filename", peakListFileName, null, 0);
     1170        /*
     1171            * File type
     1172        */
     1173        String spectrumFileType = null;
     1174        if (spectrumFile != null)
     1175        {
     1176            if (spectrumFile.getFileType() != null)
     1177            {
     1178                spectrumFileType = spectrumFile.getFileType().getName();
     1179            }
     1180        }
     1181        addTableRow(propertiesTable, "FileType", spectrumFileType, null, 0);
     1182        /*
     1183            * SpectrumId
     1184        */
     1185        String spectrumIdStr = null;
     1186        if (spectrumId != null)
     1187        {
     1188            spectrumIdStr = spectrumId;
     1189        }
     1190        addTableRow(propertiesTable, "SpectrumId", spectrumIdStr, null, 0);
     1191        /*
     1192            * Retention time in minutes
     1193        */
     1194        String timeInMinutesStr = null;
     1195        if (spectrum != null)
     1196        {
     1197            Float retentionTimeInMinutes = null;
     1198            if (spectrum.getRetentionTimeInMinutes() != null)
     1199            {
     1200                retentionTimeInMinutes = spectrum.getRetentionTimeInMinutes()
     1201                .floatValue();
     1202            }
     1203            if (retentionTimeInMinutes != null)
     1204            {
     1205                timeInMinutesStr = retentionTimeInMinutes.toString();
     1206            }
     1207        }
     1208        addTableRow(propertiesTable, "RetentionTimeInMinutes",
     1209        timeInMinutesStr, null, 0);
     1210        /***********************************************************************
     1211            * Optional spectrum fieldset
     1212        */
     1213        Table precursorTable = null;
     1214        if (spectrum != null)
     1215        {
     1216            if (spectrum.getPrecursors() != null)
     1217            {
     1218                /***************************************************************
     1219                    * Precursors
     1220                */
     1221                int precursorNo = 0;
     1222                for (SpectrumPrecursor pc : spectrum.getPrecursors())
     1223                {
     1224                    precursorNo++;
     1225                    precursorTable = new Table("Precursor");
     1226                    // Only print table header for first table
     1227                    if (precursorNo == 1)
     1228                    {
     1229                        precursorTable.setTitle("Precursor");
     1230                    }
     1231                    precursorTable.add(new Column<String>("Property"));
     1232                    precursorTable.add(new Column<String>("Value"));
     1233                    // Get precursor ion data from selected ion list, if
     1234                    // existing
     1235                    List<PrecursorSelectedIon> selectedIonList = pc
     1236                    .getSelectedIonList();
     1237                    if (selectedIonList != null && selectedIonList.size() > 0)
     1238                    {
     1239                        for (PrecursorSelectedIon selectedIon : selectedIonList)
     1240                        {
     1241                            addTableRow(precursorTable, "charge state",
     1242                            selectedIon.getCharge(), null, 0);
     1243                            addTableRow(precursorTable, "m/z", selectedIon
     1244                            .getMassToChargeRatio(), null, 0);
     1245                            addTableRow(precursorTable, "intensity",
     1246                            selectedIon.getIntensity(), null, 0);
     1247                            // Selected ion extra data
     1248                            List<StringPairInterface> dataList = selectedIon
     1249                            .getExtraDataList();
     1250                            if (dataList != null)
     1251                            {
     1252                                for (int i = 0; i < dataList.size(); i++)
     1253                                {
     1254                                    StringPairInterface data = dataList.get(i);
     1255                                    if (data != null)
     1256                                    {
     1257                                        String name = data.getName();
     1258                                        String value = data.getValue();
     1259                                        if (name != null && !name.equals(""))
     1260                                        {
     1261                                            addTableRow(precursorTable, name,
     1262                                            value, null, 0);
     1263                                        }
     1264                                    }
     1265                                }
     1266                            }
     1267                        }
     1268                    }
     1269                    else
     1270                    {
     1271                        addTableRow(precursorTable, "charge state", pc
     1272                        .getCharge(), null, 0);
     1273                        addTableRow(precursorTable, "m/z", pc
     1274                        .getMassToChargeRatio(), null, 0);
     1275                        addTableRow(precursorTable, "intensity", pc
     1276                        .getIntensity(), null, 0);
     1277                    }
     1278                    /*
     1279                        * Precursor extra data
     1280                    */
     1281                    List<StringPairInterface> dataList = pc.getExtraDataList();
     1282                    if (dataList != null)
     1283                    {
     1284                        for (int i = 0; i < dataList.size(); i++)
     1285                        {
     1286                            StringPairInterface data = dataList.get(i);
     1287                            if (data != null)
     1288                            {
     1289                                String name = data.getName();
     1290                                String value = data.getValue();
     1291                                if (name != null && !name.equals(""))
     1292                                {
     1293                                    addTableRow(precursorTable, name, value,
     1294                                    null, 0);
     1295                                }
     1296                            }
     1297                        }
     1298                    }
     1299                    /*
     1300                        * Precursor fragmentation type
     1301                    */
     1302                    SpectrumPrecursor.FragmentationType fragmentationType = pc
     1303                    .getFragmentationType();
     1304                    String fragmentationTypeStr = new String(
     1305                    "FragmentationType");
     1306                    addTableRow(precursorTable, fragmentationTypeStr,
     1307                    fragmentationType, null, 0);
     1308                    //
     1309                    propertiesFS.add(precursorTable);
     1310                }
     1311            }
     1312            if (spectrum.getExtraDataList() != null && spectrum
     1313            .getExtraDataList().size() > 0)
     1314            {
     1315                /*
     1316                    * Extra data.
     1317                */
     1318                Table extraDataTable = new Table("AdditionalInformation");
     1319                extraDataTable.setTitle("AdditionalInformation");
     1320                extraDataTable.add(new Column<String>("Property"));
     1321                extraDataTable.add(new Column<String>("Value"));
     1322                List<StringPairInterface> dataList = spectrum
     1323                .getExtraDataList();
     1324                if (dataList != null)
     1325                {
     1326                    for (int i = 0; i < dataList.size(); i++)
     1327                    {
     1328                        StringPairInterface data = dataList.get(i);
     1329                        if (data != null)
     1330                        {
     1331                            String name = data.getName();
     1332                            String value = data.getValue();
     1333                            if (name != null && !name.equals(""))
     1334                            {
     1335                                addTableRow(extraDataTable, name, value, null,
     1336                                0);
     1337                            }
     1338                        }
     1339                    }
     1340                }
     1341                propertiesFS.add(extraDataTable);
     1342            }
     1343        }
     1344        /***********************************************************************
     1345            * Form
     1346        */
     1347        Form form = new Form("SpectrumProperties");
     1348        form.addFieldset(propertiesFS);
     1349        return form;
     1350    }
     1351   
     1352    /**
     1353        * Returns a form with spectrum file instrument data for a spectrum file.
     1354        *
     1355        * @param spectrumFileInstrumentList List<SpectrumFileInstrumentInterface>
     1356        *        Spectrum file instrument list.
     1357        * @return Form for displaying spectrum file instrument data.
     1358    */
     1359    public Form getSpectrumFileInstrumentForm(
     1360    List<SpectrumFileInstrumentInterface> spectrumFileInstrumentList)
     1361    {
     1362        if (spectrumFileInstrumentList == null || spectrumFileInstrumentList
     1363        .size() == 0)
     1364        {
     1365            return null;
     1366        }
     1367        /***********************************************************************
     1368            * Instrument fieldset
     1369        */
     1370        Fieldset instrumentFS = new Fieldset();
     1371        int instrumentNo = 0;
     1372        for (SpectrumFileInstrumentInterface spectrumFileInstrument : spectrumFileInstrumentList)
     1373        {
     1374            instrumentNo++;
     1375            List<StringPairInterface> dataList;
     1376            /*
     1377                * Name field.
     1378            */
     1379            Table instrumentGeneralTable = new Table(
     1380            "InstrumentGeneralInformation");
     1381            // Only print table header for first table
     1382            if (instrumentNo == 1)
     1383            {
     1384                instrumentGeneralTable.setTitle("InstrumentInformation");
     1385            }
     1386            // instrumentGeneralTable.add(new Column<String>("Property"));
     1387            instrumentGeneralTable.add(new Column<String>("InstrumentGeneral"));
     1388            instrumentGeneralTable.add(new Column<String>("Value"));
     1389            String instrumentName = null;
     1390            if (spectrumFileInstrument != null)
     1391            {
     1392                instrumentName = spectrumFileInstrument.getInstrumentName();
     1393            }
     1394            addTableRow(instrumentGeneralTable, "InstrumentName",
     1395            instrumentName, null, 0);
     1396            // instrumentFS.add(instrumentGeneralTable);
     1397            /*
     1398                * Serial No field.
     1399            */
     1400            String instrumentSerialNo = null;
     1401            if (spectrumFileInstrument != null)
     1402            {
     1403                instrumentSerialNo = spectrumFileInstrument
     1404                .getInstrumentSerialNo();
     1405            }
     1406            addTableRow(instrumentGeneralTable, "InstrumentSerialNo",
     1407            instrumentSerialNo, null, 0);
     1408            instrumentFS.add(instrumentGeneralTable);
     1409            /*
     1410                * Source field.
     1411            */
     1412            Table sourceTable = new Table("SourceInformation");
     1413            // sourceTable.setTitle("SourceInformation");
     1414            // sourceTable.add(new Column<String>("Property"));
     1415            sourceTable.add(new Column<String>("SourceInformation"));
     1416            sourceTable.add(new Column<String>("Value"));
     1417            dataList = spectrumFileInstrument.getSource();
     1418            if (dataList != null)
     1419            {
     1420                for (int i = 0; i < dataList.size(); i++)
     1421                {
     1422                    StringPairInterface data = dataList.get(i);
     1423                    if (data != null)
     1424                    {
     1425                        String name = data.getName();
     1426                        String value = data.getValue();
     1427                        if (name != null && !name.equals(""))
     1428                        {
     1429                            addTableRow(sourceTable, name, value, null, 0);
     1430                        }
     1431                    }
     1432                }
     1433            }
     1434            instrumentFS.add(sourceTable);
     1435            /*
     1436                * AnalyzerList field.
     1437            */
     1438            List<SpectrumFileAnalyzerInterface> analyzerList = spectrumFileInstrument
     1439            .getAnalyzers();
     1440            if (analyzerList != null)
     1441            {
     1442                for (int j = 0; j < analyzerList.size(); j++)
     1443                {
     1444                    Table analyzerTable = new Table("AnalyzerListInformation");
     1445                    /*
     1446                        * // Only add table title header for first table if (j ==
     1447                        * 0) { analyzerTable.setTitle("AnalyzerListInformation"); }
     1448                    */
     1449                    // analyzerTable.add(new Column<String>("Property"));
     1450                    analyzerTable
     1451                    .add(new Column<String>("AnalyzerInformation"));
     1452                    analyzerTable.add(new Column<String>("Value"));
     1453                    SpectrumFileAnalyzerInterface analyzer = analyzerList
     1454                    .get(j);
     1455                    if (analyzer != null)
     1456                    {
     1457                        dataList = analyzer.getAnalyzer();
     1458                        if (dataList != null)
     1459                        {
     1460                            for (int i = 0; i < dataList.size(); i++)
     1461                            {
     1462                                StringPairInterface data = dataList.get(i);
     1463                                if (data != null)
     1464                                {
     1465                                    String name = data.getName();
     1466                                    String value = data.getValue();
     1467                                    if (name != null && !name.equals(""))
     1468                                    {
     1469                                        addTableRow(analyzerTable, name, value,
     1470                                        null, 0);
     1471                                    }
     1472                                }
     1473                            }
     1474                        }
     1475                    }
     1476                    instrumentFS.add(analyzerTable);
     1477                }
     1478            }
     1479            /*
     1480                * Detector field.
     1481            */
     1482            Table detectorTable = new Table("DetectorInformation");
     1483            // detectorTable.setTitle("DetectorInformation");
     1484            // detectorTable.add(new Column<String>("Property"));
     1485            detectorTable.add(new Column<String>("DetectorInformation"));
     1486            detectorTable.add(new Column<String>("Value"));
     1487            dataList = spectrumFileInstrument.getDetector();
     1488            if (dataList != null)
     1489            {
     1490                for (int i = 0; i < dataList.size(); i++)
     1491                {
     1492                    StringPairInterface data = dataList.get(i);
     1493                    if (data != null)
     1494                    {
     1495                        String name = data.getName();
     1496                        String value = data.getValue();
     1497                        if (name != null && !name.equals(""))
     1498                        {
     1499                            addTableRow(detectorTable, name, value, null, 0);
     1500                        }
     1501                    }
     1502                }
     1503            }
     1504            instrumentFS.add(detectorTable);
     1505            /*
     1506                * Additional field.
     1507            */
     1508            Table additionalTable = new Table("AdditionalInformation");
     1509            // additionalTable.setTitle("AdditionalInformation");
     1510            // additionalTable.add(new Column<String>("Property"));
     1511            additionalTable.add(new Column<String>("AdditionalInformation"));
     1512            additionalTable.add(new Column<String>("Value"));
     1513            dataList = spectrumFileInstrument.getAdditional();
     1514            if (dataList != null)
     1515            {
     1516                for (int i = 0; i < dataList.size(); i++)
     1517                {
     1518                    StringPairInterface data = dataList.get(i);
     1519                    if (data != null)
     1520                    {
     1521                        String name = data.getName();
     1522                        String value = data.getValue();
     1523                        if (name != null && !name.equals(""))
     1524                        {
     1525                            addTableRow(additionalTable, name, value, null, 0);
     1526                        }
     1527                    }
     1528                }
     1529            }
     1530            instrumentFS.add(additionalTable);
     1531        }
     1532        /***********************************************************************
     1533            * Form
     1534        */
     1535        Form form = new Form("InstrumentInformation");
     1536        form.addFieldset(instrumentFS);
     1537        return form;
     1538    }
     1539   
     1540    /**
     1541        * Adds a table row to a table. A "value" argument that is null will be
     1542        * represented as an empty string, otherwise by its toString() value.
     1543        *
     1544        * @param table Table The table to add a row to.
     1545        * @param nameKey String Property key string.
     1546        * @param value Object Property value object.
     1547        * @param actionClass Class<E extends ProteiosAction> Optional value cell
     1548        *        action.
     1549        * @param itemId int The item id to use for an optional action.
     1550    */
     1551    private void addTableRow(Table table, String nameKey, Object value,
     1552    Class<? extends ProteiosAction> actionClass, int itemId)
     1553    {
     1554        // Convert value to string, with empty string for null value
     1555        String valueStr = new String("");
     1556        if (value != null)
     1557        {
     1558            // Convert value to string
     1559            valueStr = "" + value;
     1560        }
     1561        //
     1562        // Construct row
     1563        String rowTitle = new String(nameKey);
     1564        Row row = new Row(rowTitle);
     1565        Cell<String> nameCell = new Cell<String>(locale.get(nameKey));
     1566        Cell<String> valueCell = new Cell<String>(valueStr);
     1567        // Check if value cell should be coupled to action
     1568        if (actionClass != null)
     1569        {
     1570            // Add action link to value cell
     1571            ActionLink cellAction = actionFactory.getActionLink(
     1572            actionClass, actionClass.getName());
     1573            cellAction.addParameter(ItemIdField.VPARAM, itemId);
     1574            valueCell.setActionLink(cellAction);
     1575        }
     1576        row.addCell(nameCell);
     1577        row.addCell(valueCell);
     1578        table.addRow(row);
     1579    }
     1580   
     1581    /**
     1582        * Returns a form with spectrum file contact data for a spectrum file.
     1583        *
     1584        * @param spectrumContact Spectrum file contact
     1585        *        data.
     1586        * @return Form for displaying spectrum file contact data.
     1587    */
     1588    public Form getSpectrumFileContactForm(
     1589    SpectrumFileContactInterface spectrumContact)
     1590    {
     1591        if (spectrumContact == null)
     1592        {
     1593            return null;
     1594        }
     1595        /***********************************************************************
     1596            * Contact fieldset
     1597        */
     1598        Fieldset contactFS = new Fieldset();
     1599        //
     1600        Table contactTable = new Table("ContactInformation");
     1601        contactTable.setTitle("ContactInformation");
     1602        contactTable.add(new Column<String>("Property"));
     1603        contactTable.add(new Column<String>("Value"));
     1604        contactFS.add(contactTable);
     1605        /*
     1606            * Name
     1607        */
     1608        String name = null;
     1609        if (spectrumContact != null)
     1610        {
     1611            name = spectrumContact.getName();
     1612        }
     1613        addTableRow(contactTable, "Name", name, null, 0);
     1614        /*
     1615            * Institution
     1616        */
     1617        String institution = null;
     1618        if (spectrumContact != null)
     1619        {
     1620            institution = spectrumContact.getInstitution();
     1621        }
     1622        addTableRow(contactTable, "Institution", institution, null, 0);
     1623        /*
     1624            * ContactInfo
     1625        */
     1626        String contactInfo = null;
     1627        if (spectrumContact != null)
     1628        {
     1629            contactInfo = spectrumContact.getContactInfo();
     1630        }
     1631        addTableRow(contactTable, "ContactInfo", contactInfo, null, 0);
     1632        /*
     1633            * Address
     1634        */
     1635        String address = null;
     1636        if (spectrumContact != null)
     1637        {
     1638            address = spectrumContact.getAddress();
     1639        }
     1640        addTableRow(contactTable, "Address", address, null, 0);
     1641        /*
     1642            * URL
     1643        */
     1644        String url = null;
     1645        if (spectrumContact != null)
     1646        {
     1647            url = spectrumContact.getUrl();
     1648        }
     1649        addTableRow(contactTable, "URL", url, null, 0);
     1650        /*
     1651            * Email
     1652        */
     1653        String email = null;
     1654        if (spectrumContact != null)
     1655        {
     1656            email = spectrumContact.getEmail();
     1657        }
     1658        addTableRow(contactTable, "Email", email, null, 0);
     1659        /***********************************************************************
     1660            * Form
     1661        */
     1662        Form form = new Form("ContactInformation");
     1663        form.addFieldset(contactFS);
     1664        return form;
     1665    }
     1666   
     1667    /**
     1668        * Returns a form for adding spectrum file contact data for a spectrum file.
     1669        *
     1670        * @param project Project The project in whose directory a new output
     1671        *        directory is created.
     1672        * @param outputDirNameDefault String The default name of the output
     1673        *        directory.
     1674        * @param user User The user from whose profile default contact information
     1675        *        should be taken.
     1676        * @return Form for displaying spectrum file contact data.
     1677    */
     1678    public Form getSpectrumFileContactInputForm(Project project,
     1679    String outputDirNameDefault, User user)
     1680    {
     1681        Form form = new Form("spectrumFileContactInputForm");
     1682        // Get potential default contact information from user profile
     1683        String defaultName = new String("");
     1684        String defaultInstitution = new String("");
     1685        String defaultAddress = new String("");
     1686        String defaultEmail = new String("");
     1687        String defaultContactInfo = new String("");
     1688        if (user != null)
     1689        {
     1690            // Default name
     1691            if (user.getName() != null)
     1692            {
     1693                defaultName = user.getName();
     1694            }
     1695            // Default institution
     1696            if (user.getOrganisation() != null)
     1697            {
     1698                defaultInstitution = user.getOrganisation();
     1699            }
     1700            // Default address
     1701            if (user.getAddress() != null)
     1702            {
     1703                defaultAddress = user.getAddress();
     1704            }
     1705            // Default e-mail
     1706            if (user.getEmail() != null)
     1707            {
     1708                defaultEmail = user.getEmail();
     1709            }
     1710            // Default contact info
     1711            defaultContactInfo = addContactInfoElement(defaultContactInfo,
     1712            "Name", defaultName);
     1713            defaultContactInfo = addContactInfoElement(defaultContactInfo,
     1714            "Institution", defaultInstitution);
     1715            defaultContactInfo = addContactInfoElement(defaultContactInfo,
     1716            "Address", defaultAddress);
     1717            defaultContactInfo = addContactInfoElement(defaultContactInfo,
     1718            "Phone", user.getPhone());
     1719            defaultContactInfo = addContactInfoElement(defaultContactInfo,
     1720            "Fax", user.getFax());
     1721            defaultContactInfo = addContactInfoElement(defaultContactInfo,
     1722            "e-mail", defaultEmail);
     1723        }
     1724        //
     1725        Fieldset contactInputFS = new Fieldset();
     1726        contactInputFS.setTitle("SpectrumFileContactInput");
     1727        form.addFieldset(contactInputFS);
     1728        //
     1729        TextField<String> nameF = new TextField<String>(VNONREQUIRED_NAME);
     1730        nameF.setValue(defaultName);
     1731        nameF.setLabel("Name");
     1732        contactInputFS.add(nameF);
     1733        //
     1734        TextField<String> institutionF = new TextField<String>(
     1735        VNONREQUIRED_INSTITUTION);
     1736        institutionF.setValue(defaultInstitution);
     1737        institutionF.setLabel("Institution");
     1738        contactInputFS.add(institutionF);
     1739        //
     1740        TextField<String> contactInfoF = new TextField<String>(
     1741        VNONREQUIRED_CONTACT_INFO);
     1742        contactInfoF.setValue(defaultContactInfo);
     1743        contactInfoF.setLabel("ContactInfo");
     1744        contactInputFS.add(contactInfoF);
     1745        //
     1746        TextField<String> addressF = new TextField<String>(VNONREQUIRED_ADDRESS);
     1747        addressF.setValue(defaultAddress);
     1748        addressF.setLabel("Address");
     1749        contactInputFS.add(addressF);
     1750        //
     1751        TextField<String> urlF = new TextField<String>(VNONREQUIRED_URL);
     1752        urlF.setValue("");
     1753        urlF.setLabel("URL");
     1754        contactInputFS.add(urlF);
     1755        //
     1756        TextField<String> emailF = new TextField<String>(VNONREQUIRED_EMAIL);
     1757        emailF.setValue(defaultEmail);
     1758        emailF.setLabel("email");
     1759        contactInputFS.add(emailF);
     1760        //
     1761        Fieldset contactOutputFS = new Fieldset();
     1762        contactOutputFS.setTitle("SpectrumFileContactOutput");
     1763        form.addFieldset(contactOutputFS);
     1764        //
     1765        TextField<String> outputDirNameF = new TextField<String>(
     1766        VNONREQUIRED_FILENAME);
     1767        outputDirNameF.setValue(outputDirNameDefault);
     1768        outputDirNameF.setLabel("OutputDirectoryName");
     1769        contactOutputFS.add(outputDirNameF);
     1770        //
     1771        /*
     1772            * Checkbox<VBoolean> overwriteExistingContactDataCB = new Checkbox<VBoolean>(
     1773            * SpectrumFileContactDataAdder.VOVERWRITEEXISTINGCONTACTDATAFLAG);
     1774            * overwriteExistingContactDataCB.setLabel("OverwriteExistingContactData");
     1775            * overwriteExistingContactDataCB.setValue("true");
     1776            * overwriteExistingContactDataCB.isChecked(true);
     1777            * contactOutputFS.add(overwriteExistingContactDataCB);
     1778        */
     1779        //
     1780        return form;
     1781    }
     1782   
     1783    /**
     1784        * Adds an element of data to contact info string.
     1785        *
     1786        * @param contactInfo String Current contact info string.
     1787        * @param elementName String Name of contact info element.
     1788        * @param elementValue String Contents of contact info element.
     1789        * @return String Contact info string with the added info data.
     1790    */
     1791    private String addContactInfoElement(String contactInfo,
     1792    String elementName, String elementValue)
     1793    {
     1794        if (elementValue != null && !elementValue.equals(""))
     1795        {
     1796            if (!contactInfo.equals(""))
     1797            {
     1798                contactInfo += ", ";
     1799            }
     1800            contactInfo += elementName + ": " + elementValue;
     1801        }
     1802        return contactInfo;
     1803    }
     1804   
     1805    /**
     1806        * Returns a form for adding spectrum file sample data for a spectrum file.
     1807        *
     1808        * @param project Project The project in whose directory a new output
     1809        *        directory is created.
     1810        * @param outputDirNameDefault String The default name of the output
     1811        *        directory.
     1812        * @return Form for displaying spectrum file contact data.
     1813    */
     1814    public Form getSpectrumFileSampleInputForm(Project project,
     1815    String outputDirNameDefault)
     1816    {
     1817        Form form = new Form("spectrumFileSampleInputForm");
     1818        //
     1819        Fieldset sampleInputFS = new Fieldset();
     1820        sampleInputFS.setTitle("SpectrumFileSampleInput");
     1821        form.addFieldset(sampleInputFS);
     1822        //
     1823        TextField<String> nameF = new TextField<String>(
     1824        VNONREQUIRED_SAMPLE_NAME);
     1825        nameF.setValue("");
     1826        nameF.setLabel("SampleName");
     1827        sampleInputFS.add(nameF);
     1828        //
     1829        TextField<String> numberF = new TextField<String>(
     1830        VNONREQUIRED_SAMPLE_NUMBER);
     1831        numberF.setValue("");
     1832        numberF.setLabel("SampleNumber");
     1833        sampleInputFS.add(numberF);
     1834        //
     1835        /*
     1836            * TextField<String> stateF = new TextField<String>(VNONREQUIRED_SAMPLE_STATE);
     1837            * stateF.setValue(""); stateF.setLabel("SampleState");
     1838            * sampleInputFS.add(stateF);
     1839        */
     1840        // Sample state select box
     1841        VString validStringParam = VNONREQUIRED_SAMPLE_STATE;
     1842        List<Option> optionList = new ArrayList<Option>();
     1843        optionList.add(new Option("emulsion", "emulsion").setSelected(true));
     1844        optionList.add(new Option("gas", "gas"));
     1845        optionList.add(new Option("liquid", "liquid"));
     1846        optionList.add(new Option("solid", "solid"));
     1847        optionList.add(new Option("solution", "solution"));
     1848        optionList.add(new Option("suspension", "suspension"));