Changeset 3941


Ignore:
Timestamp:
Nov 2, 2010, 2:06:13 PM (13 years ago)
Author:
Gregory Vincic
Message:

Refs #698. Moved method getForm(FormTemplateInterface?) and related methods to the one action that used them.

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

Legend:

Unmodified
Added
Removed
  • trunk/client/servlet/src/org/proteios/action/spectrumSearch/ViewActivePeptideSearchResult.java

    r3935 r3941  
    11/*
    2  $Id$
    3 
    4  Copyright (C) 2006 Fredrik Levander, Gregory Vincic, Olle Mansson
    5  Copyright (C) 2007 Fredrik Levander, 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-2.x 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  */
     2    $Id$
     3                   
     4    Copyright (C) 2006 Fredrik Levander, Gregory Vincic, Olle Mansson
     5    Copyright (C) 2007 Fredrik Levander, Gregory Vincic
     6    Copyright (C) 2010 Gregory Vincic
     7                   
     8    Files are copyright by their respective authors. The contributions to
     9    files where copyright is not explicitly stated can be traced with the
     10    source code revision system.
     11                   
     12    This file is part of Proteios.
     13    Available at http://www.proteios.org/
     14                   
     15    Proteios-2.x is free software; you can redistribute it and/or
     16    modify it under the terms of the GNU General Public License
     17    as published by the Free Software Foundation; either version 2
     18    of the License, or (at your option) any later version.
     19                   
     20    Proteios is distributed in the hope that it will be useful,
     21    but WITHOUT ANY WARRANTY; without even the implied warranty of
     22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     23    GNU General Public License for more details.
     24                   
     25    You should have received a copy of the GNU General Public License
     26    along with this program; if not, write to the Free Software
     27    Foundation, Inc., 59 Temple Place - Suite 330,
     28    Boston, MA  02111-1307, USA.
     29*/
    2930package org.proteios.action.spectrumSearch;
    3031
     32import java.lang.reflect.InvocationTargetException;
     33import java.lang.reflect.Method;
     34import java.lang.reflect.Modifier;
     35import java.text.SimpleDateFormat;
     36import java.util.ArrayList;
     37import java.util.Date;
     38import java.util.List;
    3139import org.proteios.ActionLink;
    3240import org.proteios.action.ProteiosAction;
    3341import org.proteios.action.peakList.PlotFileSpectrum;
    3442import org.proteios.core.Annotation;
     43import org.proteios.core.AnnotationSet;
    3544import org.proteios.core.Annotator;
    3645import org.proteios.core.DbControl;
     
    5160import org.proteios.gui.RowContainer;
    5261import org.proteios.gui.Toolbar;
     62import org.proteios.gui.form.*;
    5363import org.proteios.gui.form.Fieldset;
    54 import org.proteios.gui.form.Form;
    55 import org.proteios.gui.form.FormFactory;
    56 import org.proteios.gui.form.FormTemplateImpl;
    57 import org.proteios.gui.form.FormTemplateInterface;
    5864import org.proteios.gui.layout.RowLayout;
    5965import org.proteios.gui.table.Table;
    6066import org.proteios.gui.table.TableFactory;
    61 
    6267import se.lu.thep.waf.ActionException;
     68import se.lu.thep.waf.constraints.Format;
    6369import se.lu.thep.waf.constraints.InvalidParameterValue;
    6470import se.lu.thep.waf.constraints.VBoolean;
    6571import se.lu.thep.waf.constraints.VInteger;
     72import se.lu.thep.waf.constraints.VString;
    6673
    67 /**
    68  * @author gregory
    69  */
    7074public class ViewActivePeptideSearchResult
    71     extends ProteiosAction<ViewActivePeptideSearchResult>
     75extends ProteiosAction<ViewActivePeptideSearchResult>
    7276{
    73   public static final VInteger VSEARCHRESULTID = new VInteger(
    74     "active.searchresult.id", 1, true);
    75   public static final VBoolean VKEEPORIGINALSPECTRUM = new VBoolean(
    76     "keepOriginalSpectrum", false);
    77 
    78 
    79   @Override
    80   public void runMe()
    81       throws ActionException, InvalidParameterValue
    82   {
    83     verifySessionAttributes(VSEARCHRESULTID);
    84     /***********************************************************************
    85      * Properties
    86      */
    87     Integer ssId = getSessionAttribute(VSEARCHRESULTID);
    88     String massCutoffLowStr = getValidString(PlotFileSpectrum.VMASSCUTOFFLOWSTR);
    89     String massCutoffHighStr = getValidString(PlotFileSpectrum.VMASSCUTOFFHIGHSTR);
    90     Boolean keepOriginalSpectrum = getValidBoolean(VKEEPORIGINALSPECTRUM);
    91     log.debug("ssId = " + ssId);
    92     log.debug("massCutoffLowStr = \"" + massCutoffLowStr + "\"");
    93     log.debug("massCutoffHighStr = \"" + massCutoffHighStr + "\"");
    94     log.debug("(1) keepOriginalSpectrum = " + keepOriginalSpectrum);
    95     if (keepOriginalSpectrum == null)
    96     {
    97       keepOriginalSpectrum = true;
    98     }
    99     log.debug("(2) keepOriginalSpectrum = " + keepOriginalSpectrum);
    100     // Only show one spectrum view if no mass range parameters
    101     if ((massCutoffLowStr == null || massCutoffLowStr.equals(""))
    102       && (massCutoffHighStr == null || massCutoffHighStr.equals("")))
    103     {
    104       keepOriginalSpectrum = false;
    105     }
    106     log.debug("(3) keepOriginalSpectrum = " + keepOriginalSpectrum);
    107     DbControl dc = newDbControl();
    108     ItemFactory factory = new ItemFactory(dc);
    109     TableFactory tableFactory = getTableFactory();
    110     SearchResult ss = factory.getById(SearchResult.class, ssId);
    111     Form mainForm = new Form("Search Result");
    112     Fieldset fs=new Fieldset();
    113     fs.setTitle("Search Result");
    114     mainForm.addFieldset(fs);
    115     FormTemplateImpl formTemplate = new FormTemplateImpl();
    116     formTemplate.setItemObject(ss);
    117     formTemplate.setReadOnlyForm(true);
    118     FormFactory formFactory = getFormFactory();
    119     Form form = formFactory.getForm(formTemplate);
    120     // Peptides:
    121     ItemQuery<Peptide> peptideQuery = Peptide.getQuery();
    122     peptideQuery.restrict(Restrictions.eq(Hql.property("searchResult"), Hql
    123       .entity(ss)));
    124     tableFactory.reset();
    125     tableFactory.setItemClass(Peptide.class);
    126     tableFactory.setQuery(peptideQuery);
    127     ActionLink rowAction = getActionFactory().getActionLink(
    128       ViewExternalId.class, "View");
    129     tableFactory.setColumnAction("AccessionNumber", rowAction);
    130     Table peptideTable = tableFactory.build();
    131     peptideTable.setTitle("Peptides");
    132     peptideTable.setToolbar(null);
    133     /***********************************************************************
    134      * Annotations table
    135      */
    136     Annotator anna = new Annotator(getItemFactory(dc));
    137     tableFactory.reset();
    138     tableFactory.setItemClass(Annotation.class);
    139     ItemQuery<Annotation> annotationQuery = anna.getAnnotationSet(ss)
    140       .getAnnotations();
    141     tableFactory.setQuery(annotationQuery);
    142     Table annotationsTable = tableFactory.build();
    143     ColumnContainer cc = new ColumnContainer();
    144     cc.add(annotationsTable);
    145     /**
    146      * Spectrum plot
    147      */
    148     ItemQuery<Hit> hitQuery = Hit.getQuery();
    149     hitQuery.restrict(Restrictions.eq(Hql.property("identificationResultFile"), Hql
    150       .entity(ss.getSpectrumSearch().getResultFile())));
    151     File peakListFile = null;
    152     ItemResultIterator<Hit> hitit = hitQuery.iterate(dc);
    153     if (hitit.hasNext()) peakListFile = hitit.next().getPeakListFile();
    154     if (peakListFile == null)
    155     {
    156       ItemQuery<File> fileQuery = File.getQuery();
    157       fileQuery.restrict(Restrictions.eq(Hql.property("name"),
    158         Expressions.parameter("name")));
    159       fileQuery.setParameter("name", ss.getSpectrumSearch().getInputSpectrumFileName(), null);
    160       ItemResultIterator<File> fileit = fileQuery.iterate(dc);
    161       if (fileit.hasNext()) peakListFile = fileit.next();
    162     }
    163     if (peakListFile!=null)
    164     {
    165       /***********************************************************************
    166        * Spectrum plot
    167        */
    168       String spectrumId = Integer.toString(ss.getInputSpectrumId());
    169       PlotFileSpectrum plotFileSpectrum = new PlotFileSpectrum();
    170       ImageMap imageMap;
    171       Image plotOriginal = null;
    172       if (keepOriginalSpectrum)
    173       {
    174         plotOriginal = new Image();
    175         ActionLink viewOriginalAction = getActionFactory().getActionLink(
    176           PlotFileSpectrum.class, "ViewOriginal");
    177         viewOriginalAction.addParameter(FormFactory.VID, peakListFile.getId());
    178         viewOriginalAction.addParameter(PlotFileSpectrum.VSPECTRUMID, spectrumId);
    179         plotOriginal.setViewAction(viewOriginalAction);
    180         plotOriginal.setHeight(PlotFileSpectrum.HEIGHT);
    181         plotOriginal.setWidth(PlotFileSpectrum.WIDTH);
    182         // Add mass annotation image map
    183         imageMap = plotFileSpectrum.fetchMassPeakAnnotationToolTips(dc, peakListFile.getId(), spectrumId,
    184           (String) null, (String) null);
    185         plotOriginal.setImageMap(imageMap);
    186       }
    187       Image plot = new Image();
    188       ActionLink viewAction = getActionFactory().getActionLink(
    189         PlotFileSpectrum.class, "View");
    190       viewAction.addParameter(FormFactory.VID, peakListFile.getId());
    191       viewAction.addParameter(PlotFileSpectrum.VSPECTRUMID, spectrumId);
    192       viewAction.addParameter(PlotFileSpectrum.VMASSCUTOFFLOWSTR, massCutoffLowStr);
    193       viewAction.addParameter(PlotFileSpectrum.VMASSCUTOFFHIGHSTR, massCutoffHighStr);
    194       plot.setViewAction(viewAction);
    195       plot.setHeight(PlotFileSpectrum.HEIGHT);
    196       plot.setWidth(PlotFileSpectrum.WIDTH);
    197       // Add mass annotation image map
    198       imageMap = plotFileSpectrum.fetchMassPeakAnnotationToolTips(dc, peakListFile.getId(), spectrumId,
    199         massCutoffLowStr, massCutoffHighStr);
    200       plot.setImageMap(imageMap);
    201       /***********************************************************************
    202        * Spectrum mass range selection form
    203        */
    204       Form massRangeSelectionForm = getFormFactory().getSpectrumMassRangeSelectionForm(massCutoffLowStr, massCutoffHighStr, spectrumId);
    205       Toolbar toolbar = new Toolbar();
    206       massRangeSelectionForm.setToolbar(toolbar);
    207       //
    208       ActionLink zoomWithOriginalAction = getActionLink(ViewActivePeptideSearchResult.class, "ZoomedAndOriginalSpectrum");
    209       //zoomWithOriginalAction.addParameter(FormFactory.VID, peakListFile.getId());
    210       zoomWithOriginalAction.addParameter(VKEEPORIGINALSPECTRUM, true);
    211       toolbar.add(zoomWithOriginalAction);
    212       //
    213       ActionLink zoomAction = getActionLink(ViewActivePeptideSearchResult.class, "ZoomedSpectrum");
    214       //zoomAction.addParameter(FormFactory.VID, peakListFile.getId());
    215       zoomAction.addParameter(VKEEPORIGINALSPECTRUM, false);
    216       toolbar.add(zoomAction);
    217       // Row container for plot and properties form
    218       RowContainer rc = new RowContainer();
    219       if (plotOriginal != null)
    220       {
    221         rc.add(plotOriginal);
    222       }
    223       rc.add(plot);
    224       rc.add(massRangeSelectionForm);
    225       cc.add(rc);
    226     }
    227     /***********************************************************************
    228      * Layout
    229      */
    230     RowLayout layout = getLayoutFactory().getRowLayout();
    231     layout.add(mainForm);
    232     layout.add(form);
    233     layout.add(cc);
    234     layout.add(peptideTable);
    235     setLayout(layout);
    236   }
     77    public static final VInteger VSEARCHRESULTID = new VInteger("active.searchresult.id", 1, true);
     78    public static final VBoolean VKEEPORIGINALSPECTRUM = new VBoolean("keepOriginalSpectrum", false);
     79    public static final VBoolean VREADONLYFORM = new VBoolean("readOnlyForm",false);
     80                   
     81    /**
     82        * List<String> of excluded getter methods declared in current class. If a
     83        * getter accessor method is included in this list, when a generic form for
     84        * an object is created with getForm(), no field will be added to the form
     85        * for an instance variable (if any) corresponding to the getter method.
     86    */
     87    private List<String> excludedDeclMethods = new ArrayList<String>();
     88       
     89    @Override
     90    public void runMe()
     91    throws ActionException, InvalidParameterValue
     92    {
     93        Integer ssId;
     94        String massCutoffLowStr;
     95        String massCutoffHighStr;
     96        Boolean keepOriginalSpectrum;
     97        DbControl dc;
     98        ItemFactory factory;
     99        TableFactory tableFactory;
     100        SearchResult ss;
     101        Form mainForm;
     102        Fieldset fs;
     103        FormTemplateImpl formTemplate;
     104        Form form;
     105        ItemQuery<Peptide> peptideQuery;
     106        ActionLink rowAction;
     107        Table peptideTable;
     108        Annotator anna;
     109        ItemQuery<Annotation> annotationQuery;
     110        Table annotationsTable;
     111        ColumnContainer cc;
     112        ItemQuery<Hit> hitQuery;
     113        File peakListFile;
     114        ItemResultIterator<Hit> hitit;
     115        ItemQuery<File> fileQuery;
     116        ItemResultIterator<File> fileit;
     117        // Define
     118        initExcludedDeclMethods();
     119               
     120        verifySessionAttributes(VSEARCHRESULTID);
     121        ssId = getSessionAttribute(VSEARCHRESULTID);
     122        massCutoffLowStr = getValidString(PlotFileSpectrum.VMASSCUTOFFLOWSTR);
     123        massCutoffHighStr = getValidString(PlotFileSpectrum.VMASSCUTOFFHIGHSTR);
     124        keepOriginalSpectrum = getValidBoolean(VKEEPORIGINALSPECTRUM);
     125        if (keepOriginalSpectrum == null)
     126        {
     127            keepOriginalSpectrum = true;
     128        }
     129        // Only show one spectrum view if no mass range parameters
     130        if ((massCutoffLowStr == null || massCutoffLowStr.equals(""))
     131        && (massCutoffHighStr == null || massCutoffHighStr.equals("")))
     132        {
     133            keepOriginalSpectrum = false;
     134        }
     135        log.debug("keepOriginalSpectrum = " + keepOriginalSpectrum);
     136        dc = newDbControl();
     137        factory = getItemFactory(dc);
     138        tableFactory = getTableFactory();
     139        ss = factory.getById(SearchResult.class, ssId);
     140        mainForm = new Form("Search Result");
     141        fs=new Fieldset();
     142        fs.setTitle("Search Result");
     143        mainForm.addFieldset(fs);
     144        formTemplate = new FormTemplateImpl();
     145        formTemplate.setItemObject(ss);
     146        formTemplate.setReadOnlyForm(true);
     147        form = getForm(formTemplate);
     148        // Peptides:
     149        peptideQuery = Peptide.getQuery();
     150        peptideQuery.restrict(Restrictions.eq(Hql.property("searchResult"), Hql.entity(ss)));
     151        tableFactory.reset();
     152        tableFactory.setItemClass(Peptide.class);
     153        tableFactory.setQuery(peptideQuery);
     154        rowAction = getActionFactory().getActionLink(ViewExternalId.class, "View");
     155        tableFactory.setColumnAction("AccessionNumber", rowAction);
     156        peptideTable = tableFactory.build();
     157        peptideTable.setTitle("Peptides");
     158        peptideTable.setToolbar(null);
     159        // Annotations
     160        anna = new Annotator(getItemFactory(dc));
     161        tableFactory.reset();
     162        tableFactory.setItemClass(Annotation.class);
     163        annotationQuery = anna.getAnnotationSet(ss).getAnnotations();
     164        tableFactory.setQuery(annotationQuery);
     165        annotationsTable = tableFactory.build();
     166        cc = new ColumnContainer();
     167        cc.add(annotationsTable);
     168        // Plot
     169        hitQuery = Hit.getQuery();
     170        hitQuery.restrict(Restrictions.eq(Hql.property("identificationResultFile"), Hql
     171        .entity(ss.getSpectrumSearch().getResultFile())));
     172        peakListFile = null;
     173        hitit = hitQuery.iterate(dc);
     174        if (hitit.hasNext())
     175        {
     176            peakListFile = hitit.next().getPeakListFile();
     177        }
     178        if (peakListFile == null)
     179        {
     180            fileQuery = File.getQuery();
     181            fileQuery.restrict(Restrictions.eq(Hql.property("name"),
     182            Expressions.parameter("name")));
     183            fileQuery.setParameter("name", ss.getSpectrumSearch().getInputSpectrumFileName(), null);
     184            fileit = fileQuery.iterate(dc);
     185            if (fileit.hasNext()) peakListFile = fileit.next();
     186        }
     187        if (peakListFile!=null)
     188        {
     189            String spectrumId = Integer.toString(ss.getInputSpectrumId());
     190            PlotFileSpectrum plotFileSpectrum = new PlotFileSpectrum();
     191            ImageMap imageMap;
     192            Image plotOriginal = null;
     193            if (keepOriginalSpectrum)
     194            {
     195                plotOriginal = new Image();
     196                ActionLink viewOriginalAction = getActionFactory().getActionLink(
     197                PlotFileSpectrum.class, "ViewOriginal");
     198                viewOriginalAction.addParameter(FormFactory.VID, peakListFile.getId());
     199                viewOriginalAction.addParameter(PlotFileSpectrum.VSPECTRUMID, spectrumId);
     200                plotOriginal.setViewAction(viewOriginalAction);
     201                plotOriginal.setHeight(PlotFileSpectrum.HEIGHT);
     202                plotOriginal.setWidth(PlotFileSpectrum.WIDTH);
     203                // Add mass annotation image map
     204                imageMap = plotFileSpectrum.fetchMassPeakAnnotationToolTips(dc, peakListFile.getId(), spectrumId,
     205                (String) null, (String) null);
     206                plotOriginal.setImageMap(imageMap);
     207            }
     208            Image plot = new Image();
     209            ActionLink viewAction = getActionFactory().getActionLink(
     210            PlotFileSpectrum.class, "View");
     211            viewAction.addParameter(FormFactory.VID, peakListFile.getId());
     212            viewAction.addParameter(PlotFileSpectrum.VSPECTRUMID, spectrumId);
     213            viewAction.addParameter(PlotFileSpectrum.VMASSCUTOFFLOWSTR, massCutoffLowStr);
     214            viewAction.addParameter(PlotFileSpectrum.VMASSCUTOFFHIGHSTR, massCutoffHighStr);
     215            plot.setViewAction(viewAction);
     216            plot.setHeight(PlotFileSpectrum.HEIGHT);
     217            plot.setWidth(PlotFileSpectrum.WIDTH);
     218            // Add mass annotation image map
     219            imageMap = plotFileSpectrum.fetchMassPeakAnnotationToolTips(dc, peakListFile.getId(), spectrumId,
     220            massCutoffLowStr, massCutoffHighStr);
     221            plot.setImageMap(imageMap);
     222            // Spectrum mass range selection form
     223            Form massRangeSelectionForm = getFormFactory().getSpectrumMassRangeSelectionForm(massCutoffLowStr, massCutoffHighStr, spectrumId);
     224            Toolbar toolbar = new Toolbar();
     225            massRangeSelectionForm.setToolbar(toolbar);
     226                                               
     227            ActionLink zoomWithOriginalAction = getActionLink(ViewActivePeptideSearchResult.class, "ZoomedAndOriginalSpectrum");
     228            zoomWithOriginalAction.addParameter(VKEEPORIGINALSPECTRUM, true);
     229            toolbar.add(zoomWithOriginalAction);
     230                                               
     231            ActionLink zoomAction = getActionLink(ViewActivePeptideSearchResult.class, "ZoomedSpectrum");
     232            zoomAction.addParameter(VKEEPORIGINALSPECTRUM, false);
     233            toolbar.add(zoomAction);
     234            // Row container for plot and properties form
     235            RowContainer rc = new RowContainer();
     236            if (plotOriginal != null)
     237            {
     238                rc.add(plotOriginal);
     239            }
     240            rc.add(plot);
     241            rc.add(massRangeSelectionForm);
     242            cc.add(rc);
     243        }
     244                               
     245        RowLayout layout = getLayoutFactory().getRowLayout();
     246        layout.add(mainForm);
     247        layout.add(form);
     248        layout.add(cc);
     249        layout.add(peptideTable);
     250        setLayout(layout);
     251    }
     252       
     253    /**
     254        Get generic form for object.
     255                                               
     256        @param template template for generic form
     257        @return Form for editing the object
     258    */
     259    private Form getForm(FormTemplateInterface formTemplate)
     260    {
     261        /***********************************************************************
     262            Analyze object class
     263        */
     264                                               
     265        /*
     266            Get class from formTemplate itemObject or itemClass.
     267        */
     268        Object itemObject = null;
     269        Class<? extends Object> itemClass = null;
     270        if (formTemplate.getItemObject() != null)
     271        {
     272            itemObject = formTemplate.getItemObject();
     273            itemClass = itemObject.getClass();
     274        }
     275        else if (formTemplate.getItemClass() != null)
     276        {
     277            itemClass = formTemplate.getItemClass();
     278        }
     279        /*
     280            Add optional extra formTemplate list of methods to be excluded.
     281        */
     282        if (formTemplate != null && formTemplate.getExcludedDeclMethods() != null)
     283        {
     284            addExcludedDeclMethods(formTemplate.getExcludedDeclMethods());
     285        }
     286        String clsName = new String("");
     287        if (itemClass != null)
     288        {
     289            clsName = itemClass.getSimpleName();
     290        }
     291                                               
     292        /***********************************************************************
     293            Main fieldset
     294        */
     295        Fieldset mainFS = new Fieldset();
     296        String mainFsName = new String("Properties");
     297        mainFS.setTitle(mainFsName);
     298        /*
     299            Add forward actionId field as first field, for external use.
     300        */
     301        TextField<String> fwdactionF = new ForwardField();
     302        mainFS.add(fwdactionF);
     303        /*
     304            Get item id, if any.
     305        */
     306        int itemId = 0;
     307        String getIdMethodName = "getId";
     308        Method getIdMethod = fetchPublicMethodForObject(getIdMethodName,
     309        itemClass);
     310        if (getIdMethod != null && itemObject != null)
     311        {
     312            try
     313            {
     314                Object[] arguments = new Object[] {};
     315                Object retobj = getIdMethod.invoke(itemObject, arguments);
     316                String idStr = retobj.toString();
     317                itemId = Integer.parseInt(idStr);
     318            }
     319            catch (InvocationTargetException e)
     320            {
     321                itemId = 0;
     322            }
     323            catch (IllegalAccessException e)
     324            {
     325                itemId = 0;
     326            }
     327            catch (java.lang.NumberFormatException e)
     328            {
     329                itemId = 0;
     330            }
     331        }
     332        /*
     333            Add itemId field idF (hidden) if itemId value ok.
     334        */
     335        if (itemId > 0)
     336        {
     337            TextField<Integer> idF = new ItemIdField().setHidden(true);
     338            mainFS.add(idF);
     339            idF.setLabel("ItemId");
     340            idF.setValue(itemId);
     341            idF.setDisabled(true);
     342        }
     343        /*
     344            Add class name field cnF.
     345        */
     346        String classNameFull = new String("");
     347        if (itemClass != null)
     348        {
     349            classNameFull = itemClass.getName();
     350        }
     351        TextField<String> cnF = new ClassNameField();
     352        mainFS.add(cnF);
     353        cnF.setHidden(true);
     354        cnF.setLabel("ClassName");
     355        cnF.setValue(classNameFull);
     356        cnF.setDisabled(true);
     357        /*
     358            Add readOnlyForm field rofF (hidden).
     359        */
     360        TextField<Boolean> rofF = newHiddenReadOnlyFormField();
     361        mainFS.add(rofF);
     362        rofF.setLabel("ReadOnlyForm");
     363        rofF.setValue(formTemplate.isReadOnlyForm());
     364        rofF.setDisabled(true);
     365        /*
     366            Keep track on whether public setter methods exist, in order to know
     367            if a "Save" button should be added.
     368        */
     369        boolean hasSetterMethods = false;
     370        /*
     371            Methods, declared and inherited
     372        */
     373        Method[] methodArr = new Method[0];
     374        if (itemClass != null)
     375        {
     376            methodArr = itemClass.getMethods();
     377        }
     378                                               
     379        /*
     380            Methods declared in object class (not inherited)
     381        */
     382        Method[] declaredMethodArr = new Method[0];
     383        if (itemClass != null)
     384        {
     385            declaredMethodArr = itemClass.getDeclaredMethods();
     386        }
     387        for (int i = 0; i < declaredMethodArr.length; i++)
     388        {
     389            Method method = declaredMethodArr[i];
     390            String modStr = methodModifierString(method);
     391            String methodName = method.getName();
     392            String methodReturnType = method.getReturnType().getName();
     393            /*
     394                Only process declared methods not in exclude list.
     395            */
     396            if (!getExcludedDeclMethods().contains(methodName))
     397            {
     398                String attrName = new String("");
     399                String attrValueStr = new String("");
     400                String returnTypeStr = new String("");
     401                boolean returnTypeOK = false;
     402                Class<?> returnTypeOfGetterMethod = null;
     403                /*
     404                    Check if getter access method.
     405                */
     406                if (methodName.startsWith("get"))
     407                {
     408                    /*
     409                        Assume that attribute name can optained by skipping "get"
     410                        in method name.
     411                    */
     412                    attrName = methodName.substring(3);
     413                    // int methodMod = declaredMethodArr[i].getModifiers();
     414                    if (method.getReturnType().getName().equals("int") || method
     415                    .getReturnType().getName().equals("java.lang.Integer") || method
     416                    .getReturnType().getName().equals("float") || method
     417                    .getReturnType().getName().equals("java.lang.Float") || method
     418                    .getReturnType().getName().equals("double") || method
     419                    .getReturnType().getName().equals("java.lang.Double") || method
     420                    .getReturnType().getName().equals("java.lang.String") || method
     421                    .getReturnType().getName().equals("java.util.Date"))
     422                    {
     423                        returnTypeOfGetterMethod = method.getReturnType();
     424                        returnTypeStr = method.getReturnType().getName();
     425                        returnTypeOK = true;
     426                    }
     427                }
     428                else if (methodName.startsWith("is"))
     429                {
     430                    /*
     431                        Assume that attribute name can optained by skipping "is"
     432                        in method name.
     433                    */
     434                    attrName = methodName.substring(2);
     435                    // int methodMod = declaredMethodArr[i].getModifiers();
     436                    if (method.getReturnType().getName().equals("boolean") || method
     437                    .getReturnType().getName().equals("java.lang.Boolean"))
     438                    {
     439                        returnTypeOfGetterMethod = method.getReturnType();
     440                        returnTypeStr = method.getReturnType().getName();
     441                        returnTypeOK = true;
     442                    }
     443                }
     444                if (returnTypeOK)
     445                {
     446                    if (itemObject != null)
     447                    {
     448                        try
     449                        {
     450                            Object[] arguments = new Object[] {};
     451                            Object retobj = method
     452                            .invoke(itemObject, arguments);
     453                            if (retobj != null)
     454                            {
     455                                /*
     456                                    Return date values in "YYYY-MM-DD HH:mm:ss"
     457                                    24-hour format.
     458                                */
     459                                if (method.getReturnType().getName().equals(
     460                                "java.util.Date"))
     461                                {
     462                                    SimpleDateFormat dateFormat = Format.TIMESTAMP
     463                                    .getPattern();
     464                                    attrValueStr = dateFormat
     465                                    .format((Date) retobj);
     466                                }
     467                                else
     468                                {
     469                                    attrValueStr = retobj.toString();
     470                                }
     471                            }
     472                        }
     473                        catch (InvocationTargetException e)
     474                        {
     475                            log
     476                            .warn("FormFactory::getFormImpl(): InvocationTargetException when invoking method \"" + methodName + "\":" + e);
     477                        }
     478                        catch (IllegalAccessException e)
     479                        {
     480                            log
     481                            .warn("FormFactory::getFormImpl(): IllegalAccessException when invoking method \"" + methodName + "\":" + e);
     482                        }
     483                        log
     484                        .debug("FormFactory::getFormImpl(): methodName = \"" + methodName + "\"  returnTypeOfGetterMethod = \"" + returnTypeOfGetterMethod + "\" attrValueStr = \"" + attrValueStr + "\"");
     485                    }
     486                    /*
     487                        Check if public accessor method for setting value exists.
     488                    */
     489                    boolean isSettable = false;
     490                    String publMethodName = new String("set" + attrName);
     491                    if (!formTemplate.isReadOnlyForm())
     492                    {
     493                        if (fetchPublicMethodForObject(publMethodName,
     494                        itemClass) != null)
     495                        {
     496                            isSettable = true;
     497                        }
     498                    }
     499                    log
     500                    .debug("FormFactory::getFormImpl(): attrName = \"" + attrName + "\" publMethodName = \"" + publMethodName + "\" isSettable = " + isSettable);
     501                    /*
     502                        Use TextArea for Description, else TextField
     503                    */
     504                    if (attrName.equals("Description"))
     505                    {
     506                        /*
     507                            Value text area
     508                        */
     509                        TextArea valueF = null;
     510                        if (!isSettable)
     511                        {
     512                            valueF = newValueTextArea("", String.class);
     513                        }
     514                        else
     515                        {
     516                            hasSetterMethods = true;
     517                            valueF = newValueTextArea(publMethodName,
     518                            returnTypeOfGetterMethod);
     519                        }
     520                        mainFS.add(valueF);
     521                        valueF.setLabel(attrName);
     522                        valueF.setValue(attrValueStr);
     523                    }
     524                    else
     525                    {
     526                        /*
     527                            Value field
     528                        */
     529                        TextField<String> valueF = null;
     530                        if (!isSettable)
     531                        {
     532                            valueF = getFormFactory().newValueField("", String.class);
     533                        }
     534                        else
     535                        {
     536                            hasSetterMethods = true;
     537                            valueF = getFormFactory().newValueField(publMethodName,
     538                            returnTypeOfGetterMethod);
     539                        }
     540                        mainFS.add(valueF);
     541                        valueF.setLabel(attrName);
     542                        valueF.setValue(attrValueStr);
     543                    }
     544                }
     545            }
     546        }
     547                                               
     548        /*
     549            Check if object supports method getAnnotationSet().
     550        */
     551        Fieldset annotationFS = null;
     552        Method[] methodGeneralArr = new Method[0];
     553        if (itemClass != null)
     554        {
     555            methodGeneralArr = itemClass.getMethods();
     556        }
     557        for (int i = 0; i < methodGeneralArr.length; i++)
     558        {
     559            Method method = methodGeneralArr[i];
     560            // String modStr = methodModifierString(method);
     561            String methodName = method.getName();
     562            if (methodName.equals("getAnnotationSet"))
     563            {
     564                /***************************************************************
     565                    Annotation fieldset
     566                */
     567                annotationFS = new Fieldset();
     568                annotationFS.setTitle("Annotations");
     569                /*
     570                    Get DbControl
     571                */
     572                DbControl dc = getDbControlForObject(itemObject);
     573                /*
     574                    Fetch annotations
     575                */
     576                if (itemObject != null)
     577                {
     578                    try
     579                    {
     580                        Object[] arguments = new Object[] {};
     581                        Object retobj = method.invoke(itemObject, arguments);
     582                        AnnotationSet as = (AnnotationSet) retobj;
     583                        for (Annotation a : as.getAnnotations().list(dc))
     584                        {
     585                            /*
     586                                Only add annotations that contain something.
     587                            */
     588                            String value = joinAnnotationValues(a);
     589                            if (value != null && !value.equals(""))
     590                            {
     591                                /*
     592                                    Value (description) field - optional scroll
     593                                    bar
     594                                */
     595                                TextArea descrF = new DescriptionField();
     596                                descrF.setDisabled(true);
     597                                descrF
     598                                .setLabel(a.getAnnotationType().getName());
     599                                descrF.setValue(value);
     600                                annotationFS.add(descrF);
     601                            }
     602                        }
     603                    }
     604                    catch (InvocationTargetException e)
     605                    {
     606                        log
     607                        .warn("FormFactory::getFormImpl(): InvocationTargetException when invoking method \"" + methodName + "\":" + e);
     608                    }
     609                    catch (IllegalAccessException e)
     610                    {
     611                        log
     612                        .warn("FormFactory::getFormImpl(): IllegalAccessException when invoking method \"" + methodName + "\":" + e);
     613                    }
     614                }
     615            }
     616        }
     617        /***********************************************************************
     618            Form
     619        */
     620        String formName = new String("newForm");
     621        if (clsName != null && clsName.length() > 0)
     622        {
     623            formName = clsName.substring(0, 1).toLowerCase() + clsName
     624            .substring(1, clsName.length()) + "Form";
     625        }
     626        Form form = new Form(formName);
     627        form.setTitle(clsName);
     628        /***********************************************************************
     629            Add fieldsets to form
     630        */
     631        form.addFieldset(mainFS);
     632        if (annotationFS != null)
     633        {
     634            form.addFieldset(annotationFS);
     635        }
     636        /*
     637            Return generated form.
     638        */
     639        return form;
     640    }
     641       
     642    /**
     643        Get DbControl for object.
     644                                               
     645        @return DbControl for the object
     646    */
     647    public DbControl getDbControlForObject(Object itemObject)
     648    {
     649        /*
     650            Get class from itemObject.
     651        */
     652        Class<? extends Object> cls = null;
     653        if (itemObject != null)
     654        {
     655            cls = itemObject.getClass();
     656        }
     657        if (cls == null)
     658        {
     659            return null;
     660        }
     661        String clsName = cls.getSimpleName();
     662        /*
     663            Check if object supports method getDbControl().
     664        */
     665        DbControl dc = null;
     666        Method[] methodGeneralArr = cls.getMethods();
     667        for (int i = 0; i < methodGeneralArr.length; i++)
     668        {
     669            Method method = methodGeneralArr[i];
     670            String methodName = method.getName();
     671            if (methodName.equals("getDbControl"))
     672            {
     673                /*
     674                    Get DbControl for object
     675                */
     676                try
     677                {
     678                    Object[] arguments = new Object[] {};
     679                    Object retobj = method.invoke(itemObject, arguments);
     680                    dc = (DbControl) retobj;
     681                }
     682                catch (InvocationTargetException e)
     683                {
     684                    log
     685                    .warn("FormFactory::getDbControlForObject(): InvocationTargetException when invoking method \"" + methodName + "\":" + e);
     686                }
     687                catch (IllegalAccessException e)
     688                {
     689                    log
     690                    .warn("FormFactory::getDbControlForObject(): IllegalAccessException when invoking method \"" + methodName + "\":" + e);
     691                }
     692            }
     693        }
     694        /*
     695            Return DbControl.
     696        */
     697        return dc;
     698    }
     699                       
     700    /**
     701        @param a annotation
     702        @return String
     703    */
     704    private String joinAnnotationValues(Annotation a)
     705    {
     706        List<?> values = a.getValues();
     707        StringBuilder sb = new StringBuilder();
     708        for (Object o : values)
     709        sb.append(o);
     710        return sb.toString();
     711    }
     712                       
     713    /**
     714        Get list of excluded getter methods declared in current class.
     715                                               
     716        @return List<String> of excluded getter methods.
     717    */
     718    public List<String> getExcludedDeclMethods()
     719    {
     720        return this.excludedDeclMethods;
     721    }
     722                       
     723    /**
     724        Set list of excluded getter methods declared in current class.
     725                                               
     726        @param excludedDeclMethods List<String> of excluded getter methods to
     727        set.
     728    */
     729    public void setExcludedDeclMethods(List<String> excludedDeclMethods)
     730    {
     731        this.excludedDeclMethods = excludedDeclMethods;
     732    }
     733                       
     734    /**
     735        Add list of excluded getter methods declared in current class.
     736                                               
     737        @param excludedDeclMethods List<String> of excluded getter methods to to
     738        add.
     739    */
     740    public void addExcludedDeclMethods(List<String> excludedDeclMethods)
     741    {
     742        for (String exclMethod : excludedDeclMethods)
     743        {
     744            /*
     745                Add excluded method if not already in list.
     746            */
     747            if (!getExcludedDeclMethods().contains(exclMethod))
     748            {
     749                getExcludedDeclMethods().add(exclMethod);
     750            }
     751        }
     752    }
     753       
     754    /**
     755        Initializes list of excluded getter methods declared in current class.
     756    */
     757    public void initExcludedDeclMethods()
     758    {
     759        /*
     760            Initialize list of excluded declared methods.
     761        */
     762        getExcludedDeclMethods().add("getType");
     763        getExcludedDeclMethods().add("getQuery");
     764        getExcludedDeclMethods().add("getNew");
     765        getExcludedDeclMethods().add("getById");
     766        getExcludedDeclMethods().add("isUsed");
     767        getExcludedDeclMethods().add("isRemoved");
     768        getExcludedDeclMethods().add("getAnnotatableParents");
     769    }
     770             
     771    /**
     772        Fetch public method for object, or null if not found.
     773                                               
     774        @param publMethodName String Name of public method to search for.
     775        @return Method public method for object with desired name, or null if not
     776        found.
     777    */
     778    private Method fetchPublicMethodForObject(String publMethodName,
     779    Class<? extends Object> cls)
     780    {
     781        if (cls == null)
     782        {
     783            return null;
     784        }
     785        String clsName = cls.getSimpleName();
     786        /*
     787            Check if object supports public method with desired name.
     788        */
     789        Method publMethod = null;
     790        Method[] methodGeneralArr = cls.getMethods();
     791        for (int i = 0; i < methodGeneralArr.length; i++)
     792        {
     793            Method method = methodGeneralArr[i];
     794            String methodName = method.getName();
     795            if (methodName.equals(publMethodName))
     796            {
     797                /*
     798                    Check if method is public.
     799                */
     800                int methodMod = method.getModifiers();
     801                if (Modifier.isPublic(methodMod))
     802                {
     803                    publMethod = method;
     804                }
     805            }
     806        }
     807        return publMethod;
     808    }
     809                       
     810    /**
     811        Returns a String corresponding to the method modifier: "static",
     812        "public", "protected", or "private".
     813                                               
     814        @param method
     815        @return String for method modifier
     816    */
     817    private String methodModifierString(Method method)
     818    {
     819        String modStr = new String("");
     820        int methodMod = method.getModifiers();
     821        if (Modifier.isStatic(methodMod))
     822        {
     823            modStr = new String("static");
     824        }
     825        else if (Modifier.isPublic(methodMod))
     826        {
     827            modStr = new String("public");
     828        }
     829        else if (Modifier.isProtected(methodMod))
     830        {
     831            modStr = new String("protected");
     832        }
     833        else if (Modifier.isPrivate(methodMod))
     834        {
     835            modStr = new String("private");
     836        }
     837        return modStr;
     838    }
     839    private TextArea newValueTextArea(String setValueMethodName,
     840    Class<?> valueClass)
     841    {
     842        log
     843        .debug("FormFactory::newValueTextArea(): setValueMethodName = \"" + setValueMethodName + "\" valueClass.getSimpleName() = \"" + valueClass
     844        .getSimpleName() + "\"");
     845        String setValueMethodSignature = null;
     846        if (setValueMethodName != null && !setValueMethodName.equals(""))
     847        {
     848            /*
     849                Set valid parameter name to signature of single-argument setter
     850                method, if existing, in order to separate between arguments of
     851                primitive types like boolean, int, float, and double, from those
     852                of wrapper class types like Boolean, Integer, Float, and Double.
     853            */
     854            setValueMethodSignature = setValueMethodName + ":" + valueClass
     855            .getSimpleName();
     856            if (valueClass == String.class)
     857            {
     858                VString vSetterMethodParam = new VString(
     859                setValueMethodSignature, 0, 65535, false);
     860                TextArea valueF = new TextArea(vSetterMethodParam);
     861                valueF.setLabel("");
     862                valueF.setDisabled(false);
     863                return valueF;
     864            }
     865            VString vSetterMethodParam = new VString("null", 0, 65535, false);
     866            TextArea valueF = new TextArea(vSetterMethodParam);
     867            valueF.setLabel("");
     868            valueF.setDisabled(false);
     869            return valueF;
     870        }
     871        VString vSetterMethodParam = new VString("null", 0, 65535, false);
     872        TextArea valueF = new TextArea(vSetterMethodParam);
     873        valueF.setLabel("");
     874        valueF.setDisabled(true);
     875        return valueF;
     876    }
     877       
     878    private TextField<Boolean> newHiddenReadOnlyFormField()
     879    {
     880        TextField<Boolean> field = new TextField<Boolean>(VREADONLYFORM)
     881        .setHidden(true);
     882        return field;
     883    }
    237884}
  • trunk/client/servlet/src/org/proteios/gui/form/FormFactory.java

    r3939 r3941  
    11/*
    22    $Id$
    3                
     3                       
    44    Copyright (C) 2006, 2007 Fredrik Levander, Gregory Vincic, Olle Mansson
    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-2.x 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
     
    6868    private HttpServletRequest request = null;
    6969    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>();
     70       
    7771    private Localizer locale = null;
    7872    private String forwardActionId = null;
     
    124118    public static final VBoolean VISMICROTITREPLATE = new VBoolean("isMicrotitrePlate", false);
    125119    public static final VString VRANDOMSTRING = new VString("randomString", 1,15, true);
    126     public static final VBoolean VREADONLYFORM = new VBoolean("readOnlyForm",false);
    127120    public static final VBoolean VCONFIRM = new VBoolean("confirm", false);
    128121    public static final VString VCONFIRMMESSAGE = new VString("confirmMessage",0, 255, false);
     
    173166    private static final org.apache.log4j.Logger log = org.apache.log4j.LogManager
    174167    .getLogger("org.proteios.gui.form");
    175                
     168                       
    176169    /**
    177170        Default constructor. Initializes list excludedDeclMethods.
     
    182175            Initialize list excludedDeclMethods.
    183176        */
    184         initExcludedDeclMethods();
    185     }
    186177               
    187     /**
    188         Get list of excluded getter methods declared in current class.
    189                                
    190         @return List<String> of excluded getter methods.
    191     */
    192     public List<String> getExcludedDeclMethods()
    193     {
    194         return this.excludedDeclMethods;
    195     }
    196                
    197     /**
    198         Set list of excluded getter methods declared in current class.
    199                                
    200         @param excludedDeclMethods List<String> of excluded getter methods to
    201         set.
    202     */
    203     public void setExcludedDeclMethods(List<String> excludedDeclMethods)
    204     {
    205         this.excludedDeclMethods = excludedDeclMethods;
    206     }
    207                
    208     /**
    209         Add list of excluded getter methods declared in current class.
    210                                
    211         @param excludedDeclMethods List<String> of excluded getter methods to to
    212         add.
    213     */
    214     public void addExcludedDeclMethods(List<String> excludedDeclMethods)
    215     {
    216         for (String exclMethod : excludedDeclMethods)
    217         {
    218             /*
    219                 Add excluded method if not already in list.
    220             */
    221             if (!getExcludedDeclMethods().contains(exclMethod))
    222             {
    223                 getExcludedDeclMethods().add(exclMethod);
    224             }
    225         }
    226     }
    227                
     178    }
     179                       
    228180    public void setActionFactory(ActionFactory af)
    229181    {
    230182        this.actionFactory = af;
    231183    }
    232                
     184                       
    233185    public String getForwardActionId()
    234186    {
    235187        return this.forwardActionId;
    236188    }
    237                
     189                       
    238190    public void setForwardActionId(String forwardActionId)
    239191    {
    240192        this.forwardActionId = forwardActionId;
    241193    }
    242                
     194                       
    243195    public String getSortColumnKey()
    244196    {
    245197        return this.sortColumnKey;
    246198    }
    247                
     199                       
    248200    public void setSortColumnKey(String sortColumnKey)
    249201    {
    250202        this.sortColumnKey = sortColumnKey;
    251203    }
    252                
     204                       
    253205    public Integer getFilterListSize()
    254206    {
    255207        return this.filterListSize;
    256208    }
    257                
     209                       
    258210    public void setFilterListSize(Integer filterListSize)
    259211    {
    260212        this.filterListSize = filterListSize;
    261213    }
    262                
     214                       
    263215    public List<String> getFilterKeyColumnList()
    264216    {
    265217        return this.filterKeyColumnList;
    266218    }
    267                
     219                       
    268220    public void setFilterKeyColumnList(List<String> filterKeyColumnList)
    269221    {
    270222        this.filterKeyColumnList = filterKeyColumnList;
    271223    }
    272                
     224                       
    273225    public HashMap<String, String> getFilterClassColumnHashMap()
    274226    {
    275227        return this.filterClassColumnHashMap;
    276228    }
    277                
     229                       
    278230    public void setFilterClassColumnHashMap(
    279231    HashMap<String, String> filterClassColumnHashMap)
     
    281233        this.filterClassColumnHashMap = filterClassColumnHashMap;
    282234    }
    283                
     235                       
    284236    public HashMap<String, String> getFilterConditionColumnHashMap()
    285237    {
    286238        return this.filterConditionColumnHashMap;
    287239    }
    288                
     240                       
    289241    public void setFilterConditionColumnHashMap(
    290242    HashMap<String, String> filterConditionColumnHashMap)
     
    292244        this.filterConditionColumnHashMap = filterConditionColumnHashMap;
    293245    }
    294                
     246                       
    295247    public HashMap<String, String> getFilterValueColumnHashMap()
    296248    {
    297249        return this.filterValueColumnHashMap;
    298250    }
    299                
     251                       
    300252    public void setFilterValueColumnHashMap(
    301253    HashMap<String, String> filterValueColumnHashMap)
     
    303255        this.filterValueColumnHashMap = filterValueColumnHashMap;
    304256    }
    305                
    306     /**
    307         Initializes list of excluded getter methods declared in current class.
    308     */
    309     public void initExcludedDeclMethods()
    310     {
    311         /*
    312             Initialize list of excluded declared methods.
    313         */
    314         getExcludedDeclMethods().add("getType");
    315         getExcludedDeclMethods().add("getQuery");
    316         getExcludedDeclMethods().add("getNew");
    317         getExcludedDeclMethods().add("getById");
    318         getExcludedDeclMethods().add("isUsed");
    319         getExcludedDeclMethods().add("isRemoved");
    320         getExcludedDeclMethods().add("getAnnotatableParents");
    321     }
    322                
     257                       
    323258    public HttpServletRequest getRequest()
    324259    {
    325260        return request;
    326261    }
    327                
     262                       
    328263    public void setRequest(HttpServletRequest request)
    329264    {
    330265        this.request = request;
    331266    }
    332                
     267                       
    333268    public void modifyForPopup(Fieldset fs)
    334269    {
    335270        actionFactory.modifyForPopup(fs);
    336271    }
    337                
     272                       
    338273    private FileField newFileField()
    339274    {
     
    342277        return fileF;
    343278    }
    344                
     279                       
    345280    public TextField<Integer> newIdField()
    346281    {
     
    350285        return idF;
    351286    }
    352                
    353     private TextField<String> newValueField(String setValueMethodName,
     287                       
     288    public TextField<String> newValueField(String setValueMethodName,
    354289    Class<?> valueClass)
    355290    {
     
    382317        return valueF;
    383318    }
    384                
    385     private TextArea newValueTextArea(String setValueMethodName,
    386     Class<?> valueClass)
    387     {
    388         log
    389         .debug("FormFactory::newValueTextArea(): setValueMethodName = \"" + setValueMethodName + "\" valueClass.getSimpleName() = \"" + valueClass
    390         .getSimpleName() + "\"");
    391         String setValueMethodSignature = null;
    392         if (setValueMethodName != null && !setValueMethodName.equals(""))
    393         {
    394             /*
    395                 Set valid parameter name to signature of single-argument setter
    396                 method, if existing, in order to separate between arguments of
    397                 primitive types like boolean, int, float, and double, from those
    398                 of wrapper class types like Boolean, Integer, Float, and Double.
    399             */
    400             setValueMethodSignature = setValueMethodName + ":" + valueClass
    401             .getSimpleName();
    402             if (valueClass == String.class)
    403             {
    404                 VString vSetterMethodParam = new VString(
    405                 setValueMethodSignature, 0, 65535, false);
    406                 TextArea valueF = new TextArea(vSetterMethodParam);
    407                 valueF.setLabel("");
    408                 valueF.setDisabled(false);
    409                 return valueF;
    410             }
    411             VString vSetterMethodParam = new VString("null", 0, 65535, false);
    412             TextArea valueF = new TextArea(vSetterMethodParam);
    413             valueF.setLabel("");
    414             valueF.setDisabled(false);
    415             return valueF;
    416         }
    417         VString vSetterMethodParam = new VString("null", 0, 65535, false);
    418         TextArea valueF = new TextArea(vSetterMethodParam);
    419         valueF.setLabel("");
    420         valueF.setDisabled(true);
    421         return valueF;
    422     }
    423                
     319                       
    424320    public TextField<Integer> newHiddenItemIdField()
    425321    {
     
    427323        return field;
    428324    }
    429                
    430     private TextField<Boolean> newHiddenReadOnlyFormField()
    431     {
    432         TextField<Boolean> field = new TextField<Boolean>(VREADONLYFORM)
    433         .setHidden(true);
    434         return field;
    435     }
    436                
     325                       
    437326    private TextField<Integer> newHiddenIntegerField(VInteger vInteger)
    438327    {
     
    441330        return field;
    442331    }
    443                
     332                       
    444333    private TextField<String> newHiddenStringField(VString vString)
    445334    {
     
    448337        return field;
    449338    }
    450                
     339                       
    451340    public <D extends BasicItem<?>, E extends ProteiosAction<?>> Form getAnnotationsForm(
    452341    DbControl dc, D item, Class<E> forwardAction)
     
    498387        return form;
    499388    }
    500                
     389                       
    501390    /**
    502391        @return Hidden
     
    508397        return field;
    509398    }
    510                
     399                       
    511400    /**
    512401        Form for user preferences configuration settings. Arguments
     
    514403        holders for current values for the notification configuration and table
    515404        preferences configuration form fields.
    516                                
     405                                               
    517406        @param nc NotificationConfiguration object (need not be stored in
    518407        database) with default field values.
     
    532421        return form;
    533422    }
    534                
     423                       
    535424    /**
    536425        Fieldset for notification configuration settings. Argument
    537426        NotificationConfiguration is place holder for current values for the
    538427        notification configuration form fields.
    539                                
     428                                               
    540429        @param nc NotificationConfiguration object (need not be stored in
    541430        database) with default field values.
     
    589478        return properties;
    590479    }
    591                
     480                       
    592481    /**
    593482        Creates a select box for notification mode.
    594                                
     483                                               
    595484        @param modeValue int Mode value for default selection.
    596485        @return Select<VInteger> Select box for notification mode selection
     
    617506        return modeS;
    618507    }
    619                
     508                       
    620509    /**
    621510        Fieldset for table preferences configuration settings. Argument
    622511        TablePreferencesConfiguration is place holder for current values for the
    623512        table preferences configuration form fields.
    624                                
     513                                               
    625514        @param tpc TablePreferencesConfiguration object (need not be stored in
    626515        database) with default field values.
     
    652541        return properties;
    653542    }
    654                
     543                       
    655544    /**
    656545        Creates a select box for table preferences mode.
    657                                
     546                                               
    658547        @param modeValue int Mode value for default selection.
    659548        @return Select<VInteger> Select box for table preferences mode selection
     
    680569        return modeS;
    681570    }
    682                
     571                       
     572    /**
     573        @param a annotation
     574        @return String
     575    */
     576    private String joinAnnotationValues(Annotation a)
     577    {
     578        List<?> values = a.getValues();
     579        StringBuilder sb = new StringBuilder();
     580        for (Object o : values)
     581        sb.append(o);
     582        return sb.toString();
     583    }
     584       
    683585    /**
    684586        This will probably be removed when fixint #691
     
    779681        return form;
    780682    }
    781                
     683                       
    782684    /**
    783685        @param hit Current Hit
     
    995897        return form;
    996898    }
    997                
    998     /**
    999         @param a annotation
    1000         @return String
    1001     */
    1002     private String joinAnnotationValues(Annotation a)
    1003     {
    1004         List<?> values = a.getValues();
    1005         StringBuilder sb = new StringBuilder();
    1006         for (Object o : values)
    1007         sb.append(o);
    1008         return sb.toString();
    1009     }
    1010                
     899                       
    1011900    /**
    1012901        Returns a form for selecting spectrum mass range limits.
    1013                                
     902                                               
    1014903        @param massCutoffLow String The lower cutoff mass value.
    1015904        @param massCutoffHigh String The upper cutoff mass value.
     
    1057946        return form;
    1058947    }
    1059                
     948                       
    1060949    /**
    1061950        Returns a form with spectrum properties for a spectrum obtained from a
    1062951        spectrum file.
    1063                                
     952                                               
    1064953        @param spectrumFile File Core file with spectrum.
    1065954        @param spectrumId String Spectrum id string.
     
    12701159        return form;
    12711160    }
    1272                
     1161                       
    12731162    /**
    12741163        Returns a form with spectrum file instrument data for a spectrum file.
    1275                                
     1164                                               
    12761165        @param spectrumFileInstrumentList List<SpectrumFileInstrumentInterface>
    12771166        Spectrum file instrument list.
     
    14581347        return form;
    14591348    }
    1460                
     1349                       
    14611350    /**
    14621351        Adds a table row to a table. A "value" argument that is null will be
    14631352        represented as an empty string, otherwise by its toString() value.
    1464                                
     1353                                               
    14651354        @param table Table The table to add a row to.
    14661355        @param nameKey String Property key string.
     
    14991388        table.addRow(row);
    15001389    }
    1501                
     1390                       
    15021391    /**
    15031392        Returns a form with spectrum file contact data for a spectrum file.
    1504                                
     1393                                               
    15051394        @param spectrumContact Spectrum file contact
    15061395        data.
     
    15851474        return form;
    15861475    }
    1587                    
     1476                           
    15881477    /**
    15891478        Returns a form for adding spectrum file sample data for a spectrum file.
    1590                                
     1479                                               
    15911480        @param project Project The project in whose directory a new output
    15921481        directory is created.
     
    16781567        return form;
    16791568    }
    1680                
     1569                       
    16811570    private <D extends Object> TextField<D> newTextField(String name, D value)
    16821571    {
     
    16871576        return field;
    16881577    }
    1689                
     1578                       
    16901579    public Form getPeakListSetForm(PeakListSet pls)
    16911580    {
     
    17551644        return form;
    17561645    }
    1757                
     1646                       
    17581647    public Form getExportPeakListSetForm(PeakListSet pls)
    17591648    {
     
    18021691        return form;
    18031692    }
    1804                
     1693                       
    18051694    private void addAnnotationsAsFields(Fieldset to, Annotatable item,
    18061695    DbControl dc)
     
    18171706        }
    18181707    }
    1819                
     1708                       
    18201709    public Fieldset getProteinAssemblyFieldset(Project project)
    18211710    {
     
    18401729        return properties;
    18411730    }
    1842                
     1731                       
    18431732    public Select<VString> selectLocalSampleIdWithAllOption(DbControl dc,
    18441733    Project project)
     
    18541743        return select;
    18551744    }
    1856                
     1745                       
    18571746    private Select<VInteger> newSelectLabel(LabeledExtract le, DbControl dc)
    18581747    {
     
    18751764        return select;
    18761765    }
    1877                
     1766                       
    18781767    /**
    18791768        Creates and adds a hidden field with an Integer value to the given form.
     
    18871776        form.getFieldsets().get(0).add(field);
    18881777    }
    1889                
     1778                       
    18901779    /**
    18911780        Creates and adds a hidden field with an Integer value to the given table.
     
    18991788        table.add(field);
    19001789    }
    1901                
     1790                       
    19021791    public Fieldset getUsedSampleFieldset(Sample sample)
    19031792    {
     
    19171806        return fs;
    19181807    }
    1919                
     1808                       
    19201809    public Fieldset getUsedExtractFieldset(Extract extract)
    19211810    {
     
    19321821        return fs;
    19331822    }
    1934                
     1823                       
    19351824    public Fieldset getUsedLabeledExtractFieldset(LabeledExtract extract)
    19361825    {
     
    19501839        return fs;
    19511840    }
    1952                
     1841                       
    19531842    public Form getSecondaryLabeledExtractForm(LabeledExtract extract,
    19541843    DbControl dc, LabeledExtract fromExtract)
     
    20131902        return form;
    20141903    }
    2015                
     1904                       
    20161905    public Form getSetFilterForm(String filterName, String filterClass,
    20171906    String filterCondition, String filterValue)
     
    21071996        return form;
    21081997    }
    2109                
     1998                       
    21101999    private void addFilterSettingsToFieldset(Fieldset fs)
    21112000    {
     
    21712060        }
    21722061    }
    2173                
     2062                       
    21742063    public TextField<Float> newOriginalQuantityField()
    21752064    {
     
    21792068        return field;
    21802069    }
    2181                
     2070                       
    21822071    public TextField<Float> newRemainingQuantityField(Float remainingQuantity)
    21832072    {
     
    21902079        return field;
    21912080    }
    2192                
    2193     /**
    2194         Get generic form for object.
    2195                                
    2196         @param template template for generic form
    2197         @return Form for editing the object
    2198     */
    2199     public Form getForm(FormTemplateInterface formTemplate)
    2200     {
    2201         /***********************************************************************
    2202             Analyze object class
    2203         */
    2204                                
    2205         /*
    2206             Get class from formTemplate itemObject or itemClass.
    2207         */
    2208         Object itemObject = null;
    2209         Class<? extends Object> itemClass = null;
    2210         if (formTemplate.getItemObject() != null)
    2211         {
    2212             itemObject = formTemplate.getItemObject();
    2213             itemClass = itemObject.getClass();
    2214         }
    2215         else if (formTemplate.getItemClass() != null)
    2216         {
    2217             itemClass = formTemplate.getItemClass();
    2218         }
    2219         /*
    2220             Add optional extra formTemplate list of methods to be excluded.
    2221         */
    2222         if (formTemplate != null && formTemplate.getExcludedDeclMethods() != null)
    2223         {
    2224             addExcludedDeclMethods(formTemplate.getExcludedDeclMethods());
    2225         }
    2226         String clsName = new String("");
    2227         if (itemClass != null)
    2228         {
    2229             clsName = itemClass.getSimpleName();
    2230         }
    2231                                
    2232         /***********************************************************************
    2233             Main fieldset
    2234         */
    2235         Fieldset mainFS = new Fieldset();
    2236         String mainFsName = new String("Properties");
    2237         mainFS.setTitle(mainFsName);
    2238         /*
    2239             Add forward actionId field as first field, for external use.
    2240         */
    2241         TextField<String> fwdactionF = new ForwardField();
    2242         mainFS.add(fwdactionF);
    2243         /*
    2244             Get item id, if any.
    2245         */
    2246         int itemId = 0;
    2247         String getIdMethodName = "getId";
    2248         Method getIdMethod = fetchPublicMethodForObject(getIdMethodName,
    2249         itemClass);
    2250         if (getIdMethod != null && itemObject != null)
    2251         {
    2252             try
    2253             {
    2254                 Object[] arguments = new Object[] {};
    2255                 Object retobj = getIdMethod.invoke(itemObject, arguments);
    2256                 String idStr = retobj.toString();
    2257                 itemId = Integer.parseInt(idStr);
    2258             }
    2259             catch (InvocationTargetException e)
    2260             {
    2261                 itemId = 0;
    2262             }
    2263             catch (IllegalAccessException e)
    2264             {
    2265                 itemId = 0;
    2266             }
    2267             catch (java.lang.NumberFormatException e)
    2268             {
    2269                 itemId = 0;
    2270             }
    2271         }
    2272         /*
    2273             Add itemId field idF (hidden) if itemId value ok.
    2274         */
    2275         if (itemId > 0)
    2276         {
    2277             TextField<Integer> idF = newHiddenItemIdField();
    2278             mainFS.add(idF);
    2279             idF.setLabel("ItemId");
    2280             idF.setValue(itemId);
    2281             idF.setDisabled(true);
    2282         }
    2283         /*
    2284             Add class name field cnF.
    2285         */
    2286         String classNameFull = new String("");
    2287         if (itemClass != null)
    2288         {
    2289             classNameFull = itemClass.getName();
    2290         }
    2291         TextField<String> cnF = new ClassNameField();
    2292         mainFS.add(cnF);
    2293         cnF.setHidden(true);
    2294         cnF.setLabel("ClassName");
    2295         cnF.setValue(classNameFull);
    2296         cnF.setDisabled(true);
    2297         /*
    2298             Add readOnlyForm field rofF (hidden).
    2299         */
    2300         TextField<Boolean> rofF = newHiddenReadOnlyFormField();
    2301         mainFS.add(rofF);
    2302         rofF.setLabel("ReadOnlyForm");
    2303         rofF.setValue(formTemplate.isReadOnlyForm());
    2304         rofF.setDisabled(true);
    2305         /*
    2306             Keep track on whether public setter methods exist, in order to know
    2307             if a "Save" button should be added.
    2308         */
    2309         boolean hasSetterMethods = false;
    2310         /*
    2311             Methods, declared and inherited
    2312         */
    2313         Method[] methodArr = new Method[0];
    2314         if (itemClass != null)
    2315         {
    2316             methodArr = itemClass.getMethods();
    2317         }
    2318                                
    2319         /*
    2320             Methods declared in object class (not inherited)
    2321         */
    2322         Method[] declaredMethodArr = new Method[0];
    2323         if (itemClass != null)
    2324         {
    2325             declaredMethodArr = itemClass.getDeclaredMethods();
    2326         }
    2327         for (int i = 0; i < declaredMethodArr.length; i++)
    2328         {
    2329             Method method = declaredMethodArr[i];
    2330             String modStr = methodModifierString(method);
    2331             String methodName = method.getName();
    2332             String methodReturnType = method.getReturnType().getName();
    2333             /*
    2334                 Only process declared methods not in exclude list.
    2335             */
    2336             if (!getExcludedDeclMethods().contains(methodName))
    2337             {
    2338                 String attrName = new String("");
    2339                 String attrValueStr = new String("");
    2340                 String returnTypeStr = new String("");
    2341                 boolean returnTypeOK = false;
    2342                 Class<?> returnTypeOfGetterMethod = null;
    2343                 /*
    2344                     Check if getter access method.
    2345                 */
    2346                 if (methodName.startsWith("get"))
    2347                 {
    2348                     /*
    2349                         Assume that attribute name can optained by skipping "get"
    2350                         in method name.
    2351                     */
    2352                     attrName = methodName.substring(3);
    2353                     // int methodMod = declaredMethodArr[i].getModifiers();
    2354                     if (method.getReturnType().getName().equals("int") || method
    2355                     .getReturnType().getName().equals("java.lang.Integer") || method
    2356                     .getReturnType().getName().equals("float") || method
    2357                     .getReturnType().getName().equals("java.lang.Float") || method
    2358                     .getReturnType().getName().equals("double") || method
    2359                     .getReturnType().getName().equals("java.lang.Double") || method
    2360                     .getReturnType().getName().equals("java.lang.String") || method
    2361                     .getReturnType().getName().equals("java.util.Date"))
    2362                     {
    2363                         returnTypeOfGetterMethod = method.getReturnType();
    2364                         returnTypeStr = method.getReturnType().getName();
    2365                         returnTypeOK = true;
    2366                     }
    2367                 }
    2368                 else if (methodName.startsWith("is"))
    2369                 {
    2370                     /*
    2371                         Assume that attribute name can optained by skipping "is"
    2372                         in method name.
    2373                     */
    2374                     attrName = methodName.substring(2);
    2375                     // int methodMod = declaredMethodArr[i].getModifiers();
    2376                     if (method.getReturnType().getName().equals("boolean") || method
    2377                     .getReturnType().getName().equals("java.lang.Boolean"))
    2378                     {
    2379                         returnTypeOfGetterMethod = method.getReturnType();
    2380                         returnTypeStr = method.getReturnType().getName();
    2381                         returnTypeOK = true;
    2382                     }
    2383                 }
    2384                 if (returnTypeOK)
    2385                 {
    2386                     if (itemObject != null)
    2387                     {
    2388                         try
    2389                         {
    2390                             Object[] arguments = new Object[] {};
    2391                             Object retobj = method
    2392                             .invoke(itemObject, arguments);
    2393                             if (retobj != null)
    2394                             {
    2395                                 /*
    2396                                     Return date values in "YYYY-MM-DD HH:mm:ss"
    2397                                     24-hour format.
    2398                                 */
    2399                                 if (method.getReturnType().getName().equals(
    2400                                 "java.util.Date"))
    2401                                 {
    2402                                     SimpleDateFormat dateFormat = Format.TIMESTAMP
    2403                                     .getPattern();
    2404                                     attrValueStr = dateFormat
    2405                                     .format((Date) retobj);
    2406                                 }
    2407                                 else
    2408                                 {
    2409                                     attrValueStr = retobj.toString();
    2410                                 }
    2411                             }
    2412                         }
    2413                         catch (InvocationTargetException e)
    2414                         {
    2415                             log
    2416                             .warn("FormFactory::getFormImpl(): InvocationTargetException when invoking method \"" + methodName + "\":" + e);
    2417                         }
    2418                         catch (IllegalAccessException e)
    2419                         {
    2420                             log
    2421                             .warn("FormFactory::getFormImpl(): IllegalAccessException when invoking method \"" + methodName + "\":" + e);
    2422                         }
    2423                         log
    2424                         .debug("FormFactory::getFormImpl(): methodName = \"" + methodName + "\"  returnTypeOfGetterMethod = \"" + returnTypeOfGetterMethod + "\" attrValueStr = \"" + attrValueStr + "\"");
    2425                     }
    2426                     /*
    2427                         Check if public accessor method for setting value exists.
    2428                     */
    2429                     boolean isSettable = false;
    2430                     String publMethodName = new String("set" + attrName);
    2431                     if (!formTemplate.isReadOnlyForm())
    2432                     {
    2433                         if (fetchPublicMethodForObject(publMethodName,
    2434                         itemClass) != null)
    2435                         {
    2436                             isSettable = true;
    2437                         }
    2438                     }
    2439                     log
    2440                     .debug("FormFactory::getFormImpl(): attrName = \"" + attrName + "\" publMethodName = \"" + publMethodName + "\" isSettable = " + isSettable);
    2441                     /*
    2442                         Use TextArea for Description, else TextField
    2443                     */
    2444                     if (attrName.equals("Description"))
    2445                     {
    2446                         /*
    2447                             Value text area
    2448                         */
    2449                         TextArea valueF = null;
    2450                         if (!isSettable)
    2451                         {
    2452                             valueF = newValueTextArea("", String.class);
    2453                         }
    2454                         else
    2455                         {
    2456                             hasSetterMethods = true;
    2457                             valueF = newValueTextArea(publMethodName,
    2458                             returnTypeOfGetterMethod);
    2459                         }
    2460                         mainFS.add(valueF);
    2461                         valueF.setLabel(attrName);
    2462                         valueF.setValue(attrValueStr);
    2463                     }
    2464                     else
    2465                     {
    2466                         /*
    2467                             Value field
    2468                         */
    2469                         TextField<String> valueF = null;
    2470                         if (!isSettable)
    2471                         {
    2472                             valueF = newValueField("", String.class);
    2473                         }
    2474                         else
    2475                         {
    2476                             hasSetterMethods = true;
    2477                             valueF = newValueField(publMethodName,
    2478                             returnTypeOfGetterMethod);
    2479                         }
    2480                         mainFS.add(valueF);
    2481                         valueF.setLabel(attrName);
    2482                         valueF.setValue(attrValueStr);
    2483                     }
    2484                 }
    2485             }
    2486         }
    2487                                
    2488         /*
    2489             Check if object supports method getAnnotationSet().
    2490         */
    2491         Fieldset annotationFS = null;
    2492         Method[] methodGeneralArr = new Method[0];
    2493         if (itemClass != null)
    2494         {
    2495             methodGeneralArr = itemClass.getMethods();
    2496         }
    2497         for (int i = 0; i < methodGeneralArr.length; i++)
    2498         {
    2499             Method method = methodGeneralArr[i];
    2500             // String modStr = methodModifierString(method);
    2501             String methodName = method.getName();
    2502             if (methodName.equals("getAnnotationSet"))
    2503             {
    2504                 /***************************************************************
    2505                     Annotation fieldset
    2506                 */
    2507                 annotationFS = new Fieldset();
    2508                 annotationFS.setTitle("Annotations");
    2509                 /*
    2510                     Get DbControl
    2511                 */
    2512                 DbControl dc = getDbControlForObject(itemObject);
    2513                 /*
    2514                     Fetch annotations
    2515                 */
    2516                 if (itemObject != null)
    2517                 {
    2518                     try
    2519                     {
    2520                         Object[] arguments = new Object[] {};
    2521                         Object retobj = method.invoke(itemObject, arguments);
    2522                         AnnotationSet as = (AnnotationSet) retobj;
    2523                         for (Annotation a : as.getAnnotations().list(dc))
    2524                         {
    2525                             /*
    2526                                 Only add annotations that contain something.
    2527                             */
    2528                             String value = joinAnnotationValues(a);
    2529                             if (value != null && !value.equals(""))
    2530                             {
    2531                                 /*
    2532                                     Value (description) field - optional scroll
    2533                                     bar
    2534                                 */
    2535                                 TextArea descrF = new DescriptionField();
    2536                                 descrF.setDisabled(true);
    2537                                 descrF
    2538                                 .setLabel(a.getAnnotationType().getName());
    2539                                 descrF.setValue(value);
    2540                                 annotationFS.add(descrF);
    2541                             }
    2542                         }
    2543                     }
    2544                     catch (InvocationTargetException e)
    2545                     {
    2546                         log
    2547                         .warn("FormFactory::getFormImpl(): InvocationTargetException when invoking method \"" + methodName + "\":" + e);
    2548                     }
    2549                     catch (IllegalAccessException e)
    2550                     {
    2551                         log
    2552                         .warn("FormFactory::getFormImpl(): IllegalAccessException when invoking method \"" + methodName + "\":" + e);
    2553                     }
    2554                 }
    2555             }
    2556         }
    2557         /***********************************************************************
    2558             Form
    2559         */
    2560         String formName = new String("newForm");
    2561         if (clsName != null && clsName.length() > 0)
    2562         {
    2563             formName = clsName.substring(0, 1).toLowerCase() + clsName
    2564             .substring(1, clsName.length()) + "Form";
    2565         }
    2566         Form form = new Form(formName);
    2567         form.setTitle(clsName);
    2568         /***********************************************************************
    2569             Add fieldsets to form
    2570         */
    2571         form.addFieldset(mainFS);
    2572         if (annotationFS != null)
    2573         {
    2574             form.addFieldset(annotationFS);
    2575         }
    2576         /*
    2577             Return generated form.
    2578         */
    2579         return form;
    2580     }
    2581                
    2582     /**
    2583         Get DbControl for object.
    2584                                
    2585         @return DbControl for the object
    2586     */
    2587     public DbControl getDbControlForObject(Object itemObject)
    2588     {
    2589         /*
    2590             Get class from itemObject.
    2591         */
    2592         Class<? extends Object> cls = null;
    2593         if (itemObject != null)
    2594         {
    2595             cls = itemObject.getClass();
    2596         }
    2597         if (cls == null)
    2598         {
    2599             return null;
    2600         }
    2601         String clsName = cls.getSimpleName();
    2602         /*
    2603             Check if object supports method getDbControl().
    2604         */
    2605         DbControl dc = null;
    2606         Method[] methodGeneralArr = cls.getMethods();
    2607         for (int i = 0; i < methodGeneralArr.length; i++)
    2608         {
    2609             Method method = methodGeneralArr[i];
    2610             String methodName = method.getName();
    2611             if (methodName.equals("getDbControl"))
    2612             {
    2613                 /*
    2614                     Get DbControl for object
    2615                 */
    2616                 try
    2617                 {
    2618                     Object[] arguments = new Object[] {};
    2619                     Object retobj = method.invoke(itemObject, arguments);
    2620                     dc = (DbControl) retobj;
    2621                 }
    2622                 catch (InvocationTargetException e)
    2623                 {
    2624                     log
    2625                     .warn("FormFactory::getDbControlForObject(): InvocationTargetException when invoking method \"" + methodName + "\":" + e);
    2626                 }
    2627                 catch (IllegalAccessException e)
    2628                 {
    2629                     log
    2630                     .warn("FormFactory::getDbControlForObject(): IllegalAccessException when invoking method \"" + methodName + "\":" + e);
    2631                 }
    2632             }
    2633         }
    2634         /*
    2635             Return DbControl.
    2636         */
    2637         return dc;
    2638     }
    2639                
    2640     /**
    2641         Fetch public method for object, or null if not found.
    2642                                
    2643         @param publMethodName String Name of public method to search for.
    2644         @return Method public method for object with desired name, or null if not
    2645         found.
    2646     */
    2647     private Method fetchPublicMethodForObject(String publMethodName,
    2648     Class<? extends Object> cls)
    2649     {
    2650         if (cls == null)
    2651         {
    2652             return null;
    2653         }
    2654         String clsName = cls.getSimpleName();
    2655         /*
    2656             Check if object supports public method with desired name.
    2657         */
    2658         Method publMethod = null;
    2659         Method[] methodGeneralArr = cls.getMethods();
    2660         for (int i = 0; i < methodGeneralArr.length; i++)
    2661         {
    2662             Method method = methodGeneralArr[i];
    2663             String methodName = method.getName();
    2664             if (methodName.equals(publMethodName))
    2665             {
    2666                 /*
    2667                     Check if method is public.
    2668                 */
    2669                 int methodMod = method.getModifiers();
    2670                 if (Modifier.isPublic(methodMod))
    2671                 {
    2672                     publMethod = method;
    2673                 }
    2674             }
    2675         }
    2676         return publMethod;
    2677     }
    2678                
    2679     /**
    2680         Returns a String corresponding to the method modifier: "static",
    2681         "public", "protected", or "private".
    2682                                
    2683         @param method
    2684         @return String for method modifier
    2685     */
    2686     private String methodModifierString(Method method)
    2687     {
    2688         String modStr = new String("");
    2689         int methodMod = method.getModifiers();
    2690         if (Modifier.isStatic(methodMod))
    2691         {
    2692             modStr = new String("static");
    2693         }
    2694         else if (Modifier.isPublic(methodMod))
    2695         {
    2696             modStr = new String("public");
    2697         }
    2698         else if (Modifier.isProtected(methodMod))
    2699         {
    2700             modStr = new String("protected");
    2701         }
    2702         else if (Modifier.isPrivate(methodMod))
    2703         {
    2704             modStr = new String("private");
    2705         }
    2706         return modStr;
    2707     }
    2708                
     2081                       
    27092082    private Localizer getLocale()
    27102083    {
    27112084        return locale;
    27122085    }
    2713                
     2086                       
    27142087    public void setLocale(Localizer locale)
    27152088    {
    27162089        this.locale = locale;
    27172090    }
    2718                
     2091                       
    27192092    //Cleaning up from here       
    2720            
     2093                   
    27212094    /**
    27222095        Form for new Protocol item. The difference between calling
     
    27292102        a convenient place holder for default values for the Protocol form
    27302103        fields.
    2731                                
     2104                                               
    27322105        @param protocol Protocol object (need not be stored in database) with
    27332106        default field values.
     
    28142187        return form;
    28152188    }
    2816                
     2189                       
    28172190    public Form getForm(Class<?> cls)
    28182191    {
     
    29042277            loginF.setDisabled(true);
    29052278            fs.add(fs.size()-2, loginF); // After the itemId field
    2906                                    
     2279                                                           
    29072280            TextField<String> emailF = new EmailField();
    29082281            fs.add(fs.size()-1, emailF);
    2909                                                
     2282                                                                       
    29102283            TextField<String> phoneF = new PhoneField();
    29112284            fs.add(phoneF);
    2912                                                
     2285                                                                       
    29132286            TextField<String> addressF = new AddressField();
    29142287            fs.add(addressF);
    2915                                                
     2288                                                                       
    29162289            TextField<String> organisationF = new OrganisationField();
    29172290            fs.add(organisationF);
    2918                                                
     2291                                                                       
    29192292            if (obj != null)
    29202293            {
     
    32472620        return form;
    32482621    }
    3249                
     2622                       
    32502623    /**
    32512624        Creates a select box for protocols. If the class for which the protocol
     
    32552628        if the protocol is tagged to be removed. However, no other protocols
    32562629        tagged to be removed should be included in the list.
    3257                                
     2630                                               
    32582631        @param cls Class Class for which a protocol should be selected.
    32592632        @param obj Object Optional object with attached protocol for setting
     
    33622735        return protocolS;
    33632736    }
    3364                
     2737                       
    33652738    public void setSc(SessionControl sc)
    33662739    {
Note: See TracChangeset for help on using the changeset viewer.