Changeset 3945


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

Refs #698. Moved method getSpectrumFileInstrumentForm from FormFactory to InspectActiveSpectrumFile, also introducing PropertyRow.

Location:
trunk/client/servlet/src/org/proteios
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/client/servlet/src/org/proteios/action/file/InspectActiveSpectrumFile.java

    r3842 r3945  
    11/*
    2  $Id$
    3  
    4  Copyright (C) 2009 Gregory Vincic
    5 
    6  This file is part of Proteios.
    7  Available at http://www.proteios.org/
    8 
    9  Proteios is free software; you can redistribute it and/or modify it
    10  under the terms of the GNU General Public License as published by
    11  the Free Software Foundation; either version 2 of the License, or
    12  (at your option) any later version.
    13 
    14  Proteios is distributed in the hope that it will be useful, but
    15  WITHOUT ANY WARRANTY; without even the implied warranty of
    16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    17  General Public License for more details.
    18 
    19  You should have received a copy of the GNU General Public License
    20  along with this program; if not, write to the Free Software
    21  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    22  02111-1307, USA.
    23  */
     2    $Id$
     3                
     4    Copyright (C) 2009 Gregory Vincic
     5               
     6    This file is part of Proteios.
     7    Available at http://www.proteios.org/
     8               
     9    Proteios is free software; you can redistribute it and/or modify it
     10    under the terms of the GNU General Public License as published by
     11    the Free Software Foundation; either version 2 of the License, or
     12    (at your option) any later version.
     13               
     14    Proteios is distributed in the hope that it will be useful, but
     15    WITHOUT ANY WARRANTY; without even the implied warranty of
     16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     17    General Public License for more details.
     18               
     19    You should have received a copy of the GNU General Public License
     20    along with this program; if not, write to the Free Software
     21    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
     22    02111-1307, USA.
     23*/
    2424package org.proteios.action.file;
    2525
     26import java.util.ArrayList;
     27import java.util.List;
    2628import org.proteios.ActionLink;
    2729import org.proteios.action.ProteiosAction;
     
    4547import org.proteios.gui.table.Cell;
    4648import org.proteios.gui.table.Column;
     49import org.proteios.gui.table.PropertyRow;
    4750import org.proteios.gui.table.Row;
    4851import org.proteios.gui.table.Table;
    4952import org.proteios.io.MgfFileReader;
    5053import org.proteios.io.PeakListFileInterface;
     54import org.proteios.io.SpectrumFileAnalyzerInterface;
    5155import org.proteios.io.SpectrumFileContactInterface;
    5256import org.proteios.io.SpectrumFileContactReaderInterface;
     
    5559import org.proteios.io.SpectrumIdReaderInterface;
    5660import org.proteios.io.SpectrumInterface;
    57 
     61import org.proteios.io.StringPairInterface;
    5862import se.lu.thep.waf.ActionException;
    5963import se.lu.thep.waf.constraints.InvalidParameterValue;
     
    6165import se.lu.thep.waf.constraints.VInteger;
    6266
    63 import java.util.ArrayList;
    64 import java.util.List;
    65 
    6667/**
    67  * This action presents a form with a table of spectrum id values in a selected
    68  * spectrum file, together with a spectrum corresponding to the first spectrum
    69  * id value. The user may click on another spectrum id in the table to show that
    70  * spectrum.
    71  *
    72  * @author olle
    73  */
     68    * This action presents a form with a table of spectrum id values in a selected
     69    * spectrum file, together with a spectrum corresponding to the first spectrum
     70    * id value. The user may click on another spectrum id in the table to show that
     71    * spectrum.
     72    *
     73    * @author olle
     74*/
    7475public class InspectActiveSpectrumFile
    75     extends ProteiosAction<InspectActiveSpectrumFile>
     76extends ProteiosAction<InspectActiveSpectrumFile>
    7677{
    77   public static final VInteger VSPECTRUMFILEID = new VInteger(
    78     "spectrumFileId", 0, false);
    79   public static final VBoolean VKEEPORIGINALSPECTRUM = new VBoolean(
    80     "keepOriginalSpectrum", false);
    81   public static final VBoolean VFIRSTMGFTITLESPECTRUM = new VBoolean(
    82     "firstMGF", false);
    83   private int maxResults = 20;
    84   private int itemsFrom = 0;
    85   private boolean pageSelectedFromScroller = false;
    86 
    87 
    88   /**
    89    * Get the max number of results to show in list.
    90    *
    91    * @return int The max number of results to show in list.
    92    */
    93   public int getMaxResults()
    94   {
    95     return this.maxResults;
    96   }
    97 
    98 
    99   /**
    100    * Set the max number of results to show in list.
    101    *
    102    * @param maxResults int The value to set for the max number of results to
    103    *        show in list.
    104    */
    105   public void setMaxResults(int maxResults)
    106   {
    107     this.maxResults = maxResults;
    108   }
    109 
    110 
    111   /**
    112    * Get the item number to start from in the list.
    113    *
    114    * @return int The item number to start from in the list.
    115    */
    116   public int getItemsFrom()
    117   {
    118     return this.itemsFrom;
    119   }
    120 
    121 
    122   /**
    123    * Set the item number to start from in the list.
    124    *
    125    * @param itemsFrom int The value to set for the item number to start from
    126    *        in the list.
    127    */
    128   public void setItemsFrom(int itemsFrom)
    129   {
    130     this.itemsFrom = itemsFrom;
    131   }
    132 
    133 
    134   /**
    135    * Get flag indicating that page is selected from scroller.
    136    *
    137    * @return boolean The flag indicating that page is selected from scroller.
    138    */
    139   public boolean isPageSelectedFromScroller()
    140   {
    141     return this.pageSelectedFromScroller;
    142   }
    143 
    144 
    145   /**
    146    * Set flag indicating that page is selected from scroller.
    147    *
    148    * @param pageSelectedFromScroller boolean The value to set for flag
    149    *        indicating that page is selected from scroller.
    150    */
    151   public void setPageSelectedFromScroller(boolean pageSelectedFromScroller)
    152   {
    153     this.pageSelectedFromScroller = pageSelectedFromScroller;
    154   }
    155 
    156 
    157   @Override
    158   protected void runMe()
    159       throws ActionException, InvalidParameterValue
    160   {
    161     /*
    162      * Get the id's of all selected files. VSPECTRUMFILEID is the valid
    163      * identifier used when rendering the list of files, thus we use it to
    164      * get the valid list of item id values.
    165      */
    166     List<Integer> files = getValidIntegerList(VSPECTRUMFILEID);
    167     log.debug("(1) files = " + files);
    168     // Check alternative input
    169     if (files == null)
    170     {
    171       Integer fileIdFromSessionAttribute = getSessionAttribute(VSPECTRUMFILEID);
    172       log
    173         .debug("fileIdFromSessionAttribute = " + fileIdFromSessionAttribute);
    174       if (fileIdFromSessionAttribute != null)
    175       {
    176         files = new ArrayList<Integer>(0);
    177         files.add(fileIdFromSessionAttribute);
    178       }
    179     }
    180     log.debug("(2) files = " + files);
    181     /*
    182      * Make sure at least one file has been selected
    183      */
    184     if (files == null || files.size() == 0)
    185     {
    186       setError("Please select a spectrum file to inspect");
    187       return;
    188     }
    189     /*
    190      * Inspect first file.
    191      */
    192     Integer fileId = files.get(0);
    193     String spectrumId = getValidString(PlotFileSpectrum.VSPECTRUMID);
    194     String massCutoffLowStr = getValidString(PlotFileSpectrum.VMASSCUTOFFLOWSTR);
    195     String massCutoffHighStr = getValidString(PlotFileSpectrum.VMASSCUTOFFHIGHSTR);
    196     Boolean keepOriginalSpectrum = getValidBoolean(VKEEPORIGINALSPECTRUM);
    197     log.debug("(1) spectrumId = " + spectrumId);
    198     // Check alternative input
    199     if (spectrumId == null)
    200     {
    201       String spectrumIdFromSessionAttribute = getSessionAttribute(PlotFileSpectrum.VSPECTRUMID);
    202       log
    203         .debug("spectrumIdFromSessionAttribute = " + spectrumIdFromSessionAttribute);
    204       if (spectrumIdFromSessionAttribute != null)
    205       {
    206         spectrumId = spectrumIdFromSessionAttribute;
    207       }
    208       // Reset value of spectrum Id from session attribute
    209       setSessionAttribute(PlotFileSpectrum.VSPECTRUMID, null);
    210     }
    211     log.debug("(2) spectrumId = " + spectrumId);
    212     log.debug("fileId = " + fileId);
    213     log.debug("spectrumId = \"" + spectrumId + "\"");
    214     log.debug("massCutoffLowStr = \"" + massCutoffLowStr + "\"");
    215     log.debug("massCutoffHighStr = \"" + massCutoffHighStr + "\"");
    216     log.debug("(1) keepOriginalSpectrum = " + keepOriginalSpectrum);
    217     if (keepOriginalSpectrum == null)
    218     {
    219       keepOriginalSpectrum = true;
    220     }
    221     log.debug("(2) keepOriginalSpectrum = " + keepOriginalSpectrum);
    222     // Only show one spectrum view if no mass range parameters
    223     if ((massCutoffLowStr == null || massCutoffLowStr.equals("")) && (massCutoffHighStr == null || massCutoffHighStr
    224       .equals("")))
    225     {
    226       keepOriginalSpectrum = false;
    227     }
    228     log.debug("(3) keepOriginalSpectrum = " + keepOriginalSpectrum);
    229     DbControl dc = newDbControl();
    230     ItemFactory factory = new ItemFactory(dc);
    231     File file = factory.getById(File.class, fileId);
    232     log.debug("file = " + file);
    233     List<String> spectrumIds = null;
    234     // Get spectrum id reader
    235     SpectrumFileReaderFactory spectrumFileReaderFactory = new SpectrumFileReaderFactory();
    236     SpectrumIdReaderInterface spectrumIdReader = spectrumFileReaderFactory
    237       .fetchSpectrumIdReader(file);
    238     if (spectrumIdReader != null)
    239     {
    240       spectrumIds = spectrumIdReader.getSpectrumIdList();
    241     }
    242     /***********************************************************************
    243      * Peaklists
    244      */
    245     Table peakListTable = new Table("peaklists");
    246     // Add tool-bar to table to make GUIConverter set
    247     // form id for action in hidden field.
    248     Toolbar peakListTableToolbar = new Toolbar();
    249     peakListTable.setToolbar(peakListTableToolbar);
    250     if (spectrumIdReader != null)
    251     {
    252       if (spectrumIdReader.isSpectrumIdObtainedFromSpectrumOrderNumber())
    253       {
    254         peakListTable.add(new Column("SpectrumIdOrderNumber3"));
    255         /* Special fix to get to the right spectrum id if it is from an MGF title*/
    256         if (spectrumId != null && spectrumIdReader instanceof MgfFileReader)
    257         {
    258           if (!spectrumId.matches("^d+(\\s-\\s.*)?"))
    259           {
    260             spectrumId = spectrumId.trim();
    261             for (String s : spectrumIds)
    262             {
    263               String toMatch = s.substring(s.indexOf("-") + 2)
    264                 .trim();
    265               if (spectrumId.equals(toMatch))
    266               {
    267                 log.debug("Found spectrum:"+s);
    268                 spectrumId = s;
    269                 setSessionAttribute(PlotFileSpectrum.VSPECTRUMID.getName(), spectrumId);
    270                 break;
    271               }
    272             }
    273           }
    274         }
    275       }
    276       else
    277       {
    278         peakListTable.add(new Column("Spectrum id"));
    279       }
    280     }
    281     if (spectrumIds != null)
    282     {
    283       log.debug("spectrumIds.size() = " + spectrumIds.size());
    284       // Fetch scroller page selected
    285       restoreScrollerState();
    286       log
    287         .debug("getItemsFrom() = " + getItemsFrom() + " isPageSelectedFromScroller() = " + isPageSelectedFromScroller());
    288       if (!isPageSelectedFromScroller())
    289       {
    290         // Adjust scroller page to include selected spectrum
    291         if (spectrumId != null && !spectrumId.equals(""))
    292         {
    293           // find start of scroller page including selected spectrum
    294           Integer currentIndex = fetchStringListItemIndex(spectrumId,
    295             spectrumIds);
    296           log.debug("currentIndex = " + currentIndex);
    297           if (currentIndex != null && currentIndex >= 0)
    298           {
    299             int pageNo = currentIndex / getMaxResults();
    300             int tempStart = pageNo * getMaxResults();
    301             log
    302               .debug("currentIndex = " + currentIndex + " pageNo = " + pageNo + " tempStart = " + tempStart);
    303             // Set start index for displayed list
    304             setItemsFrom(tempStart);
    305           }
    306         }
    307       }
    308       // Add scroller
    309       int count = spectrumIds.size();
    310       if (count > getMaxResults())
    311       {
    312         Scroller scroller = new Scroller();
    313         scroller.setFrom(getItemsFrom());
    314         scroller.setMax(getMaxResults());
    315         scroller.setTotalCount(count);
    316         scroller.setScrollActionId(getActionFactory().getId(
    317           ScrollTo.class));
    318         scroller.setTableConfActionId(getActionFactory().getId(
    319           InspectActiveSpectrumFile.class));
    320         scroller.setDisplayActionId(getActionFactory().getId(
    321           InspectActiveSpectrumFile.class));
    322         // scroller.put(FormFactory.VCLASSNAME, itemClass.getName());
    323         log.debug("scroller ScrollActionId = \"" + getActionFactory()
    324           .getId(ScrollTo.class) + "\"");
    325         log
    326           .debug("scroller TableConfActionId = \"" + getActionFactory()
    327             .getId(InspectActiveSpectrumFile.class) + "\"");
    328         log.debug("scroller.getDisplayActionId() = \"" + scroller
    329           .getDisplayActionId() + "\"");
    330         // Add scroller to table
    331         peakListTable.setScroller(scroller);
    332       }
    333       // Add scroller data
    334       log.debug("getItemsFrom() = " + getItemsFrom());
    335       log.debug("getMaxResults() = " + getMaxResults());
    336       int scrollFrom = getItemsFrom();
    337       int scrollMaxResults = getMaxResults();
    338       TextField<Integer> scrollFromField = new TextField<Integer>(
    339         Scroller.VFROM);
    340       TextField<Integer> scrollMaxResultsField = new TextField<Integer>(
    341         Scroller.VMAXRESULT);
    342       scrollFromField.setValue(scrollFrom);
    343       scrollMaxResultsField.setValue(scrollMaxResults);
    344       peakListTable.add(scrollFromField);
    345       peakListTable.add(scrollMaxResultsField);
    346       //
    347       // Add spectrum id field
    348       TextField<String> spectrumIdField = new TextField<String>(
    349         PlotFileSpectrum.VSPECTRUMID);
    350       spectrumIdField.setHidden(true);
    351       spectrumIdField.setValue(spectrumId);
    352       peakListTable.add(spectrumIdField);
    353       //
    354       // Add mass cut-off low string field
    355       TextField<String> massCutOffLowStrField = new TextField<String>(
    356         PlotFileSpectrum.VMASSCUTOFFLOWSTR);
    357       massCutOffLowStrField.setHidden(true);
    358       massCutOffLowStrField.setValue(massCutoffLowStr);
    359       peakListTable.add(massCutOffLowStrField);
    360       //
    361       // Add mass cut-off high string field
    362       TextField<String> massCutOffHighStrField = new TextField<String>(
    363         PlotFileSpectrum.VMASSCUTOFFHIGHSTR);
    364       massCutOffHighStrField.setHidden(true);
    365       massCutOffHighStrField.setValue(massCutoffHighStr);
    366       peakListTable.add(massCutOffHighStrField);
    367       //
    368       // Add keep original spectrum flag field
    369       TextField<Boolean> keepOriginalSpectrumField = new TextField<Boolean>(
    370         VKEEPORIGINALSPECTRUM);
    371       keepOriginalSpectrumField.setHidden(true);
    372       keepOriginalSpectrumField.setValue(keepOriginalSpectrum);
    373       peakListTable.add(keepOriginalSpectrumField);
    374       //
    375       // Create spectrum list to display
    376       int itemStart = getItemsFrom();
    377       int itemStop = getItemsFrom() + getMaxResults();
    378       for (int i = itemStart; (i < spectrumIds.size() && i < itemStop); i++)
    379       {
    380         // log.debug("spectrumIds.get(" + i + ") = \"" +
    381         // spectrumIds.get(i) + "\"");
    382         // Add data
    383         Row row = new Row(i);
    384         row.addCell(new Cell<String>(spectrumIds.get(i)));
    385         // Configure on-click row action to re-run this action with new
    386         // spectrum id
    387         ActionLink rowAction = getActionFactory().getActionLink(
    388           InspectActiveSpectrumFile.class, "View");
    389         rowAction.addParameter(VSPECTRUMFILEID, fileId);
    390         rowAction.addParameter(PlotFileSpectrum.VSPECTRUMID,
    391           spectrumIds.get(i));
    392         row.setActionLink(rowAction);
    393         peakListTable.addRow(row);
    394       }
    395       // Show first spectrum as default
    396       if (spectrumId == null || spectrumId.equals(""))
    397       {
    398         if (spectrumIds != null && spectrumIds.size() > 0)
    399         {
    400           // Plot first spectrum
    401           spectrumId = spectrumIds.get(0);
    402         }
    403       }
    404     }
    405     /***********************************************************************
    406      * Spectrum plot
    407      */
    408     PlotFileSpectrum plotFileSpectrum = new PlotFileSpectrum();
    409     ImageMap imageMap;
    410     Image plotOriginal = null;
    411     if (keepOriginalSpectrum)
    412     {
    413       plotOriginal = new Image();
    414       ActionLink viewOriginalAction = getActionFactory().getActionLink(
    415         PlotFileSpectrum.class, "ViewOriginal");
    416       viewOriginalAction.addParameter(FormFactory.VID, fileId);
    417       viewOriginalAction.addParameter(PlotFileSpectrum.VSPECTRUMID,
    418         spectrumId);
    419       plotOriginal.setViewAction(viewOriginalAction);
    420       plotOriginal.setHeight(PlotFileSpectrum.HEIGHT);
    421       plotOriginal.setWidth(PlotFileSpectrum.WIDTH);
    422       // Add mass annotation image map
    423       imageMap = plotFileSpectrum.fetchMassPeakAnnotationToolTips(dc,
    424         fileId, spectrumId, (String) null, (String) null);
    425       plotOriginal.setImageMap(imageMap);
    426     }
    427     Image plot = new Image();
    428     ActionLink viewAction = getActionFactory().getActionLink(
    429       PlotFileSpectrum.class, "View");
    430     viewAction.addParameter(FormFactory.VID, fileId);
    431     viewAction.addParameter(PlotFileSpectrum.VSPECTRUMID, spectrumId);
    432     viewAction.addParameter(PlotFileSpectrum.VMASSCUTOFFLOWSTR,
    433       massCutoffLowStr);
    434     viewAction.addParameter(PlotFileSpectrum.VMASSCUTOFFHIGHSTR,
    435       massCutoffHighStr);
    436     plot.setViewAction(viewAction);
    437     plot.setHeight(PlotFileSpectrum.HEIGHT);
    438     plot.setWidth(PlotFileSpectrum.WIDTH);
    439     // Add mass annotation image map
    440     imageMap = plotFileSpectrum.fetchMassPeakAnnotationToolTips(dc, fileId,
    441       spectrumId, massCutoffLowStr, massCutoffHighStr);
    442     plot.setImageMap(imageMap);
    443     /***********************************************************************
    444      * Spectrum iteration buttons
    445      */
    446     Form spectrumIterationForm = new Form("spectrumIterationForm");
    447     spectrumIterationForm.setTitle("spectrumIterationForm");
    448     Fieldset spectrumIterationFS = new Fieldset();
    449     spectrumIterationFS.setTitle("SpectrumIteration");
    450     spectrumIterationForm.addFieldset(spectrumIterationFS);
    451     Toolbar spectrumIterationToolbar = new Toolbar();
    452     spectrumIterationForm.setToolbar(spectrumIterationToolbar);
    453     //
    454     // Add button for previous spectrum
    455     String previousSpectrumId = fetchPreviousListItem(spectrumId,
    456       spectrumIds);
    457     log.debug("previousSpectrumId = \"" + previousSpectrumId + "\"");
    458     ActionLink previousSpectrumAction = getActionLink(
    459       InspectActiveSpectrumFile.class, "PreviousSpectrum");
    460     previousSpectrumAction.addParameter(FormFactory.VID, fileId);
    461     previousSpectrumAction.addParameter(PlotFileSpectrum.VSPECTRUMID,
    462       previousSpectrumId);
    463     previousSpectrumAction.addParameter(VKEEPORIGINALSPECTRUM, true);
    464     if (previousSpectrumId == null)
    465     {
    466       previousSpectrumAction.disable();
    467     }
    468     spectrumIterationToolbar.add(previousSpectrumAction);
    469     //
    470     // Add button for next spectrum
    471     String nextSpectrumId = fetchNextListItem(spectrumId, spectrumIds);
    472     log.debug("nextSpectrumId = \"" + nextSpectrumId + "\"");
    473     ActionLink nextSpectrumAction = getActionLink(
    474       InspectActiveSpectrumFile.class, "NextSpectrum");
    475     nextSpectrumAction.addParameter(FormFactory.VID, fileId);
    476     nextSpectrumAction.addParameter(PlotFileSpectrum.VSPECTRUMID,
    477       nextSpectrumId);
    478     nextSpectrumAction.addParameter(VKEEPORIGINALSPECTRUM, true);
    479     if (nextSpectrumId == null)
    480     {
    481       nextSpectrumAction.disable();
    482     }
    483     spectrumIterationToolbar.add(nextSpectrumAction);
    484     /***********************************************************************
    485      * Spectrum mass range selection form
    486      */
    487     Form massRangeSelectionForm = getFormFactory()
    488       .getSpectrumMassRangeSelectionForm(massCutoffLowStr,
    489         massCutoffHighStr, spectrumId);
    490     Toolbar toolbar = new Toolbar();
    491     massRangeSelectionForm.setToolbar(toolbar);
    492     //
    493     ActionLink zoomWithOriginalAction = getActionLink(
    494       InspectActiveSpectrumFile.class, "ZoomedAndOriginalSpectrum");
    495     zoomWithOriginalAction.addParameter(FormFactory.VID, fileId);
    496     zoomWithOriginalAction.addParameter(VKEEPORIGINALSPECTRUM, true);
    497     toolbar.add(zoomWithOriginalAction);
    498     //
    499     ActionLink zoomAction = getActionLink(InspectActiveSpectrumFile.class,
    500       "ZoomedSpectrum");
    501     zoomAction.addParameter(FormFactory.VID, fileId);
    502     zoomAction.addParameter(VKEEPORIGINALSPECTRUM, false);
    503     toolbar.add(zoomAction);
    504     /***********************************************************************
    505      * Spectrum properties
    506      */
    507     SpectrumInterface spectrum = null;
    508     Form propertiesForm = null;
    509     if (file != null)
    510     {
    511       // Get new list file reader
    512       PeakListFileInterface peakListFileReader = spectrumFileReaderFactory
    513         .fetchPeakListFileReader(file);
    514       if (peakListFileReader != null && spectrumId != null)
    515       {
    516         spectrum = peakListFileReader.getSpectrum(spectrumId);
    517       }
    518       // Spectrum properties form
    519       propertiesForm = getFormFactory().getSpectrumPropertiesForm(file,
    520         spectrumId, spectrum);
    521     }
    522     /***********************************************************************
    523      * Spectrum file instrument data
    524      */
    525     List<SpectrumFileInstrumentInterface> spectrumFileInstrumentList = null;
    526     Form instrumentForm = null;
    527     if (file != null)
    528     {
    529       // Get new spectrum file instrument reader
    530       SpectrumFileInstrumentReaderInterface spectrumFileInstrumentReader = spectrumFileReaderFactory
    531         .fetchSpectrumFileInstrumentReader(file);
    532       if (spectrumFileInstrumentReader != null)
    533       {
    534         spectrumFileInstrumentList = spectrumFileInstrumentReader
    535           .getSpectrumFileInstrumentList();
    536       }
    537       // Spectrum file instrument form
    538       instrumentForm = getFormFactory().getSpectrumFileInstrumentForm(
    539         spectrumFileInstrumentList);
    540     }
    541     /***********************************************************************
    542      * Spectrum file contact data
    543      */
    544     SpectrumFileContactInterface spectrumContact = null;
    545     Form contactForm = null;
    546     if (file != null)
    547     {
    548       // Get new spectrum file contact reader
    549       SpectrumFileContactReaderInterface spectrumFileContactReader = spectrumFileReaderFactory
    550         .fetchSpectrumFileContactReader(file);
    551       if (spectrumFileContactReader != null)
    552       {
    553         spectrumContact = spectrumFileContactReader
    554           .getSpectrumContact();
    555       }
    556       // Spectrum file contacts form
    557       contactForm = getFormFactory().getSpectrumFileContactForm(
    558         spectrumContact);
    559     }
    560     /***********************************************************************
    561      * Layout
    562      */
    563     // GridLayout layout = getLayoutFactory().getGridLayout(1, 2, 1, 1);
    564     RowLayout layout = getLayoutFactory().getRowLayout();
    565     // Adapt title to file type
    566     String titleHeader = spectrumFileReaderFactory
    567       .fetchFileTypeTitleString(file);
    568     Title title = new Title(titleHeader);
    569     title.setSubtitle("" + file.getName() + " [" + fileId + "]");
    570     layout.add(title);
    571     // Row container for plot and properties form
    572     RowContainer rc = new RowContainer();
    573     if (plotOriginal != null)
    574     {
    575       rc.add(plotOriginal);
    576     }
    577     rc.add(plot);
    578     rc.add(spectrumIterationForm);
    579     rc.add(massRangeSelectionForm);
    580     rc.add(propertiesForm);
    581     if (instrumentForm != null)
    582     {
    583       rc.add(instrumentForm);
    584     }
    585     if (contactForm != null)
    586     {
    587       rc.add(contactForm);
    588     }
    589     //
    590     ColumnContainer cc = new ColumnContainer();
    591     cc.add(peakListTable);
    592     if (plot != null || propertiesForm != null)
    593     {
    594       cc.add(rc);
    595     }
    596     layout.add(cc);
    597     //
    598     setLayout(layout);
    599     log.debug("End");
    600   }
    601 
    602 
    603   /**
    604    * Fetch index for item from from string list.
    605    *
    606    * @param currentItem String The current item.
    607    * @param inList List<String> The string list to use.
    608    * @return Integer The index for the item, or null if none.
    609    */
    610   public Integer fetchStringListItemIndex(String currentItem,
    611       List<String> inList)
    612   {
    613     log.debug("currentItem = \"" + currentItem + "\"");
    614     if (currentItem == null || inList == null)
    615     {
    616       return null;
    617     }
    618     log.debug("inList.size() = " + inList.size());
    619     // Find current index
    620     Integer currentIndex = null;
    621     for (int i = 0; i < inList.size(); i++)
    622     {
    623       String item = (String) inList.get(i);
    624       if (item != null)
    625       {
    626         if (item.equals(currentItem))
    627         {
    628           currentIndex = i;
    629           break;
    630         }
    631       }
    632     }
    633     log.debug("currentIndex = " + currentIndex);
    634     return currentIndex;
    635   }
    636 
    637 
    638   /**
    639    * Fetch previous list item from string list.
    640    *
    641    * @param currentItem String The current item.
    642    * @param inList List<String> The string list to use.
    643    * @return String The previous item, or null if none.
    644    */
    645   public String fetchPreviousListItem(String currentItem, List<String> inList)
    646   {
    647     log.debug("currentItem = \"" + currentItem + "\"");
    648     if (currentItem == null || inList == null)
    649     {
    650       return null;
    651     }
    652     log.debug("inList.size() = " + inList.size());
    653     // Find current index
    654     int currentIndex = -1;
    655     for (int i = 0; i < inList.size(); i++)
    656     {
    657       String item = (String) inList.get(i);
    658       if (item != null)
    659       {
    660         if (item.equals(currentItem))
    661         {
    662           currentIndex = i;
    663           break;
    664         }
    665       }
    666     }
    667     log.debug("currentIndex = " + currentIndex);
    668     // Find previous item
    669     String previousItem = null;
    670     if (currentIndex > 0)
    671     {
    672       previousItem = (String) inList.get(currentIndex - 1);
    673     }
    674     log.debug("previousItem = \"" + previousItem + "\"");
    675     return previousItem;
    676   }
    677 
    678 
    679   /**
    680    * Fetch next list item from string list.
    681    *
    682    * @param currentItem String The current item.
    683    * @param inList List<String> The string list to use.
    684    * @return String The next item, or null if none.
    685    */
    686   public String fetchNextListItem(String currentItem, List<String> inList)
    687   {
    688     log.debug("currentItem = \"" + currentItem + "\"");
    689     if (currentItem == null || inList == null)
    690     {
    691       return null;
    692     }
    693     log.debug("inList.size() = " + inList.size());
    694     // Find current index
    695     int currentIndex = -1;
    696     for (int i = 0; i < inList.size(); i++)
    697     {
    698       String item = (String) inList.get(i);
    699       if (item != null)
    700       {
    701         if (item.equals(currentItem))
    702         {
    703           currentIndex = i;
    704           break;
    705         }
    706       }
    707     }
    708     log.debug("currentIndex = " + currentIndex);
    709     // Find next item
    710     String nextItem = null;
    711     if (currentIndex < (inList.size() - 1))
    712     {
    713       nextItem = (String) inList.get(currentIndex + 1);
    714     }
    715     log.debug("nextItem = \"" + nextItem + "\"");
    716     return nextItem;
    717   }
    718 
    719 
    720   /**
    721    * Restores table scroller settings (stored as valid parameters).
    722    */
    723   private void restoreScrollerState()
    724       throws InvalidParameterValue
    725   {
    726     // Get scroller data from valid parameters set to table
    727     Integer scrollFrom = getValidInteger(Scroller.VFROM);
    728     Integer scrollMaxResults = getValidInteger(Scroller.VMAXRESULT);
    729     // Update scroller settings
    730     if (scrollFrom != null)
    731     {
    732       setItemsFrom(scrollFrom);
    733       setPageSelectedFromScroller(true);
    734     }
    735     if (scrollMaxResults != null)
    736     {
    737       setMaxResults(scrollMaxResults);
    738     }
    739     log
    740       .debug("scrollFrom = " + scrollFrom + " isPageSelectedFromScroller() = " + isPageSelectedFromScroller());
    741     log.debug("scrollMaxResults = " + scrollMaxResults);
    742   }
    743 }
     78    public static final VInteger VSPECTRUMFILEID = new VInteger(
     79    "spectrumFileId", 0, false);
     80    public static final VBoolean VKEEPORIGINALSPECTRUM = new VBoolean(
     81    "keepOriginalSpectrum", false);
     82    public static final VBoolean VFIRSTMGFTITLESPECTRUM = new VBoolean(
     83    "firstMGF", false);
     84    private int maxResults = 20;
     85    private int itemsFrom = 0;
     86    private boolean pageSelectedFromScroller = false;
     87               
     88    /**
     89        * Get the max number of results to show in list.
     90        *
     91        * @return int The max number of results to show in list.
     92    */
     93    public int getMaxResults()
     94    {
     95        return this.maxResults;
     96    }
     97               
     98    /**
     99        * Set the max number of results to show in list.
     100        *
     101        * @param maxResults int The value to set for the max number of results to
     102        *        show in list.
     103    */
     104    public void setMaxResults(int maxResults)
     105    {
     106        this.maxResults = maxResults;
     107    }
     108               
     109    /**
     110        * Get the item number to start from in the list.
     111        *
     112        * @return int The item number to start from in the list.
     113    */
     114    public int getItemsFrom()
     115    {
     116        return this.itemsFrom;
     117    }
     118               
     119    /**
     120        * Set the item number to start from in the list.
     121        *
     122        * @param itemsFrom int The value to set for the item number to start from
     123        *        in the list.
     124    */
     125    public void setItemsFrom(int itemsFrom)
     126    {
     127        this.itemsFrom = itemsFrom;
     128    }
     129               
     130    /**
     131        * Get flag indicating that page is selected from scroller.
     132        *
     133        * @return boolean The flag indicating that page is selected from scroller.
     134    */
     135    public boolean isPageSelectedFromScroller()
     136    {
     137        return this.pageSelectedFromScroller;
     138    }
     139               
     140    /**
     141        * Set flag indicating that page is selected from scroller.
     142        *
     143        * @param pageSelectedFromScroller boolean The value to set for flag
     144        *        indicating that page is selected from scroller.
     145    */
     146    public void setPageSelectedFromScroller(boolean pageSelectedFromScroller)
     147    {
     148        this.pageSelectedFromScroller = pageSelectedFromScroller;
     149    }
     150               
     151    @Override
     152    protected void runMe()
     153    throws ActionException, InvalidParameterValue
     154    {
     155        /*
     156            * Get the id's of all selected files. VSPECTRUMFILEID is the valid
     157            * identifier used when rendering the list of files, thus we use it to
     158            * get the valid list of item id values.
     159        */
     160        List<Integer> files = getValidIntegerList(VSPECTRUMFILEID);
     161        log.debug("(1) files = " + files);
     162        // Check alternative input
     163        if (files == null)
     164        {
     165            Integer fileIdFromSessionAttribute = getSessionAttribute(VSPECTRUMFILEID);
     166            log
     167            .debug("fileIdFromSessionAttribute = " + fileIdFromSessionAttribute);
     168            if (fileIdFromSessionAttribute != null)
     169            {
     170                files = new ArrayList<Integer>(0);
     171                files.add(fileIdFromSessionAttribute);
     172            }
     173        }
     174        log.debug("(2) files = " + files);
     175        /*
     176            * Make sure at least one file has been selected
     177        */
     178        if (files == null || files.size() == 0)
     179        {
     180            setError("Please select a spectrum file to inspect");
     181            return;
     182        }
     183        /*
     184            * Inspect first file.
     185        */
     186        Integer fileId = files.get(0);
     187        String spectrumId = getValidString(PlotFileSpectrum.VSPECTRUMID);
     188        String massCutoffLowStr = getValidString(PlotFileSpectrum.VMASSCUTOFFLOWSTR);
     189        String massCutoffHighStr = getValidString(PlotFileSpectrum.VMASSCUTOFFHIGHSTR);
     190        Boolean keepOriginalSpectrum = getValidBoolean(VKEEPORIGINALSPECTRUM);
     191        log.debug("(1) spectrumId = " + spectrumId);
     192        // Check alternative input
     193        if (spectrumId == null)
     194        {
     195            String spectrumIdFromSessionAttribute = getSessionAttribute(PlotFileSpectrum.VSPECTRUMID);
     196            log
     197            .debug("spectrumIdFromSessionAttribute = " + spectrumIdFromSessionAttribute);
     198            if (spectrumIdFromSessionAttribute != null)
     199            {
     200                spectrumId = spectrumIdFromSessionAttribute;
     201            }
     202            // Reset value of spectrum Id from session attribute
     203            setSessionAttribute(PlotFileSpectrum.VSPECTRUMID, null);
     204        }
     205        log.debug("(2) spectrumId = " + spectrumId);
     206        log.debug("fileId = " + fileId);
     207        log.debug("spectrumId = \"" + spectrumId + "\"");
     208        log.debug("massCutoffLowStr = \"" + massCutoffLowStr + "\"");
     209        log.debug("massCutoffHighStr = \"" + massCutoffHighStr + "\"");
     210        log.debug("(1) keepOriginalSpectrum = " + keepOriginalSpectrum);
     211        if (keepOriginalSpectrum == null)
     212        {
     213            keepOriginalSpectrum = true;
     214        }
     215        log.debug("(2) keepOriginalSpectrum = " + keepOriginalSpectrum);
     216        // Only show one spectrum view if no mass range parameters
     217        if ((massCutoffLowStr == null || massCutoffLowStr.equals("")) && (massCutoffHighStr == null || massCutoffHighStr
     218        .equals("")))
     219        {
     220            keepOriginalSpectrum = false;
     221        }
     222        log.debug("(3) keepOriginalSpectrum = " + keepOriginalSpectrum);
     223        DbControl dc = newDbControl();
     224        ItemFactory factory = new ItemFactory(dc);
     225        File file = factory.getById(File.class, fileId);
     226        log.debug("file = " + file);
     227        List<String> spectrumIds = null;
     228        // Get spectrum id reader
     229        SpectrumFileReaderFactory spectrumFileReaderFactory = new SpectrumFileReaderFactory();
     230        SpectrumIdReaderInterface spectrumIdReader = spectrumFileReaderFactory
     231        .fetchSpectrumIdReader(file);
     232        if (spectrumIdReader != null)
     233        {
     234            spectrumIds = spectrumIdReader.getSpectrumIdList();
     235        }
     236        /***********************************************************************
     237            * Peaklists
     238        */
     239        Table peakListTable = new Table("peaklists");
     240        // Add tool-bar to table to make GUIConverter set
     241        // form id for action in hidden field.
     242        Toolbar peakListTableToolbar = new Toolbar();
     243        peakListTable.setToolbar(peakListTableToolbar);
     244        if (spectrumIdReader != null)
     245        {
     246            if (spectrumIdReader.isSpectrumIdObtainedFromSpectrumOrderNumber())
     247            {
     248                peakListTable.add(new Column("SpectrumIdOrderNumber3"));
     249                /* Special fix to get to the right spectrum id if it is from an MGF title*/
     250                    if (spectrumId != null && spectrumIdReader instanceof MgfFileReader)
     251                    {
     252                        if (!spectrumId.matches("^d+(\\s-\\s.*)?"))
     253                        {
     254                            spectrumId = spectrumId.trim();
     255                            for (String s : spectrumIds)
     256                            {
     257                                String toMatch = s.substring(s.indexOf("-") + 2)
     258                                .trim();
     259                                if (spectrumId.equals(toMatch))
     260                                {
     261                                    log.debug("Found spectrum:"+s);
     262                                    spectrumId = s;
     263                                    setSessionAttribute(PlotFileSpectrum.VSPECTRUMID.getName(), spectrumId);
     264                                    break;
     265                                }
     266                            }
     267                        }
     268                    }
     269                }
     270                else
     271                {
     272                    peakListTable.add(new Column("Spectrum id"));
     273                }
     274            }
     275            if (spectrumIds != null)
     276            {
     277                log.debug("spectrumIds.size() = " + spectrumIds.size());
     278                // Fetch scroller page selected
     279                restoreScrollerState();
     280                log
     281                .debug("getItemsFrom() = " + getItemsFrom() + " isPageSelectedFromScroller() = " + isPageSelectedFromScroller());
     282                if (!isPageSelectedFromScroller())
     283                {
     284                    // Adjust scroller page to include selected spectrum
     285                    if (spectrumId != null && !spectrumId.equals(""))
     286                    {
     287                        // find start of scroller page including selected spectrum
     288                        Integer currentIndex = fetchStringListItemIndex(spectrumId,
     289                        spectrumIds);
     290                        log.debug("currentIndex = " + currentIndex);
     291                        if (currentIndex != null && currentIndex >= 0)
     292                        {
     293                            int pageNo = currentIndex / getMaxResults();
     294                            int tempStart = pageNo * getMaxResults();
     295                            log
     296                            .debug("currentIndex = " + currentIndex + " pageNo = " + pageNo + " tempStart = " + tempStart);
     297                            // Set start index for displayed list
     298                            setItemsFrom(tempStart);
     299                        }
     300                    }
     301                }
     302                // Add scroller
     303                int count = spectrumIds.size();
     304                if (count > getMaxResults())
     305                {
     306                    Scroller scroller = new Scroller();
     307                    scroller.setFrom(getItemsFrom());
     308                    scroller.setMax(getMaxResults());
     309                    scroller.setTotalCount(count);
     310                    scroller.setScrollActionId(getActionFactory().getId(
     311                    ScrollTo.class));
     312                    scroller.setTableConfActionId(getActionFactory().getId(
     313                    InspectActiveSpectrumFile.class));
     314                    scroller.setDisplayActionId(getActionFactory().getId(
     315                    InspectActiveSpectrumFile.class));
     316                    // scroller.put(FormFactory.VCLASSNAME, itemClass.getName());
     317                    log.debug("scroller ScrollActionId = \"" + getActionFactory()
     318                    .getId(ScrollTo.class) + "\"");
     319                    log
     320                    .debug("scroller TableConfActionId = \"" + getActionFactory()
     321                    .getId(InspectActiveSpectrumFile.class) + "\"");
     322                    log.debug("scroller.getDisplayActionId() = \"" + scroller
     323                    .getDisplayActionId() + "\"");
     324                    // Add scroller to table
     325                    peakListTable.setScroller(scroller);
     326                }
     327                // Add scroller data
     328                log.debug("getItemsFrom() = " + getItemsFrom());
     329                log.debug("getMaxResults() = " + getMaxResults());
     330                int scrollFrom = getItemsFrom();
     331                int scrollMaxResults = getMaxResults();
     332                TextField<Integer> scrollFromField = new TextField<Integer>(
     333                Scroller.VFROM);
     334                TextField<Integer> scrollMaxResultsField = new TextField<Integer>(
     335                Scroller.VMAXRESULT);
     336                scrollFromField.setValue(scrollFrom);
     337                scrollMaxResultsField.setValue(scrollMaxResults);
     338                peakListTable.add(scrollFromField);
     339                peakListTable.add(scrollMaxResultsField);
     340                //
     341                // Add spectrum id field
     342                TextField<String> spectrumIdField = new TextField<String>(
     343                PlotFileSpectrum.VSPECTRUMID);
     344                spectrumIdField.setHidden(true);
     345                spectrumIdField.setValue(spectrumId);
     346                peakListTable.add(spectrumIdField);
     347                //
     348                // Add mass cut-off low string field
     349                TextField<String> massCutOffLowStrField = new TextField<String>(
     350                PlotFileSpectrum.VMASSCUTOFFLOWSTR);
     351                massCutOffLowStrField.setHidden(true);
     352                massCutOffLowStrField.setValue(massCutoffLowStr);
     353                peakListTable.add(massCutOffLowStrField);
     354                //
     355                // Add mass cut-off high string field
     356                TextField<String> massCutOffHighStrField = new TextField<String>(
     357                PlotFileSpectrum.VMASSCUTOFFHIGHSTR);
     358                massCutOffHighStrField.setHidden(true);
     359                massCutOffHighStrField.setValue(massCutoffHighStr);
     360                peakListTable.add(massCutOffHighStrField);
     361                //
     362                // Add keep original spectrum flag field
     363                TextField<Boolean> keepOriginalSpectrumField = new TextField<Boolean>(
     364                VKEEPORIGINALSPECTRUM);
     365                keepOriginalSpectrumField.setHidden(true);
     366                keepOriginalSpectrumField.setValue(keepOriginalSpectrum);
     367                peakListTable.add(keepOriginalSpectrumField);
     368                //
     369                // Create spectrum list to display
     370                int itemStart = getItemsFrom();
     371                int itemStop = getItemsFrom() + getMaxResults();
     372                for (int i = itemStart; (i < spectrumIds.size() && i < itemStop); i++)
     373                {
     374                    // log.debug("spectrumIds.get(" + i + ") = \"" +
     375                    // spectrumIds.get(i) + "\"");
     376                    // Add data
     377                    Row row = new Row(i);
     378                    row.addCell(new Cell<String>(spectrumIds.get(i)));
     379                    // Configure on-click row action to re-run this action with new
     380                    // spectrum id
     381                    ActionLink rowAction = getActionFactory().getActionLink(
     382                    InspectActiveSpectrumFile.class, "View");
     383                    rowAction.addParameter(VSPECTRUMFILEID, fileId);
     384                    rowAction.addParameter(PlotFileSpectrum.VSPECTRUMID,
     385                    spectrumIds.get(i));
     386                    row.setActionLink(rowAction);
     387                    peakListTable.addRow(row);
     388                }
     389                // Show first spectrum as default
     390                if (spectrumId == null || spectrumId.equals(""))
     391                {
     392                    if (spectrumIds != null && spectrumIds.size() > 0)
     393                    {
     394                        // Plot first spectrum
     395                        spectrumId = spectrumIds.get(0);
     396                    }
     397                }
     398            }
     399            /***********************************************************************
     400                * Spectrum plot
     401            */
     402            PlotFileSpectrum plotFileSpectrum = new PlotFileSpectrum();
     403            ImageMap imageMap;
     404            Image plotOriginal = null;
     405            if (keepOriginalSpectrum)
     406            {
     407                plotOriginal = new Image();
     408                ActionLink viewOriginalAction = getActionFactory().getActionLink(
     409                PlotFileSpectrum.class, "ViewOriginal");
     410                viewOriginalAction.addParameter(FormFactory.VID, fileId);
     411                viewOriginalAction.addParameter(PlotFileSpectrum.VSPECTRUMID,
     412                spectrumId);
     413                plotOriginal.setViewAction(viewOriginalAction);
     414                plotOriginal.setHeight(PlotFileSpectrum.HEIGHT);
     415                plotOriginal.setWidth(PlotFileSpectrum.WIDTH);
     416                // Add mass annotation image map
     417                imageMap = plotFileSpectrum.fetchMassPeakAnnotationToolTips(dc,
     418                fileId, spectrumId, (String) null, (String) null);
     419                plotOriginal.setImageMap(imageMap);
     420            }
     421            Image plot = new Image();
     422            ActionLink viewAction = getActionFactory().getActionLink(
     423            PlotFileSpectrum.class, "View");
     424            viewAction.addParameter(FormFactory.VID, fileId);
     425            viewAction.addParameter(PlotFileSpectrum.VSPECTRUMID, spectrumId);
     426            viewAction.addParameter(PlotFileSpectrum.VMASSCUTOFFLOWSTR,
     427            massCutoffLowStr);
     428            viewAction.addParameter(PlotFileSpectrum.VMASSCUTOFFHIGHSTR,
     429            massCutoffHighStr);
     430            plot.setViewAction(viewAction);
     431            plot.setHeight(PlotFileSpectrum.HEIGHT);
     432            plot.setWidth(PlotFileSpectrum.WIDTH);
     433            // Add mass annotation image map
     434            imageMap = plotFileSpectrum.fetchMassPeakAnnotationToolTips(dc, fileId,
     435            spectrumId, massCutoffLowStr, massCutoffHighStr);
     436            plot.setImageMap(imageMap);
     437            /***********************************************************************
     438                * Spectrum iteration buttons
     439            */
     440            Form spectrumIterationForm = new Form("spectrumIterationForm");
     441            spectrumIterationForm.setTitle("spectrumIterationForm");
     442            Fieldset spectrumIterationFS = new Fieldset();
     443            spectrumIterationFS.setTitle("SpectrumIteration");
     444            spectrumIterationForm.addFieldset(spectrumIterationFS);
     445            Toolbar spectrumIterationToolbar = new Toolbar();
     446            spectrumIterationForm.setToolbar(spectrumIterationToolbar);
     447            //
     448            // Add button for previous spectrum
     449            String previousSpectrumId = fetchPreviousListItem(spectrumId,
     450            spectrumIds);
     451            log.debug("previousSpectrumId = \"" + previousSpectrumId + "\"");
     452            ActionLink previousSpectrumAction = getActionLink(
     453            InspectActiveSpectrumFile.class, "PreviousSpectrum");
     454            previousSpectrumAction.addParameter(FormFactory.VID, fileId);
     455            previousSpectrumAction.addParameter(PlotFileSpectrum.VSPECTRUMID,
     456            previousSpectrumId);
     457            previousSpectrumAction.addParameter(VKEEPORIGINALSPECTRUM, true);
     458            if (previousSpectrumId == null)
     459            {
     460                previousSpectrumAction.disable();
     461            }
     462            spectrumIterationToolbar.add(previousSpectrumAction);
     463            //
     464            // Add button for next spectrum
     465            String nextSpectrumId = fetchNextListItem(spectrumId, spectrumIds);
     466            log.debug("nextSpectrumId = \"" + nextSpectrumId + "\"");
     467            ActionLink nextSpectrumAction = getActionLink(
     468            InspectActiveSpectrumFile.class, "NextSpectrum");
     469            nextSpectrumAction.addParameter(FormFactory.VID, fileId);
     470            nextSpectrumAction.addParameter(PlotFileSpectrum.VSPECTRUMID,
     471            nextSpectrumId);
     472            nextSpectrumAction.addParameter(VKEEPORIGINALSPECTRUM, true);
     473            if (nextSpectrumId == null)
     474            {
     475                nextSpectrumAction.disable();
     476            }
     477            spectrumIterationToolbar.add(nextSpectrumAction);
     478            /***********************************************************************
     479                * Spectrum mass range selection form
     480            */
     481            Form massRangeSelectionForm = getFormFactory().getSpectrumMassRangeSelectionForm(massCutoffLowStr,
     482            massCutoffHighStr, spectrumId);
     483            Toolbar toolbar = new Toolbar();
     484            massRangeSelectionForm.setToolbar(toolbar);
     485            //
     486            ActionLink zoomWithOriginalAction = getActionLink(
     487            InspectActiveSpectrumFile.class, "ZoomedAndOriginalSpectrum");
     488            zoomWithOriginalAction.addParameter(FormFactory.VID, fileId);
     489            zoomWithOriginalAction.addParameter(VKEEPORIGINALSPECTRUM, true);
     490            toolbar.add(zoomWithOriginalAction);
     491            //
     492            ActionLink zoomAction = getActionLink(InspectActiveSpectrumFile.class,
     493            "ZoomedSpectrum");
     494            zoomAction.addParameter(FormFactory.VID, fileId);
     495            zoomAction.addParameter(VKEEPORIGINALSPECTRUM, false);
     496            toolbar.add(zoomAction);
     497            /***********************************************************************
     498                * Spectrum properties
     499            */
     500            SpectrumInterface spectrum = null;
     501            Form propertiesForm = null;
     502            if (file != null)
     503            {
     504                // Get new list file reader
     505                PeakListFileInterface peakListFileReader = spectrumFileReaderFactory
     506                .fetchPeakListFileReader(file);
     507                if (peakListFileReader != null && spectrumId != null)
     508                {
     509                    spectrum = peakListFileReader.getSpectrum(spectrumId);
     510                }
     511                // Spectrum properties form
     512                propertiesForm = getFormFactory().getSpectrumPropertiesForm(file,
     513                spectrumId, spectrum);
     514            }
     515            /***********************************************************************
     516                * Spectrum file instrument data
     517            */
     518            List<SpectrumFileInstrumentInterface> spectrumFileInstrumentList = null;
     519            Form instrumentForm = null;
     520            if (file != null)
     521            {
     522                // Get new spectrum file instrument reader
     523                SpectrumFileInstrumentReaderInterface spectrumFileInstrumentReader = spectrumFileReaderFactory
     524                .fetchSpectrumFileInstrumentReader(file);
     525                if (spectrumFileInstrumentReader != null)
     526                {
     527                    spectrumFileInstrumentList = spectrumFileInstrumentReader
     528                    .getSpectrumFileInstrumentList();
     529                }
     530                // Spectrum file instrument form
     531                instrumentForm = getSpectrumFileInstrumentForm(spectrumFileInstrumentList);
     532            }
     533            /***********************************************************************
     534                * Spectrum file contact data
     535            */
     536            SpectrumFileContactInterface spectrumContact = null;
     537            Form contactForm = null;
     538            if (file != null)
     539            {
     540                // Get new spectrum file contact reader
     541                SpectrumFileContactReaderInterface spectrumFileContactReader = spectrumFileReaderFactory
     542                .fetchSpectrumFileContactReader(file);
     543                if (spectrumFileContactReader != null)
     544                {
     545                    spectrumContact = spectrumFileContactReader
     546                    .getSpectrumContact();
     547                }
     548                // Spectrum file contacts form
     549                contactForm = getFormFactory().getSpectrumFileContactForm(
     550                spectrumContact);
     551            }
     552            /***********************************************************************
     553                * Layout
     554            */
     555            // GridLayout layout = getLayoutFactory().getGridLayout(1, 2, 1, 1);
     556            RowLayout layout = getLayoutFactory().getRowLayout();
     557            // Adapt title to file type
     558            String titleHeader = spectrumFileReaderFactory
     559            .fetchFileTypeTitleString(file);
     560            Title title = new Title(titleHeader);
     561            title.setSubtitle("" + file.getName() + " [" + fileId + "]");
     562            layout.add(title);
     563            // Row container for plot and properties form
     564            RowContainer rc = new RowContainer();
     565            if (plotOriginal != null)
     566            {
     567                rc.add(plotOriginal);
     568            }
     569            rc.add(plot);
     570            rc.add(spectrumIterationForm);
     571            rc.add(massRangeSelectionForm);
     572            rc.add(propertiesForm);
     573            if (instrumentForm != null)
     574            {
     575                rc.add(instrumentForm);
     576            }
     577            if (contactForm != null)
     578            {
     579                rc.add(contactForm);
     580            }
     581            //
     582            ColumnContainer cc = new ColumnContainer();
     583            cc.add(peakListTable);
     584            if (plot != null || propertiesForm != null)
     585            {
     586                cc.add(rc);
     587            }
     588            layout.add(cc);
     589            //
     590            setLayout(layout);
     591            log.debug("End");
     592        }
     593                               
     594        /**
     595            * Fetch index for item from from string list.
     596            *
     597            * @param currentItem String The current item.
     598            * @param inList List<String> The string list to use.
     599            * @return Integer The index for the item, or null if none.
     600        */
     601        public Integer fetchStringListItemIndex(String currentItem,
     602        List<String> inList)
     603        {
     604            log.debug("currentItem = \"" + currentItem + "\"");
     605            if (currentItem == null || inList == null)
     606            {
     607                return null;
     608            }
     609            log.debug("inList.size() = " + inList.size());
     610            // Find current index
     611            Integer currentIndex = null;
     612            for (int i = 0; i < inList.size(); i++)
     613            {
     614                String item = (String) inList.get(i);
     615                if (item != null)
     616                {
     617                    if (item.equals(currentItem))
     618                    {
     619                        currentIndex = i;
     620                        break;
     621                    }
     622                }
     623            }
     624            log.debug("currentIndex = " + currentIndex);
     625            return currentIndex;
     626        }
     627                               
     628        /**
     629            * Fetch previous list item from string list.
     630            *
     631            * @param currentItem String The current item.
     632            * @param inList List<String> The string list to use.
     633            * @return String The previous item, or null if none.
     634        */
     635        public String fetchPreviousListItem(String currentItem, List<String> inList)
     636        {
     637            log.debug("currentItem = \"" + currentItem + "\"");
     638            if (currentItem == null || inList == null)
     639            {
     640                return null;
     641            }
     642            log.debug("inList.size() = " + inList.size());
     643            // Find current index
     644            int currentIndex = -1;
     645            for (int i = 0; i < inList.size(); i++)
     646            {
     647                String item = (String) inList.get(i);
     648                if (item != null)
     649                {
     650                    if (item.equals(currentItem))
     651                    {
     652                        currentIndex = i;
     653                        break;
     654                    }
     655                }
     656            }
     657            log.debug("currentIndex = " + currentIndex);
     658            // Find previous item
     659            String previousItem = null;
     660            if (currentIndex > 0)
     661            {
     662                previousItem = (String) inList.get(currentIndex - 1);
     663            }
     664            log.debug("previousItem = \"" + previousItem + "\"");
     665            return previousItem;
     666        }
     667                               
     668        /**
     669            * Fetch next list item from string list.
     670            *
     671            * @param currentItem String The current item.
     672            * @param inList List<String> The string list to use.
     673            * @return String The next item, or null if none.
     674        */
     675        public String fetchNextListItem(String currentItem, List<String> inList)
     676        {
     677            log.debug("currentItem = \"" + currentItem + "\"");
     678            if (currentItem == null || inList == null)
     679            {
     680                return null;
     681            }
     682            log.debug("inList.size() = " + inList.size());
     683            // Find current index
     684            int currentIndex = -1;
     685            for (int i = 0; i < inList.size(); i++)
     686            {
     687                String item = (String) inList.get(i);
     688                if (item != null)
     689                {
     690                    if (item.equals(currentItem))
     691                    {
     692                        currentIndex = i;
     693                        break;
     694                    }
     695                }
     696            }
     697            log.debug("currentIndex = " + currentIndex);
     698            // Find next item
     699            String nextItem = null;
     700            if (currentIndex < (inList.size() - 1))
     701            {
     702                nextItem = (String) inList.get(currentIndex + 1);
     703            }
     704            log.debug("nextItem = \"" + nextItem + "\"");
     705            return nextItem;
     706        }
     707                               
     708        /**
     709            * Restores table scroller settings (stored as valid parameters).
     710        */
     711        private void restoreScrollerState()
     712        throws InvalidParameterValue
     713        {
     714            // Get scroller data from valid parameters set to table
     715            Integer scrollFrom = getValidInteger(Scroller.VFROM);
     716            Integer scrollMaxResults = getValidInteger(Scroller.VMAXRESULT);
     717            // Update scroller settings
     718            if (scrollFrom != null)
     719            {
     720                setItemsFrom(scrollFrom);
     721                setPageSelectedFromScroller(true);
     722            }
     723            if (scrollMaxResults != null)
     724            {
     725                setMaxResults(scrollMaxResults);
     726            }
     727            log
     728            .debug("scrollFrom = " + scrollFrom + " isPageSelectedFromScroller() = " + isPageSelectedFromScroller());
     729            log.debug("scrollMaxResults = " + scrollMaxResults);
     730        }
     731                               
     732        /**
     733            Returns a form with spectrum file instrument data for a spectrum file.
     734                                                                                               
     735            @param spectrumFileInstrumentList List<SpectrumFileInstrumentInterface>
     736            Spectrum file instrument list.
     737            @return Form for displaying spectrum file instrument data.
     738        */
     739        public Form getSpectrumFileInstrumentForm(
     740        List<SpectrumFileInstrumentInterface> spectrumFileInstrumentList)
     741        {
     742            if (spectrumFileInstrumentList == null || spectrumFileInstrumentList
     743            .size() == 0)
     744            {
     745                return null;
     746            }
     747            /***********************************************************************
     748                Instrument fieldset
     749            */
     750            Fieldset instrumentFS = new Fieldset();
     751            int instrumentNo = 0;
     752            for (SpectrumFileInstrumentInterface spectrumFileInstrument : spectrumFileInstrumentList)
     753            {
     754                instrumentNo++;
     755                List<StringPairInterface> dataList;
     756                /*
     757                    Name field.
     758                */
     759                Table instrumentGeneralTable = new Table(
     760                "InstrumentGeneralInformation");
     761                // Only print table header for first table
     762                if (instrumentNo == 1)
     763                {
     764                    instrumentGeneralTable.setTitle("InstrumentInformation");
     765                }
     766                // instrumentGeneralTable.add(new Column<String>("Property"));
     767                instrumentGeneralTable.add(new Column<String>("InstrumentGeneral"));
     768                instrumentGeneralTable.add(new Column<String>("Value"));
     769                String instrumentName = null;
     770                if (spectrumFileInstrument != null)
     771                {
     772                    instrumentName = spectrumFileInstrument.getInstrumentName();
     773                }
     774                instrumentGeneralTable.addRow(new PropertyRow(0, "InstrumentName", instrumentName, null));
     775                /*
     776                    Serial No field.
     777                */
     778                String instrumentSerialNo = null;
     779                if (spectrumFileInstrument != null)
     780                {
     781                    instrumentSerialNo = spectrumFileInstrument
     782                    .getInstrumentSerialNo();
     783                }
     784                instrumentGeneralTable.addRow(new PropertyRow(0, "InstrumentSerialNo", instrumentSerialNo, null));
     785                instrumentFS.add(instrumentGeneralTable);
     786                /*
     787                    Source field.
     788                */
     789                Table sourceTable = new Table("SourceInformation");
     790                // sourceTable.setTitle("SourceInformation");
     791                // sourceTable.add(new Column<String>("Property"));
     792                sourceTable.add(new Column<String>("SourceInformation"));
     793                sourceTable.add(new Column<String>("Value"));
     794                dataList = spectrumFileInstrument.getSource();
     795                if (dataList != null)
     796                {
     797                    for (int i = 0; i < dataList.size(); i++)
     798                    {
     799                        StringPairInterface data = dataList.get(i);
     800                        if (data != null)
     801                        {
     802                            String name = data.getName();
     803                            String value = data.getValue();
     804                            if (name != null && !name.equals(""))
     805                            {
     806                                sourceTable.addRow(new PropertyRow(0, name, value, null));
     807                            }
     808                        }
     809                    }
     810                }
     811                instrumentFS.add(sourceTable);
     812                /*
     813                    AnalyzerList field.
     814                */
     815                List<SpectrumFileAnalyzerInterface> analyzerList = spectrumFileInstrument
     816                .getAnalyzers();
     817                if (analyzerList != null)
     818                {
     819                    for (int j = 0; j < analyzerList.size(); j++)
     820                    {
     821                        Table analyzerTable = new Table("AnalyzerListInformation");
     822                        /*
     823                            // Only add table title header for first table if (j ==
     824                            0) { analyzerTable.setTitle("AnalyzerListInformation"); }
     825                        */
     826                        // analyzerTable.add(new Column<String>("Property"));
     827                        analyzerTable
     828                        .add(new Column<String>("AnalyzerInformation"));
     829                        analyzerTable.add(new Column<String>("Value"));
     830                        SpectrumFileAnalyzerInterface analyzer = analyzerList
     831                        .get(j);
     832                        if (analyzer != null)
     833                        {
     834                            dataList = analyzer.getAnalyzer();
     835                            if (dataList != null)
     836                            {
     837                                for (int i = 0; i < dataList.size(); i++)
     838                                {
     839                                    StringPairInterface data = dataList.get(i);
     840                                    if (data != null)
     841                                    {
     842                                        String name = data.getName();
     843                                        String value = data.getValue();
     844                                        if (name != null && !name.equals(""))
     845                                        {
     846                                            analyzerTable.addRow(new PropertyRow(0, name, value, null));
     847                                        }
     848                                    }
     849                                }
     850                            }
     851                        }
     852                        instrumentFS.add(analyzerTable);
     853                    }
     854                }
     855                /*
     856                    Detector field.
     857                */
     858                Table detectorTable = new Table("DetectorInformation");
     859                // detectorTable.setTitle("DetectorInformation");
     860                // detectorTable.add(new Column<String>("Property"));
     861                detectorTable.add(new Column<String>("DetectorInformation"));
     862                detectorTable.add(new Column<String>("Value"));
     863                dataList = spectrumFileInstrument.getDetector();
     864                if (dataList != null)
     865                {
     866                    for (int i = 0; i < dataList.size(); i++)
     867                    {
     868                        StringPairInterface data = dataList.get(i);
     869                        if (data != null)
     870                        {
     871                            String name = data.getName();
     872                            String value = data.getValue();
     873                            if (name != null && !name.equals(""))
     874                            {
     875                                detectorTable.addRow(new PropertyRow(0, name, value, null));
     876                            }
     877                        }
     878                    }
     879                }
     880                instrumentFS.add(detectorTable);
     881                /*
     882                    Additional field.
     883                */
     884                Table additionalTable = new Table("AdditionalInformation");
     885                additionalTable.add(new Column<String>("AdditionalInformation"));
     886                additionalTable.add(new Column<String>("Value"));
     887                dataList = spectrumFileInstrument.getAdditional();
     888                if (dataList != null)
     889                {
     890                    for (int i = 0; i < dataList.size(); i++)
     891                    {
     892                        StringPairInterface data = dataList.get(i);
     893                        if (data != null)
     894                        {
     895                            String name = data.getName();
     896                            String value = data.getValue();
     897                            if (name != null && !name.equals(""))
     898                            {
     899                                additionalTable.addRow(new PropertyRow(0, name, value, null));
     900                            }
     901                        }
     902                    }
     903                }
     904                instrumentFS.add(additionalTable);
     905            }
     906            /***********************************************************************
     907                Form
     908            */
     909            Form form = new Form("InstrumentInformation");
     910            form.addFieldset(instrumentFS);
     911            return form;
     912        }
     913    }
  • trunk/client/servlet/src/org/proteios/gui/form/FormFactory.java

    r3943 r3945  
    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        
     70                       
    7171    private Localizer locale = null;
    7272    private String forwardActionId = null;
     
    160160    private static final org.apache.log4j.Logger log = org.apache.log4j.LogManager
    161161    .getLogger("org.proteios.gui.form");
    162                        
     162                                       
    163163    public void setActionFactory(ActionFactory af)
    164164    {
    165165        this.actionFactory = af;
    166166    }
    167                        
     167                                       
    168168    public String getForwardActionId()
    169169    {
    170170        return this.forwardActionId;
    171171    }
    172                        
     172                                       
    173173    public void setForwardActionId(String forwardActionId)
    174174    {
    175175        this.forwardActionId = forwardActionId;
    176176    }
    177                        
     177                                       
    178178    public HttpServletRequest getRequest()
    179179    {
    180180        return request;
    181181    }
    182                        
     182                                       
    183183    public void setRequest(HttpServletRequest request)
    184184    {
    185185        this.request = request;
    186186    }
    187                        
     187                                       
    188188    public void modifyForPopup(Fieldset fs)
    189189    {
    190190        actionFactory.modifyForPopup(fs);
    191191    }
    192                        
     192                                       
    193193    private FileField newFileField()
    194194    {
     
    197197        return fileF;
    198198    }
    199                        
     199                                       
    200200    public TextField<Integer> newIdField()
    201201    {
     
    205205        return idF;
    206206    }
    207                        
     207                                       
    208208    public TextField<String> newValueField(String setValueMethodName,
    209209    Class<?> valueClass)
     
    237237        return valueF;
    238238    }
    239                        
     239                                       
    240240    public TextField<Integer> newHiddenItemIdField()
    241241    {
     
    243243        return field;
    244244    }
    245                        
     245                                       
    246246    private TextField<Integer> newHiddenIntegerField(VInteger vInteger)
    247247    {
     
    250250        return field;
    251251    }
    252                        
     252                                       
    253253    private TextField<String> newHiddenStringField(VString vString)
    254254    {
     
    257257        return field;
    258258    }
    259                        
     259                                       
    260260    public <D extends BasicItem<?>, E extends ProteiosAction<?>> Form getAnnotationsForm(
    261261    DbControl dc, D item, Class<E> forwardAction)
     
    307307        return form;
    308308    }
    309                        
     309                                       
    310310    /**
    311311        @return Hidden
     
    317317        return field;
    318318    }
    319                        
     319                                       
    320320    /**
    321321        Form for user preferences configuration settings. Arguments
     
    323323        holders for current values for the notification configuration and table
    324324        preferences configuration form fields.
    325                                                
     325                                                                               
    326326        @param nc NotificationConfiguration object (need not be stored in
    327327        database) with default field values.
     
    341341        return form;
    342342    }
    343                        
     343                                       
    344344    /**
    345345        Fieldset for notification configuration settings. Argument
    346346        NotificationConfiguration is place holder for current values for the
    347347        notification configuration form fields.
    348                                                
     348                                                                               
    349349        @param nc NotificationConfiguration object (need not be stored in
    350350        database) with default field values.
     
    398398        return properties;
    399399    }
    400                        
     400                                       
    401401    /**
    402402        Creates a select box for notification mode.
    403                                                
     403                                                                               
    404404        @param modeValue int Mode value for default selection.
    405405        @return Select<VInteger> Select box for notification mode selection
     
    426426        return modeS;
    427427    }
    428                        
     428                                       
    429429    /**
    430430        Fieldset for table preferences configuration settings. Argument
    431431        TablePreferencesConfiguration is place holder for current values for the
    432432        table preferences configuration form fields.
    433                                                
     433                                                                               
    434434        @param tpc TablePreferencesConfiguration object (need not be stored in
    435435        database) with default field values.
     
    461461        return properties;
    462462    }
    463                        
     463                                       
    464464    /**
    465465        Creates a select box for table preferences mode.
    466                                                
     466                                                                               
    467467        @param modeValue int Mode value for default selection.
    468468        @return Select<VInteger> Select box for table preferences mode selection
     
    489489        return modeS;
    490490    }
    491                        
     491                                       
    492492    /**
    493493        @param a annotation
     
    502502        return sb.toString();
    503503    }
    504        
     504                       
    505505    /**
    506506        This will probably be removed when fixint #691
     
    601601        return form;
    602602    }
    603                        
     603                                       
    604604    /**
    605605        @param hit Current Hit
     
    817817        return form;
    818818    }
    819                        
     819                                       
    820820    /**
    821821        Returns a form for selecting spectrum mass range limits.
    822                                                
     822                                                                               
    823823        @param massCutoffLow String The lower cutoff mass value.
    824824        @param massCutoffHigh String The upper cutoff mass value.
     
    866866        return form;
    867867    }
    868                        
     868                                       
    869869    /**
    870870        Returns a form with spectrum properties for a spectrum obtained from a
    871871        spectrum file.
    872                                                
     872                                                                               
    873873        @param spectrumFile File Core file with spectrum.
    874874        @param spectrumId String Spectrum id string.
     
    10791079        return form;
    10801080    }
    1081                        
    1082     /**
    1083         Returns a form with spectrum file instrument data for a spectrum file.
    1084                                                
    1085         @param spectrumFileInstrumentList List<SpectrumFileInstrumentInterface>
    1086         Spectrum file instrument list.
    1087         @return Form for displaying spectrum file instrument data.
    1088     */
    1089     public Form getSpectrumFileInstrumentForm(
    1090     List<SpectrumFileInstrumentInterface> spectrumFileInstrumentList)
    1091     {
    1092         if (spectrumFileInstrumentList == null || spectrumFileInstrumentList
    1093         .size() == 0)
    1094         {
    1095             return null;
    1096         }
    1097         /***********************************************************************
    1098             Instrument fieldset
    1099         */
    1100         Fieldset instrumentFS = new Fieldset();
    1101         int instrumentNo = 0;
    1102         for (SpectrumFileInstrumentInterface spectrumFileInstrument : spectrumFileInstrumentList)
    1103         {
    1104             instrumentNo++;
    1105             List<StringPairInterface> dataList;
    1106             /*
    1107                 Name field.
    1108             */
    1109             Table instrumentGeneralTable = new Table(
    1110             "InstrumentGeneralInformation");
    1111             // Only print table header for first table
    1112             if (instrumentNo == 1)
    1113             {
    1114                 instrumentGeneralTable.setTitle("InstrumentInformation");
    1115             }
    1116             // instrumentGeneralTable.add(new Column<String>("Property"));
    1117             instrumentGeneralTable.add(new Column<String>("InstrumentGeneral"));
    1118             instrumentGeneralTable.add(new Column<String>("Value"));
    1119             String instrumentName = null;
    1120             if (spectrumFileInstrument != null)
    1121             {
    1122                 instrumentName = spectrumFileInstrument.getInstrumentName();
    1123             }
    1124             addTableRow(instrumentGeneralTable, "InstrumentName",
    1125             instrumentName, null, 0);
    1126             // instrumentFS.add(instrumentGeneralTable);
    1127             /*
    1128                 Serial No field.
    1129             */
    1130             String instrumentSerialNo = null;
    1131             if (spectrumFileInstrument != null)
    1132             {
    1133                 instrumentSerialNo = spectrumFileInstrument
    1134                 .getInstrumentSerialNo();
    1135             }
    1136             addTableRow(instrumentGeneralTable, "InstrumentSerialNo",
    1137             instrumentSerialNo, null, 0);
    1138             instrumentFS.add(instrumentGeneralTable);
    1139             /*
    1140                 Source field.
    1141             */
    1142             Table sourceTable = new Table("SourceInformation");
    1143             // sourceTable.setTitle("SourceInformation");
    1144             // sourceTable.add(new Column<String>("Property"));
    1145             sourceTable.add(new Column<String>("SourceInformation"));
    1146             sourceTable.add(new Column<String>("Value"));
    1147             dataList = spectrumFileInstrument.getSource();
    1148             if (dataList != null)
    1149             {
    1150                 for (int i = 0; i < dataList.size(); i++)
    1151                 {
    1152                     StringPairInterface data = dataList.get(i);
    1153                     if (data != null)
    1154                     {
    1155                         String name = data.getName();
    1156                         String value = data.getValue();
    1157                         if (name != null && !name.equals(""))
    1158                         {
    1159                             addTableRow(sourceTable, name, value, null, 0);
    1160                         }
    1161                     }
    1162                 }
    1163             }
    1164             instrumentFS.add(sourceTable);
    1165             /*
    1166                 AnalyzerList field.
    1167             */
    1168             List<SpectrumFileAnalyzerInterface> analyzerList = spectrumFileInstrument
    1169             .getAnalyzers();
    1170             if (analyzerList != null)
    1171             {
    1172                 for (int j = 0; j < analyzerList.size(); j++)
    1173                 {
    1174                     Table analyzerTable = new Table("AnalyzerListInformation");
    1175                     /*
    1176                         // Only add table title header for first table if (j ==
    1177                         0) { analyzerTable.setTitle("AnalyzerListInformation"); }
    1178                     */
    1179                     // analyzerTable.add(new Column<String>("Property"));
    1180                     analyzerTable
    1181                     .add(new Column<String>("AnalyzerInformation"));
    1182                     analyzerTable.add(new Column<String>("Value"));
    1183                     SpectrumFileAnalyzerInterface analyzer = analyzerList
    1184                     .get(j);
    1185                     if (analyzer != null)
    1186                     {
    1187                         dataList = analyzer.getAnalyzer();
    1188                         if (dataList != null)
    1189                         {
    1190                             for (int i = 0; i < dataList.size(); i++)
    1191                             {
    1192                                 StringPairInterface data = dataList.get(i);
    1193                                 if (data != null)
    1194                                 {
    1195                                     String name = data.getName();
    1196                                     String value = data.getValue();
    1197                                     if (name != null && !name.equals(""))
    1198                                     {
    1199                                         addTableRow(analyzerTable, name, value,
    1200                                         null, 0);
    1201                                     }
    1202                                 }
    1203                             }
    1204                         }
    1205                     }
    1206                     instrumentFS.add(analyzerTable);
    1207                 }
    1208             }
    1209             /*
    1210                 Detector field.
    1211             */
    1212             Table detectorTable = new Table("DetectorInformation");
    1213             // detectorTable.setTitle("DetectorInformation");
    1214             // detectorTable.add(new Column<String>("Property"));
    1215             detectorTable.add(new Column<String>("DetectorInformation"));
    1216             detectorTable.add(new Column<String>("Value"));
    1217             dataList = spectrumFileInstrument.getDetector();
    1218             if (dataList != null)
    1219             {
    1220                 for (int i = 0; i < dataList.size(); i++)
    1221                 {
    1222                     StringPairInterface data = dataList.get(i);
    1223                     if (data != null)
    1224                     {
    1225                         String name = data.getName();
    1226                         String value = data.getValue();
    1227                         if (name != null && !name.equals(""))
    1228                         {
    1229                             addTableRow(detectorTable, name, value, null, 0);
    1230                         }
    1231                     }
    1232                 }
    1233             }
    1234             instrumentFS.add(detectorTable);
    1235             /*
    1236                 Additional field.
    1237             */
    1238             Table additionalTable = new Table("AdditionalInformation");
    1239             // additionalTable.setTitle("AdditionalInformation");
    1240             // additionalTable.add(new Column<String>("Property"));
    1241             additionalTable.add(new Column<String>("AdditionalInformation"));
    1242             additionalTable.add(new Column<String>("Value"));
    1243             dataList = spectrumFileInstrument.getAdditional();
    1244             if (dataList != null)
    1245             {
    1246                 for (int i = 0; i < dataList.size(); i++)
    1247                 {
    1248                     StringPairInterface data = dataList.get(i);
    1249                     if (data != null)
    1250                     {
    1251                         String name = data.getName();
    1252                         String value = data.getValue();
    1253                         if (name != null && !name.equals(""))
    1254                         {
    1255                             addTableRow(additionalTable, name, value, null, 0);
    1256                         }
    1257                     }
    1258                 }
    1259             }
    1260             instrumentFS.add(additionalTable);
    1261         }
    1262         /***********************************************************************
    1263             Form
    1264         */
    1265         Form form = new Form("InstrumentInformation");
    1266         form.addFieldset(instrumentFS);
    1267         return form;
    1268     }
    1269                        
     1081                                       
    12701082    /**
    12711083        Adds a table row to a table. A "value" argument that is null will be
    12721084        represented as an empty string, otherwise by its toString() value.
    1273                                                
     1085                                                                               
    12741086        @param table Table The table to add a row to.
    12751087        @param nameKey String Property key string.
     
    13081120        table.addRow(row);
    13091121    }
    1310                        
     1122                                       
    13111123    /**
    13121124        Returns a form with spectrum file contact data for a spectrum file.
    1313                                                
     1125                                                                               
    13141126        @param spectrumContact Spectrum file contact
    13151127        data.
     
    13941206        return form;
    13951207    }
    1396                            
     1208                                           
    13971209    /**
    13981210        Returns a form for adding spectrum file sample data for a spectrum file.
    1399                                                
     1211                                                                               
    14001212        @param project Project The project in whose directory a new output
    14011213        directory is created.
     
    14871299        return form;
    14881300    }
    1489                        
     1301                                       
    14901302    private <D extends Object> TextField<D> newTextField(String name, D value)
    14911303    {
     
    14961308        return field;
    14971309    }
    1498                        
     1310                                       
    14991311    public Form getPeakListSetForm(PeakListSet pls)
    15001312    {
     
    15641376        return form;
    15651377    }
    1566                        
    1567                        
     1378                                       
    15681379    private void addAnnotationsAsFields(Fieldset to, Annotatable item,
    15691380    DbControl dc)
     
    15801391        }
    15811392    }
    1582                        
     1393                                       
    15831394    public Fieldset getProteinAssemblyFieldset(Project project)
    15841395    {
     
    16031414        return properties;
    16041415    }
    1605                        
     1416                                       
    16061417    public Select<VString> selectLocalSampleIdWithAllOption(DbControl dc,
    16071418    Project project)
     
    16171428        return select;
    16181429    }
    1619                        
     1430                                       
    16201431    private Select<VInteger> newSelectLabel(LabeledExtract le, DbControl dc)
    16211432    {
     
    16381449        return select;
    16391450    }
    1640                        
     1451                                       
    16411452    /**
    16421453        Creates and adds a hidden field with an Integer value to the given form.
     
    16501461        form.getFieldsets().get(0).add(field);
    16511462    }
    1652                        
     1463                                       
    16531464    /**
    16541465        Creates and adds a hidden field with an Integer value to the given table.
     
    16621473        table.add(field);
    16631474    }
    1664                        
     1475                                       
    16651476    public Fieldset getUsedSampleFieldset(Sample sample)
    16661477    {
     
    16801491        return fs;
    16811492    }
    1682                        
     1493                                       
    16831494    public Fieldset getUsedExtractFieldset(Extract extract)
    16841495    {
     
    16951506        return fs;
    16961507    }
    1697                        
     1508                                       
    16981509    public Fieldset getUsedLabeledExtractFieldset(LabeledExtract extract)
    16991510    {
     
    17131524        return fs;
    17141525    }
    1715                        
     1526                                       
    17161527    public Form getSecondaryLabeledExtractForm(LabeledExtract extract,
    17171528    DbControl dc, LabeledExtract fromExtract)
     
    17761587        return form;
    17771588    }
    1778 
     1589               
    17791590    public TextField<Float> newOriginalQuantityField()
    17801591    {
     
    17841595        return field;
    17851596    }
    1786                        
     1597                                       
    17871598    public TextField<Float> newRemainingQuantityField(Float remainingQuantity)
    17881599    {
     
    17951606        return field;
    17961607    }
    1797                        
     1608                                       
    17981609    private Localizer getLocale()
    17991610    {
    18001611        return locale;
    18011612    }
    1802                        
     1613                                       
    18031614    public void setLocale(Localizer locale)
    18041615    {
    18051616        this.locale = locale;
    18061617    }
    1807                        
     1618                                       
    18081619    //Cleaning up from here       
    1809                    
     1620                                   
    18101621    /**
    18111622        Form for new Protocol item. The difference between calling
     
    18181629        a convenient place holder for default values for the Protocol form
    18191630        fields.
    1820                                                
     1631                                                                               
    18211632        @param protocol Protocol object (need not be stored in database) with
    18221633        default field values.
     
    19031714        return form;
    19041715    }
    1905                        
     1716                                       
    19061717    public Form getForm(Class<?> cls)
    19071718    {
     
    19931804            loginF.setDisabled(true);
    19941805            fs.add(fs.size()-2, loginF); // After the itemId field
    1995                                                            
     1806                                                                                                           
    19961807            TextField<String> emailF = new EmailField();
    19971808            fs.add(fs.size()-1, emailF);
    1998                                                                        
     1809                                                                                                                       
    19991810            TextField<String> phoneF = new PhoneField();
    20001811            fs.add(phoneF);
    2001                                                                        
     1812                                                                                                                       
    20021813            TextField<String> addressF = new AddressField();
    20031814            fs.add(addressF);
    2004                                                                        
     1815                                                                                                                       
    20051816            TextField<String> organisationF = new OrganisationField();
    20061817            fs.add(organisationF);
    2007                                                                        
     1818                                                                                                                       
    20081819            if (obj != null)
    20091820            {
     
    23362147        return form;
    23372148    }
    2338                        
     2149                                       
    23392150    /**
    23402151        Creates a select box for protocols. If the class for which the protocol
     
    23442155        if the protocol is tagged to be removed. However, no other protocols
    23452156        tagged to be removed should be included in the list.
    2346                                                
     2157                                                                               
    23472158        @param cls Class Class for which a protocol should be selected.
    23482159        @param obj Object Optional object with attached protocol for setting
     
    24512262        return protocolS;
    24522263    }
    2453                        
     2264                                       
    24542265    public void setSc(SessionControl sc)
    24552266    {
  • trunk/client/servlet/src/org/proteios/gui/table/Cell.java

    r2447 r3945  
    11/*
    2  $Id$
    3  
    4  Copyright (C) 2006, 2007 Gregory Vincic
    5  
    6  Files are copyright by their respective authors. The contributions to
    7  files where copyright is not explicitly stated can be traced with the
    8  source code revision system.
    9  
    10  This file is part of Proteios.
    11  Available at http://www.proteios.org/
    12  
    13  Proteios is free software; you can redistribute it and/or
    14  modify it under the terms of the GNU General Public License
    15  as published by the Free Software Foundation; either version 2
    16  of the License, or (at your option) any later version.
    17  
    18  Proteios is distributed in the hope that it will be useful,
    19  but WITHOUT ANY WARRANTY; without even the implied warranty of
    20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    21  GNU General Public License for more details.
    22  
    23  You should have received a copy of the GNU General Public License
    24  along with this program; if not, write to the Free Software
    25  Foundation, Inc., 59 Temple Place - Suite 330,
    26  Boston, MA  02111-1307, USA.
    27  */
     2    $Id$
     3                
     4    Copyright (C) 2006, 2007 Gregory Vincic
     5                
     6    Files are copyright by their respective authors. The contributions to
     7    files where copyright is not explicitly stated can be traced with the
     8    source code revision system.
     9                
     10    This file is part of Proteios.
     11    Available at http://www.proteios.org/
     12                
     13    Proteios is free software; you can redistribute it and/or
     14    modify it under the terms of the GNU General Public License
     15    as published by the Free Software Foundation; either version 2
     16    of the License, or (at your option) any later version.
     17                
     18    Proteios is distributed in the hope that it will be useful,
     19    but WITHOUT ANY WARRANTY; without even the implied warranty of
     20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     21    GNU General Public License for more details.
     22                
     23    You should have received a copy of the GNU General Public License
     24    along with this program; if not, write to the Free Software
     25    Foundation, Inc., 59 Temple Place - Suite 330,
     26    Boston, MA  02111-1307, USA.
     27*/
    2828package org.proteios.gui.table;
    2929
     
    3131
    3232/**
    33  * Describes a cell within a table.
    34  *
    35  * @author gregory
    36  */
     33    * Describes a cell within a table.
     34    *
     35    * @author gregory
     36*/
    3737public class Cell<D extends Object>
    3838{
    39   /**
    40    * Displayed in this cell
    41    */
    42   private D value = null;
    43   /**
    44    * Flag telling any converter that the value should be wrapped, default is
    45    * false.
    46    */
    47   private boolean wrap = false;
    48   /**
    49    * What happens when a user clicks the value in this column
    50    */
    51   private AbstractLink actionLink = null;
    52   /**
    53    * If clicking on this cell should invoke a javascript action
    54    */
    55   private String jsAction = null;
    56 
    57 
    58   public String getJsAction()
    59   {
    60     return jsAction;
    61   }
    62 
    63 
    64   public void setJsAction(String jsAction)
    65   {
    66     this.jsAction = jsAction;
    67   }
    68 
    69 
    70   public AbstractLink getActionLink()
    71   {
    72     return actionLink;
    73   }
    74 
    75 
    76   public void setActionLink(AbstractLink actionLink)
    77   {
    78     this.actionLink = actionLink;
    79   }
    80 
    81 
    82   public boolean isWrap()
    83   {
    84     return wrap;
    85   }
    86 
    87 
    88   public Cell<D> setWrap(boolean wrap)
    89   {
    90     this.wrap = wrap;
    91     return this;
    92   }
    93 
    94 
    95   public Cell(D value)
    96   {
    97     this.value = value;
    98   }
    99 
    100 
    101   public D getValue()
    102   {
    103     return value;
    104   }
    105 
    106 
    107   public void setValue(D value)
    108   {
    109     this.value = value;
    110   }
     39    /**
     40        * Displayed in this cell
     41    */
     42    private D value = null;
     43    /**
     44        * Flag telling any converter that the value should be wrapped, default is
     45        * false.
     46    */
     47    private boolean wrap = false;
     48    /**
     49        * What happens when a user clicks the value in this column
     50    */
     51    private AbstractLink actionLink = null;
     52    /**
     53        * If clicking on this cell should invoke a javascript action
     54    */
     55    private String jsAction = null;
     56               
     57    /**
     58        If true then the value within this cell should be translated before presented to the client. Default is false.
     59    */
     60    private boolean translate = false;
     61               
     62    /**
     63        @param translate true if you want the value within this cell should be translated before presented to the client.
     64    */
     65    public void setTranslate(boolean translate)
     66    {
     67        this.translate = translate;
     68    }
     69               
     70    /**
     71        @return true if the value within this cell should be translated, false otherwise.
     72    */
     73    public boolean getTranslate()
     74    {
     75        return this.translate;
     76    }
     77               
     78    public String getJsAction()
     79    {
     80        return jsAction;
     81    }
     82               
     83    public void setJsAction(String jsAction)
     84    {
     85        this.jsAction = jsAction;
     86    }
     87               
     88    public AbstractLink getActionLink()
     89    {
     90        return actionLink;
     91    }
     92               
     93    public void setActionLink(AbstractLink actionLink)
     94    {
     95        this.actionLink = actionLink;
     96    }
     97               
     98    public boolean isWrap()
     99    {
     100        return wrap;
     101    }
     102               
     103    public Cell<D> setWrap(boolean wrap)
     104    {
     105        this.wrap = wrap;
     106        return this;
     107    }
     108               
     109    public Cell(D value)
     110    {
     111        this.value = value;
     112    }
     113               
     114    public D getValue()
     115    {
     116        return value;
     117    }
     118               
     119    public void setValue(D value)
     120    {
     121        this.value = value;
     122    }
    111123}
Note: See TracChangeset for help on using the changeset viewer.