Changeset 3947


Ignore:
Timestamp:
Nov 4, 2010, 4:08:34 PM (13 years ago)
Author:
Gregory Vincic
Message:

Refs #698. Moved method getSpectrumFileContactForm from FormFactory to InspectActiveSpectrumFile.

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

Legend:

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

    r3945 r3947  
    11/*
    22    $Id$
    3                  
     3                            
    44    Copyright (C) 2009 Gregory Vincic
    5                
     5                           
    66    This file is part of Proteios.
    77    Available at http://www.proteios.org/
    8                
     8                           
    99    Proteios is free software; you can redistribute it and/or modify it
    1010    under the terms of the GNU General Public License as published by
    1111    the Free Software Foundation; either version 2 of the License, or
    1212    (at your option) any later version.
    13                
     13                           
    1414    Proteios is distributed in the hope that it will be useful, but
    1515    WITHOUT ANY WARRANTY; without even the implied warranty of
    1616    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1717    General Public License for more details.
    18                
     18                           
    1919    You should have received a copy of the GNU General Public License
    2020    along with this program; if not, write to the Free Software
     
    8585    private int itemsFrom = 0;
    8686    private boolean pageSelectedFromScroller = false;
    87                
     87                           
    8888    /**
    8989        * Get the max number of results to show in list.
     
    9595        return this.maxResults;
    9696    }
    97                
     97                           
    9898    /**
    9999        * Set the max number of results to show in list.
     
    106106        this.maxResults = maxResults;
    107107    }
    108                
     108                           
    109109    /**
    110110        * Get the item number to start from in the list.
     
    116116        return this.itemsFrom;
    117117    }
    118                
     118                           
    119119    /**
    120120        * Set the item number to start from in the list.
     
    127127        this.itemsFrom = itemsFrom;
    128128    }
    129                
     129                           
    130130    /**
    131131        * Get flag indicating that page is selected from scroller.
     
    137137        return this.pageSelectedFromScroller;
    138138    }
    139                
     139                           
    140140    /**
    141141        * Set flag indicating that page is selected from scroller.
     
    148148        this.pageSelectedFromScroller = pageSelectedFromScroller;
    149149    }
    150                
     150                           
    151151    @Override
    152152    protected void runMe()
     
    247247            {
    248248                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)
     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.*)?"))
    251253                    {
    252                         if (!spectrumId.matches("^d+(\\s-\\s.*)?"))
     254                        spectrumId = spectrumId.trim();
     255                        for (String s : spectrumIds)
    253256                        {
    254                             spectrumId = spectrumId.trim();
    255                             for (String s : spectrumIds)
     257                            String toMatch = s.substring(s.indexOf("-") + 2)
     258                            .trim();
     259                            if (spectrumId.equals(toMatch))
    256260                            {
    257                                 String toMatch = s.substring(s.indexOf("-") + 2)
    258                                 .trim();
    259                                 if (spectrumId.equals(toMatch))
     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 = getSpectrumFileContactForm(spectrumContact);
     550        }
     551        /***********************************************************************
     552            * Layout
     553        */
     554        // GridLayout layout = getLayoutFactory().getGridLayout(1, 2, 1, 1);
     555        RowLayout layout = getLayoutFactory().getRowLayout();
     556        // Adapt title to file type
     557        String titleHeader = spectrumFileReaderFactory
     558        .fetchFileTypeTitleString(file);
     559        Title title = new Title(titleHeader);
     560        title.setSubtitle("" + file.getName() + " [" + fileId + "]");
     561        layout.add(title);
     562        // Row container for plot and properties form
     563        RowContainer rc = new RowContainer();
     564        if (plotOriginal != null)
     565        {
     566            rc.add(plotOriginal);
     567        }
     568        rc.add(plot);
     569        rc.add(spectrumIterationForm);
     570        rc.add(massRangeSelectionForm);
     571        rc.add(propertiesForm);
     572        if (instrumentForm != null)
     573        {
     574            rc.add(instrumentForm);
     575        }
     576        if (contactForm != null)
     577        {
     578            rc.add(contactForm);
     579        }
     580        //
     581        ColumnContainer cc = new ColumnContainer();
     582        cc.add(peakListTable);
     583        if (plot != null || propertiesForm != null)
     584        {
     585            cc.add(rc);
     586        }
     587        layout.add(cc);
     588        //
     589        setLayout(layout);
     590        log.debug("End");
     591    }
     592                                               
     593    /**
     594        * Fetch index for item from from string list.
     595        *
     596        * @param currentItem String The current item.
     597        * @param inList List<String> The string list to use.
     598        * @return Integer The index for the item, or null if none.
     599    */
     600    public Integer fetchStringListItemIndex(String currentItem,
     601    List<String> inList)
     602    {
     603        log.debug("currentItem = \"" + currentItem + "\"");
     604        if (currentItem == null || inList == null)
     605        {
     606            return null;
     607        }
     608        log.debug("inList.size() = " + inList.size());
     609        // Find current index
     610        Integer currentIndex = null;
     611        for (int i = 0; i < inList.size(); i++)
     612        {
     613            String item = (String) inList.get(i);
     614            if (item != null)
     615            {
     616                if (item.equals(currentItem))
     617                {
     618                    currentIndex = i;
     619                    break;
     620                }
     621            }
     622        }
     623        log.debug("currentIndex = " + currentIndex);
     624        return currentIndex;
     625    }
     626                                               
     627    /**
     628        * Fetch previous list item from string list.
     629        *
     630        * @param currentItem String The current item.
     631        * @param inList List<String> The string list to use.
     632        * @return String The previous item, or null if none.
     633    */
     634    public String fetchPreviousListItem(String currentItem, List<String> inList)
     635    {
     636        log.debug("currentItem = \"" + currentItem + "\"");
     637        if (currentItem == null || inList == null)
     638        {
     639            return null;
     640        }
     641        log.debug("inList.size() = " + inList.size());
     642        // Find current index
     643        int currentIndex = -1;
     644        for (int i = 0; i < inList.size(); i++)
     645        {
     646            String item = (String) inList.get(i);
     647            if (item != null)
     648            {
     649                if (item.equals(currentItem))
     650                {
     651                    currentIndex = i;
     652                    break;
     653                }
     654            }
     655        }
     656        log.debug("currentIndex = " + currentIndex);
     657        // Find previous item
     658        String previousItem = null;
     659        if (currentIndex > 0)
     660        {
     661            previousItem = (String) inList.get(currentIndex - 1);
     662        }
     663        log.debug("previousItem = \"" + previousItem + "\"");
     664        return previousItem;
     665    }
     666                                               
     667    /**
     668        * Fetch next list item from string list.
     669        *
     670        * @param currentItem String The current item.
     671        * @param inList List<String> The string list to use.
     672        * @return String The next item, or null if none.
     673    */
     674    public String fetchNextListItem(String currentItem, List<String> inList)
     675    {
     676        log.debug("currentItem = \"" + currentItem + "\"");
     677        if (currentItem == null || inList == null)
     678        {
     679            return null;
     680        }
     681        log.debug("inList.size() = " + inList.size());
     682        // Find current index
     683        int currentIndex = -1;
     684        for (int i = 0; i < inList.size(); i++)
     685        {
     686            String item = (String) inList.get(i);
     687            if (item != null)
     688            {
     689                if (item.equals(currentItem))
     690                {
     691                    currentIndex = i;
     692                    break;
     693                }
     694            }
     695        }
     696        log.debug("currentIndex = " + currentIndex);
     697        // Find next item
     698        String nextItem = null;
     699        if (currentIndex < (inList.size() - 1))
     700        {
     701            nextItem = (String) inList.get(currentIndex + 1);
     702        }
     703        log.debug("nextItem = \"" + nextItem + "\"");
     704        return nextItem;
     705    }
     706                                               
     707    /**
     708        * Restores table scroller settings (stored as valid parameters).
     709    */
     710    private void restoreScrollerState()
     711    throws InvalidParameterValue
     712    {
     713        // Get scroller data from valid parameters set to table
     714        Integer scrollFrom = getValidInteger(Scroller.VFROM);
     715        Integer scrollMaxResults = getValidInteger(Scroller.VMAXRESULT);
     716        // Update scroller settings
     717        if (scrollFrom != null)
     718        {
     719            setItemsFrom(scrollFrom);
     720            setPageSelectedFromScroller(true);
     721        }
     722        if (scrollMaxResults != null)
     723        {
     724            setMaxResults(scrollMaxResults);
     725        }
     726        log
     727        .debug("scrollFrom = " + scrollFrom + " isPageSelectedFromScroller() = " + isPageSelectedFromScroller());
     728        log.debug("scrollMaxResults = " + scrollMaxResults);
     729    }
     730                                               
     731    /**
     732        Returns a form with spectrum file instrument data for a spectrum file.
     733                                                                                                                           
     734        @param spectrumFileInstrumentList List<SpectrumFileInstrumentInterface>
     735        Spectrum file instrument list.
     736        @return Form for displaying spectrum file instrument data.
     737    */
     738    public Form getSpectrumFileInstrumentForm(
     739    List<SpectrumFileInstrumentInterface> spectrumFileInstrumentList)
     740    {
     741        if (spectrumFileInstrumentList == null || spectrumFileInstrumentList
     742        .size() == 0)
     743        {
     744            return null;
     745        }
     746        /***********************************************************************
     747            Instrument fieldset
     748        */
     749        Fieldset instrumentFS = new Fieldset();
     750        int instrumentNo = 0;
     751        for (SpectrumFileInstrumentInterface spectrumFileInstrument : spectrumFileInstrumentList)
     752        {
     753            instrumentNo++;
     754            List<StringPairInterface> dataList;
     755            /*
     756                Name field.
     757            */
     758            Table instrumentGeneralTable = new Table(
     759            "InstrumentGeneralInformation");
     760            // Only print table header for first table
     761            if (instrumentNo == 1)
     762            {
     763                instrumentGeneralTable.setTitle("InstrumentInformation");
     764            }
     765            // instrumentGeneralTable.add(new Column<String>("Property"));
     766            instrumentGeneralTable.add(new Column<String>("InstrumentGeneral"));
     767            instrumentGeneralTable.add(new Column<String>("Value"));
     768            String instrumentName = null;
     769            if (spectrumFileInstrument != null)
     770            {
     771                instrumentName = spectrumFileInstrument.getInstrumentName();
     772            }
     773            instrumentGeneralTable.addRow(new PropertyRow(0, "InstrumentName", instrumentName, null));
     774            /*
     775                Serial No field.
     776            */
     777            String instrumentSerialNo = null;
     778            if (spectrumFileInstrument != null)
     779            {
     780                instrumentSerialNo = spectrumFileInstrument
     781                .getInstrumentSerialNo();
     782            }
     783            instrumentGeneralTable.addRow(new PropertyRow(0, "InstrumentSerialNo", instrumentSerialNo, null));
     784            instrumentFS.add(instrumentGeneralTable);
     785            /*
     786                Source field.
     787            */
     788            Table sourceTable = new Table("SourceInformation");
     789            // sourceTable.setTitle("SourceInformation");
     790            // sourceTable.add(new Column<String>("Property"));
     791            sourceTable.add(new Column<String>("SourceInformation"));
     792            sourceTable.add(new Column<String>("Value"));
     793            dataList = spectrumFileInstrument.getSource();
     794            if (dataList != null)
     795            {
     796                for (int i = 0; i < dataList.size(); i++)
     797                {
     798                    StringPairInterface data = dataList.get(i);
     799                    if (data != null)
     800                    {
     801                        String name = data.getName();
     802                        String value = data.getValue();
     803                        if (name != null && !name.equals(""))
     804                        {
     805                            sourceTable.addRow(new PropertyRow(0, name, value, null));
     806                        }
     807                    }
     808                }
     809            }
     810            instrumentFS.add(sourceTable);
     811            /*
     812                AnalyzerList field.
     813            */
     814            List<SpectrumFileAnalyzerInterface> analyzerList = spectrumFileInstrument
     815            .getAnalyzers();
     816            if (analyzerList != null)
     817            {
     818                for (int j = 0; j < analyzerList.size(); j++)
     819                {
     820                    Table analyzerTable = new Table("AnalyzerListInformation");
     821                    /*
     822                        // Only add table title header for first table if (j ==
     823                        0) { analyzerTable.setTitle("AnalyzerListInformation"); }
     824                    */
     825                    // analyzerTable.add(new Column<String>("Property"));
     826                    analyzerTable
     827                    .add(new Column<String>("AnalyzerInformation"));
     828                    analyzerTable.add(new Column<String>("Value"));
     829                    SpectrumFileAnalyzerInterface analyzer = analyzerList
     830                    .get(j);
     831                    if (analyzer != null)
     832                    {
     833                        dataList = analyzer.getAnalyzer();
     834                        if (dataList != null)
     835                        {
     836                            for (int i = 0; i < dataList.size(); i++)
     837                            {
     838                                StringPairInterface data = dataList.get(i);
     839                                if (data != null)
    260840                                {
    261                                     log.debug("Found spectrum:"+s);
    262                                     spectrumId = s;
    263                                     setSessionAttribute(PlotFileSpectrum.VSPECTRUMID.getName(), spectrumId);
    264                                     break;
     841                                    String name = data.getName();
     842                                    String value = data.getValue();
     843                                    if (name != null && !name.equals(""))
     844                                    {
     845                                        analyzerTable.addRow(new PropertyRow(0, name, value, null));
     846                                    }
    265847                                }
    266848                            }
    267849                        }
    268850                    }
     851                    instrumentFS.add(analyzerTable);
    269852                }
    270                 else
     853            }
     854            /*
     855                Detector field.
     856            */
     857            Table detectorTable = new Table("DetectorInformation");
     858            // detectorTable.setTitle("DetectorInformation");
     859            // detectorTable.add(new Column<String>("Property"));
     860            detectorTable.add(new Column<String>("DetectorInformation"));
     861            detectorTable.add(new Column<String>("Value"));
     862            dataList = spectrumFileInstrument.getDetector();
     863            if (dataList != null)
     864            {
     865                for (int i = 0; i < dataList.size(); i++)
    271866                {
    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(""))
     867                    StringPairInterface data = dataList.get(i);
     868                    if (data != null)
    286869                    {
    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)
     870                        String name = data.getName();
     871                        String value = data.getValue();
     872                        if (name != null && !name.equals(""))
    292873                        {
    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);
     874                            detectorTable.addRow(new PropertyRow(0, name, value, null));
    299875                        }
    300876                    }
    301877                }
    302                 // Add scroller
    303                 int count = spectrumIds.size();
    304                 if (count > getMaxResults())
     878            }
     879            instrumentFS.add(detectorTable);
     880            /*
     881                Additional field.
     882            */
     883            Table additionalTable = new Table("AdditionalInformation");
     884            additionalTable.add(new Column<String>("AdditionalInformation"));
     885            additionalTable.add(new Column<String>("Value"));
     886            dataList = spectrumFileInstrument.getAdditional();
     887            if (dataList != null)
     888            {
     889                for (int i = 0; i < dataList.size(); i++)
    305890                {
    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)
     891                    StringPairInterface data = dataList.get(i);
     892                    if (data != null)
    393893                    {
    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)
     894                        String name = data.getName();
     895                        String value = data.getValue();
     896                        if (name != null && !name.equals(""))
    801897                        {
    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                             }
     898                            additionalTable.addRow(new PropertyRow(0, name, value, null));
    808899                        }
    809900                    }
    810901                }
    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     }
     902            }
     903            instrumentFS.add(additionalTable);
     904        }
     905        /***********************************************************************
     906            Form
     907        */
     908        Form form = new Form("InstrumentInformation");
     909        form.addFieldset(instrumentFS);
     910        return form;
     911    }
     912               
     913    /**
     914        Returns a form with spectrum file contact data for a spectrum file.
     915                                                                                                                   
     916        @param spectrumContact Spectrum file contact
     917        data.
     918        @return Form for displaying spectrum file contact data.
     919    */
     920    public Form getSpectrumFileContactForm(
     921    SpectrumFileContactInterface spectrumContact)
     922    {
     923        if (spectrumContact == null)
     924        {
     925            return null;
     926        }
     927        /***********************************************************************
     928            Contact fieldset
     929        */
     930        Fieldset contactFS = new Fieldset();
     931        //
     932        Table contactTable = new Table("ContactInformation");
     933        contactTable.setTitle("ContactInformation");
     934        contactTable.add(new Column<String>("Property"));
     935        contactTable.add(new Column<String>("Value"));
     936        contactFS.add(contactTable);
     937        /*
     938            Name
     939        */
     940        String name = null;
     941        if (spectrumContact != null)
     942        {
     943            name = spectrumContact.getName();
     944        }
     945        contactTable.addRow(new PropertyRow(0 , "Name", name));
     946        /*
     947            Institution
     948        */
     949        String institution = null;
     950        if (spectrumContact != null)
     951        {
     952            institution = spectrumContact.getInstitution();
     953        }
     954        contactTable.addRow( new PropertyRow(0, "Institution", institution));
     955        /*
     956            ContactInfo
     957        */
     958        String contactInfo = null;
     959        if (spectrumContact != null)
     960        {
     961            contactInfo = spectrumContact.getContactInfo();
     962        }
     963        contactTable.addRow( new PropertyRow(0, "ContactInfo", contactInfo));
     964        /*
     965            Address
     966        */
     967        String address = null;
     968        if (spectrumContact != null)
     969        {
     970            address = spectrumContact.getAddress();
     971        }
     972        contactTable.addRow( new PropertyRow(0, "Address", address));
     973        /*
     974            URL
     975        */
     976        String url = null;
     977        if (spectrumContact != null)
     978        {
     979            url = spectrumContact.getUrl();
     980        }
     981        contactTable.addRow( new PropertyRow(0, "URL", url));
     982        /*
     983            Email
     984        */
     985        String email = null;
     986        if (spectrumContact != null)
     987        {
     988            email = spectrumContact.getEmail();
     989        }
     990        contactTable.addRow( new PropertyRow(0, "Email", email));
     991        /***********************************************************************
     992            Form
     993        */
     994        Form form = new Form("ContactInformation");
     995        form.addFieldset(contactFS);
     996        return form;
     997    }
     998               
     999}
  • trunk/client/servlet/src/org/proteios/gui/form/FormFactory.java

    r3946 r3947  
    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.
     
    10781078        return form;
    10791079    }
    1080                                            
    1081     /**
    1082         Returns a form with spectrum file contact data for a spectrum file.
    1083                                                                                        
    1084         @param spectrumContact Spectrum file contact
    1085         data.
    1086         @return Form for displaying spectrum file contact data.
    1087     */
    1088     public Form getSpectrumFileContactForm(
    1089     SpectrumFileContactInterface spectrumContact)
    1090     {
    1091         if (spectrumContact == null)
    1092         {
    1093             return null;
    1094         }
    1095         /***********************************************************************
    1096             Contact fieldset
    1097         */
    1098         Fieldset contactFS = new Fieldset();
    1099         //
    1100         Table contactTable = new Table("ContactInformation");
    1101         contactTable.setTitle("ContactInformation");
    1102         contactTable.add(new Column<String>("Property"));
    1103         contactTable.add(new Column<String>("Value"));
    1104         contactFS.add(contactTable);
    1105         /*
    1106             Name
    1107         */
    1108         String name = null;
    1109         if (spectrumContact != null)
    1110         {
    1111             name = spectrumContact.getName();
    1112         }
    1113         contactTable.addRow(new PropertyRow(0 , "Name", name));
    1114         /*
    1115             Institution
    1116         */
    1117         String institution = null;
    1118         if (spectrumContact != null)
    1119         {
    1120             institution = spectrumContact.getInstitution();
    1121         }
    1122         contactTable.addRow( new PropertyRow(0, "Institution", institution));
    1123         /*
    1124             ContactInfo
    1125         */
    1126         String contactInfo = null;
    1127         if (spectrumContact != null)
    1128         {
    1129             contactInfo = spectrumContact.getContactInfo();
    1130         }
    1131         contactTable.addRow( new PropertyRow(0, "ContactInfo", contactInfo));
    1132         /*
    1133             Address
    1134         */
    1135         String address = null;
    1136         if (spectrumContact != null)
    1137         {
    1138             address = spectrumContact.getAddress();
    1139         }
    1140         contactTable.addRow( new PropertyRow(0, "Address", address));
    1141         /*
    1142             URL
    1143         */
    1144         String url = null;
    1145         if (spectrumContact != null)
    1146         {
    1147             url = spectrumContact.getUrl();
    1148         }
    1149         contactTable.addRow( new PropertyRow(0, "URL", url));
    1150         /*
    1151             Email
    1152         */
    1153         String email = null;
    1154         if (spectrumContact != null)
    1155         {
    1156             email = spectrumContact.getEmail();
    1157         }
    1158         contactTable.addRow( new PropertyRow(0, "Email", email));
    1159         /***********************************************************************
    1160             Form
    1161         */
    1162         Form form = new Form("ContactInformation");
    1163         form.addFieldset(contactFS);
    1164         return form;
    1165     }
    1166                                                
     1080                                                   
    11671081    /**
    11681082        Returns a form for adding spectrum file sample data for a spectrum file.
    1169                                                                                        
     1083                                                                                               
    11701084        @param project Project The project in whose directory a new output
    11711085        directory is created.
     
    12571171        return form;
    12581172    }
    1259                                            
     1173                                               
    12601174    private <D extends Object> TextField<D> newTextField(String name, D value)
    12611175    {
     
    12661180        return field;
    12671181    }
    1268                                            
     1182                                               
    12691183    public Form getPeakListSetForm(PeakListSet pls)
    12701184    {
     
    13341248        return form;
    13351249    }
    1336                                            
     1250                                               
    13371251    private void addAnnotationsAsFields(Fieldset to, Annotatable item,
    13381252    DbControl dc)
     
    13491263        }
    13501264    }
    1351                                            
     1265                                               
    13521266    public Fieldset getProteinAssemblyFieldset(Project project)
    13531267    {
     
    13721286        return properties;
    13731287    }
    1374                                            
     1288                                               
    13751289    public Select<VString> selectLocalSampleIdWithAllOption(DbControl dc,
    13761290    Project project)
     
    13861300        return select;
    13871301    }
    1388                                            
     1302                                               
    13891303    private Select<VInteger> newSelectLabel(LabeledExtract le, DbControl dc)
    13901304    {
     
    14071321        return select;
    14081322    }
    1409                                            
     1323                                               
    14101324    /**
    14111325        Creates and adds a hidden field with an Integer value to the given form.
     
    14191333        form.getFieldsets().get(0).add(field);
    14201334    }
    1421                                            
     1335                                               
    14221336    /**
    14231337        Creates and adds a hidden field with an Integer value to the given table.
     
    14311345        table.add(field);
    14321346    }
    1433                                            
     1347                                               
    14341348    public Fieldset getUsedSampleFieldset(Sample sample)
    14351349    {
     
    14491363        return fs;
    14501364    }
    1451                                            
     1365                                               
    14521366    public Fieldset getUsedExtractFieldset(Extract extract)
    14531367    {
     
    14641378        return fs;
    14651379    }
    1466                                            
     1380                                               
    14671381    public Fieldset getUsedLabeledExtractFieldset(LabeledExtract extract)
    14681382    {
     
    14821396        return fs;
    14831397    }
    1484                                            
     1398                                               
    14851399    public Form getSecondaryLabeledExtractForm(LabeledExtract extract,
    14861400    DbControl dc, LabeledExtract fromExtract)
     
    15451459        return form;
    15461460    }
    1547                    
     1461                       
    15481462    public TextField<Float> newOriginalQuantityField()
    15491463    {
     
    15531467        return field;
    15541468    }
    1555                                            
     1469                                               
    15561470    public TextField<Float> newRemainingQuantityField(Float remainingQuantity)
    15571471    {
     
    15641478        return field;
    15651479    }
     1480                                               
     1481    private Localizer getLocale()
     1482    {
     1483        return locale;
     1484    }
     1485                                               
     1486    public void setLocale(Localizer locale)
     1487    {
     1488        this.locale = locale;
     1489    }
     1490                                               
     1491    //Cleaning up from here       
    15661492                                           
    1567     private Localizer getLocale()
    1568     {
    1569         return locale;
    1570     }
    1571                                            
    1572     public void setLocale(Localizer locale)
    1573     {
    1574         this.locale = locale;
    1575     }
    1576                                            
    1577     //Cleaning up from here       
    1578                                        
    15791493    /**
    15801494        Form for new Protocol item. The difference between calling
     
    15871501        a convenient place holder for default values for the Protocol form
    15881502        fields.
    1589                                                                                        
     1503                                                                                               
    15901504        @param protocol Protocol object (need not be stored in database) with
    15911505        default field values.
     
    16721586        return form;
    16731587    }
    1674                                            
     1588                                               
    16751589    public Form getForm(Class<?> cls)
    16761590    {
     
    17621676            loginF.setDisabled(true);
    17631677            fs.add(fs.size()-2, loginF); // After the itemId field
    1764                                                                                                                        
     1678                                                                                                                                   
    17651679            TextField<String> emailF = new EmailField();
    17661680            fs.add(fs.size()-1, emailF);
    1767                                                                                                                                    
     1681                                                                                                                                               
    17681682            TextField<String> phoneF = new PhoneField();
    17691683            fs.add(phoneF);
    1770                                                                                                                                    
     1684                                                                                                                                               
    17711685            TextField<String> addressF = new AddressField();
    17721686            fs.add(addressF);
    1773                                                                                                                                    
     1687                                                                                                                                               
    17741688            TextField<String> organisationF = new OrganisationField();
    17751689            fs.add(organisationF);
    1776                                                                                                                                    
     1690                                                                                                                                               
    17771691            if (obj != null)
    17781692            {
     
    21052019        return form;
    21062020    }
    2107                                            
     2021                                               
    21082022    /**
    21092023        Creates a select box for protocols. If the class for which the protocol
     
    21132027        if the protocol is tagged to be removed. However, no other protocols
    21142028        tagged to be removed should be included in the list.
    2115                                                                                        
     2029                                                                                               
    21162030        @param cls Class Class for which a protocol should be selected.
    21172031        @param obj Object Optional object with attached protocol for setting
     
    22202134        return protocolS;
    22212135    }
    2222                                            
     2136                                               
    22232137    public void setSc(SessionControl sc)
    22242138    {
Note: See TracChangeset for help on using the changeset viewer.