Changeset 3929


Ignore:
Timestamp:
Nov 1, 2010, 11:07:33 AM (13 years ago)
Author:
Gregory Vincic
Message:

Refs #698. Moved getTrashCanForm method out from FormFactory? and into action ViewHome? as that is the only place it's used.

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

Legend:

Unmodified
Added
Removed
  • trunk/client/servlet/src/org/proteios/action/read/ViewHome.java

    r3639 r3929  
    11/*
    2  $Id$
    3  
    4  Copyright (C) 2006 Gregory Vincic
    5  Copyright (C) 2007 Gregory Vincic, Olle Mansson
    6  
    7  Files are copyright by their respective authors. The contributions to
    8  files where copyright is not explicitly stated can be traced with the
    9  source code revision system.
    10  
    11  This file is part of Proteios.
    12  Available at http://www.proteios.org/
    13  
    14  Proteios is free software; you can redistribute it and/or
    15  modify it under the terms of the GNU General Public License
    16  as published by the Free Software Foundation; either version 2
    17  of the License, or (at your option) any later version.
    18  
    19  Proteios is distributed in the hope that it will be useful,
    20  but WITHOUT ANY WARRANTY; without even the implied warranty of
    21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    22  GNU General Public License for more details.
    23  
    24  You should have received a copy of the GNU General Public License
    25  along with this program; if not, write to the Free Software
    26  Foundation, Inc., 59 Temple Place - Suite 330,
    27  Boston, MA  02111-1307, USA.
    28  */
     2    $Id$
     3         
     4    Copyright (C) 2006 Gregory Vincic
     5    Copyright (C) 2007 Gregory Vincic, Olle Mansson
     6    Copyright (C) 2010 Gregory Vincic
     7         
     8    Files are copyright by their respective authors. The contributions to
     9    files where copyright is not explicitly stated can be traced with the
     10    source code revision system.
     11         
     12    This file is part of Proteios.
     13    Available at http://www.proteios.org/
     14         
     15    Proteios is free software; you can redistribute it and/or
     16    modify it under the terms of the GNU General Public License
     17    as published by the Free Software Foundation; either version 2
     18    of the License, or (at your option) any later version.
     19         
     20    Proteios is distributed in the hope that it will be useful,
     21    but WITHOUT ANY WARRANTY; without even the implied warranty of
     22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     23    GNU General Public License for more details.
     24         
     25    You should have received a copy of the GNU General Public License
     26    along with this program; if not, write to the Free Software
     27    Foundation, Inc., 59 Temple Place - Suite 330,
     28    Boston, MA  02111-1307, USA.
     29*/
    2930package org.proteios.action.read;
    3031
     32import java.util.Date;
    3133import org.proteios.AbstractLink;
    3234import org.proteios.ActionLink;
    3335import org.proteios.action.ActionFactory;
    3436import org.proteios.action.ProteiosAction;
     37import org.proteios.action.job.ViewJob;
    3538import org.proteios.action.project.ViewProject;
    36 import org.proteios.action.job.ViewJob;
    3739import org.proteios.action.write.EmptyTrash;
    3840import org.proteios.core.DbControl;
     
    4749import org.proteios.core.SpectrumSearch;
    4850import org.proteios.core.User;
     51import org.proteios.core.query.Expressions;
    4952import org.proteios.core.query.Hql;
    5053import org.proteios.core.query.Orders;
    51 import org.proteios.core.query.Expressions;
    5254import org.proteios.core.query.Restrictions;
    5355import org.proteios.gui.ColumnContainer;
     56import org.proteios.gui.Scroller;
    5457import org.proteios.gui.Title;
    5558import org.proteios.gui.Toolbar;
    56 import org.proteios.gui.Scroller;
    57 import org.proteios.gui.form.Form;
    58 import org.proteios.gui.form.FormFactory;
     59import org.proteios.gui.form.*;
    5960import org.proteios.gui.layout.RowLayout;
    6061import org.proteios.gui.table.Cell;
     
    6364import org.proteios.gui.table.Table;
    6465import org.proteios.gui.table.TableFactory;
    65 
    6666import se.lu.thep.waf.ActionException;
    6767import se.lu.thep.waf.constraints.InvalidParameterValue;
    68 
    69 import java.util.Date;
     68import se.lu.thep.waf.constraints.VInteger;
    7069
    7170public class ViewHome
    72     extends ProteiosAction<ViewHome>
     71extends ProteiosAction<ViewHome>
    7372{
    74   @Override
    75   public void runMe()
    76       throws ActionException, InvalidParameterValue
    77   {
    78     // Define
    79     DbControl dc;
    80     TableFactory tableFactory;
    81     ActionLink rowAction;
    82     QueryFactory queryFactory;
    83     User owner;
    84     ItemQuery<Project> projectQuery;
    85   ItemQuery<Message> messages;
    86     ActionFactory actionFactory;
    87   Table projectsTable, msgTable;
    88   Integer from, max;
    89  
    90 
    91   if(getOwner().isSystemItem())
    92   {
    93    setForwardTo(ViewRootHome.class);
    94    return;
    95   }
    96     dc = newDbControl();
    97     queryFactory = getQueryFactory();
    98     actionFactory = getActionFactory();
    99     tableFactory = getTableFactory();
    100   owner = super.getOwner();
    101     rowAction = actionFactory.getActionLink(ViewProject.class, "Enter");
    102     from = getValidInteger(Scroller.VFROM);
    103     max = getValidInteger(Scroller.VMAXRESULT);
    104 
    105     projectQuery = Project.getQuery();
    106     projectQuery.include(Include.SHARED);
    107     projectQuery.include(Include.MINE);
    108     projectQuery.restrict(Restrictions.neq(Hql.property("closed"),  Expressions.parameter("closed")));
    109     projectQuery.setParameter("closed", true, null);
    110 
    111   if(from != null)
    112   {
    113     tableFactory.setQueryFrom(from);
    114   }
    115   if(max != null)
    116   {
    117     tableFactory.setMaxResults(max);
    118   }
    119     tableFactory.setDbControl(dc);
    120     tableFactory.setItemClass(Project.class);
    121     tableFactory.setQuery(projectQuery);
    122     tableFactory.setColumnAction("Name", rowAction);
    123   tableFactory.setSelectCheckBoxColumnHidden(true);
    124     tableFactory.hideColumn("ProjectType");
    125     tableFactory.hideColumn("Closed");
    126 
    127     projectsTable = tableFactory.build();
    128     projectsTable.setTitle("Projects");
    129    
    130     msgTable = new Table("msgTable");
    131     msgTable.setTitle("LastServerMessages");
    132     msgTable.add(new Column<Date>("Date"));
    133     msgTable.add(new Column<String>("Title"));
    134     // Only show the five last items
    135     messages = Message.getQuery(owner);
    136     messages.order(Orders.desc(Hql.property("timeSent")));
    137     messages.setCacheResult(false);
    138     messages.setMaxResults(5);
    139     for (Message msg : messages.list(dc))
    140     {
    141       // Construct row
    142       String rowTitle = new String("message" + msg.getId());
    143       Row row = new Row(rowTitle);
    144       Cell<Date> dateCell = new Cell<Date>(msg.getTimeSent());
    145       Cell<String> titleCell = new Cell<String>(msg.getName());
    146       // Check if title cell should be coupled to action
    147       if (msg.getJob() != null)
    148       {
    149         // Add view action link to title cell
    150         ActionLink cellAction = getActionFactory().getActionLink(
    151           ViewJob.class, ViewJob.class.getName());
    152         cellAction.addParameter(FormFactory.VID, msg.getJob().getId());
    153         titleCell.setActionLink(cellAction);
    154       }
    155       row.addCell(dateCell);
    156       row.addCell(titleCell);
    157       msgTable.addRow(row);
    158     }
    159     /***********************************************************************
    160      * Count items to be removed
    161      */
    162     // Add number of removed items of each kind to accumulated count
    163     int count = 0;
    164     // Removed Directory items
    165     ItemQuery<Directory> dirQuery = queryFactory.select(Directory.class);
    166     EmptyTrash.filter(dirQuery);
    167     int dirCount = dirQuery.count(dc);
    168     count += dirCount;
    169     // Removed File items
    170     ItemQuery<File> fileQuery = queryFactory.select(File.class);
    171     EmptyTrash.filter(fileQuery);
    172     int fileCount = fileQuery.count(dc);
    173     count += fileCount;
    174     // Removed Job items
    175     ItemQuery<Job> jobQuery = queryFactory.select(Job.class);
    176     EmptyTrash.filter(jobQuery);
    177     int jobCount = jobQuery.count(dc);
    178     count += jobCount;
    179     // Removed SpectrumSearch items
    180     ItemQuery<SpectrumSearch> spectrumSearchQuery = queryFactory
    181       .select(SpectrumSearch.class);
    182     EmptyTrash.filter(spectrumSearchQuery);
    183     int spectrumSearchCount = spectrumSearchQuery.count(dc);
    184     count += spectrumSearchCount;
    185     /***********************************************************************
    186      * Form
    187      */
    188     Form form = getFormFactory().getTrashCanForm(dirCount, fileCount,
    189       jobCount, spectrumSearchCount);
    190     Toolbar tb = new Toolbar();
    191     ActionLink emptyButton = getActionFactory().getActionLink(
    192       EmptyTrash.class, "EmptyTrash");
    193     if (count == 0)
    194     {
    195       emptyButton.disable();
    196     }
    197     tb.add(emptyButton);
    198     form.setToolbar(tb);
    199     /***********************************************************************
    200      * Layout
    201      */
    202     RowLayout layout = getLayoutFactory().getRowLayout();
    203     layout.add(new Title("Home"));
    204     ColumnContainer cc = new ColumnContainer();
    205     cc.add(projectsTable);
    206     cc.add(form);
    207     layout.add(cc);
    208     layout.add(msgTable);
    209     setLayout(layout);
    210   }
     73       
     74    public static final VInteger VCOUNT = new VInteger("count", 0, true);
     75    public static final VInteger VDIRCOUNT = new VInteger("dirCount", 0, true);
     76    public static final VInteger VJOBCOUNT = new VInteger("jobCount", 0, true);
     77    public static final VInteger VSPECTRUMSEARCHCOUNT = new VInteger("spectrumSearchCount", 0, true);
     78       
     79    @Override
     80    public void runMe()
     81    throws ActionException, InvalidParameterValue
     82    {
     83        DbControl dc;
     84        TableFactory tableFactory;
     85        ActionLink rowAction;
     86        QueryFactory queryFactory;
     87        User owner;
     88        ItemQuery<Project> projectQuery;
     89        ItemQuery<Message> messages;
     90        ActionFactory actionFactory;
     91        Table projectsTable, msgTable;
     92        Integer from, max;
     93                 
     94    // The root user has a special home view
     95        if(getOwner().isSystemItem())
     96        {
     97            setForwardTo(ViewRootHome.class);
     98            return;
     99        }
     100        dc = newDbControl();
     101        queryFactory = getQueryFactory();
     102        actionFactory = getActionFactory();
     103        tableFactory = getTableFactory();
     104        owner = super.getOwner();
     105        rowAction = actionFactory.getActionLink(ViewProject.class, "Enter");
     106        from = getValidInteger(Scroller.VFROM);
     107        max = getValidInteger(Scroller.VMAXRESULT);
     108               
     109        projectQuery = Project.getQuery();
     110        projectQuery.include(Include.SHARED);
     111        projectQuery.include(Include.MINE);
     112        projectQuery.restrict(Restrictions.neq(Hql.property("closed"),  Expressions.parameter("closed")));
     113        projectQuery.setParameter("closed", true, null);
     114               
     115        if(from != null)
     116        {
     117            tableFactory.setQueryFrom(from);
     118        }
     119        if(max != null)
     120        {
     121            tableFactory.setMaxResults(max);
     122        }
     123        tableFactory.setDbControl(dc);
     124        tableFactory.setItemClass(Project.class);
     125        tableFactory.setQuery(projectQuery);
     126        tableFactory.setColumnAction("Name", rowAction);
     127        tableFactory.setSelectCheckBoxColumnHidden(true);
     128        tableFactory.hideColumn("ProjectType");
     129        tableFactory.hideColumn("Closed");
     130               
     131        projectsTable = tableFactory.build();
     132        projectsTable.setTitle("Projects");
     133                   
     134        msgTable = new Table("msgTable");
     135        msgTable.setTitle("LastServerMessages");
     136        msgTable.add(new Column<Date>("Date"));
     137        msgTable.add(new Column<String>("Title"));
     138        // Only show the five last items
     139        messages = Message.getQuery(owner);
     140        messages.order(Orders.desc(Hql.property("timeSent")));
     141        messages.setCacheResult(false);
     142        messages.setMaxResults(5);
     143        for (Message msg : messages.list(dc))
     144        {
     145            // Construct row
     146            String rowTitle = new String("message" + msg.getId());
     147            Row row = new Row(rowTitle);
     148            Cell<Date> dateCell = new Cell<Date>(msg.getTimeSent());
     149            Cell<String> titleCell = new Cell<String>(msg.getName());
     150            // Check if title cell should be coupled to action
     151            if (msg.getJob() != null)
     152            {
     153                // Add view action link to title cell
     154                ActionLink cellAction = getActionFactory().getActionLink(
     155                ViewJob.class, ViewJob.class.getName());
     156                cellAction.addParameter(FormFactory.VID, msg.getJob().getId());
     157                titleCell.setActionLink(cellAction);
     158            }
     159            row.addCell(dateCell);
     160            row.addCell(titleCell);
     161            msgTable.addRow(row);
     162        }
     163       
     164        // Add number of removed items of each kind to accumulated count
     165        int count = 0;
     166        // Removed Directory items
     167        ItemQuery<Directory> dirQuery = queryFactory.select(Directory.class);
     168        EmptyTrash.filter(dirQuery);
     169        int dirCount = dirQuery.count(dc);
     170        count += dirCount;
     171        // Removed File items
     172        ItemQuery<File> fileQuery = queryFactory.select(File.class);
     173        EmptyTrash.filter(fileQuery);
     174        int fileCount = fileQuery.count(dc);
     175        count += fileCount;
     176        // Removed Job items
     177        ItemQuery<Job> jobQuery = queryFactory.select(Job.class);
     178        EmptyTrash.filter(jobQuery);
     179        int jobCount = jobQuery.count(dc);
     180        count += jobCount;
     181        // Removed SpectrumSearch items
     182        ItemQuery<SpectrumSearch> spectrumSearchQuery = queryFactory
     183        .select(SpectrumSearch.class);
     184        EmptyTrash.filter(spectrumSearchQuery);
     185        int spectrumSearchCount = spectrumSearchQuery.count(dc);
     186        count += spectrumSearchCount;
     187       
     188        Form form = getTrashCanForm(dirCount, fileCount,
     189        jobCount, spectrumSearchCount);
     190        Toolbar tb = new Toolbar();
     191        ActionLink emptyButton = getActionFactory().getActionLink(
     192        EmptyTrash.class, "EmptyTrash");
     193        if (count == 0)
     194        {
     195            emptyButton.disable();
     196        }
     197        tb.add(emptyButton);
     198        form.setToolbar(tb);
     199        RowLayout layout = getLayoutFactory().getRowLayout();
     200        layout.add(new Title("Home"));
     201        ColumnContainer cc = new ColumnContainer();
     202        cc.add(projectsTable);
     203        cc.add(form);
     204        layout.add(cc);
     205        layout.add(msgTable);
     206        setLayout(layout);
     207    }
     208       
     209    private Form getTrashCanForm(Integer dirCount, Integer fileCount,
     210    Integer jobCount, Integer spectrumSearchCount)
     211    {
     212        Form form = new Form("trashCanForm");
     213        Fieldset fs = new Fieldset();
     214        fs.setTitle("Trash");
     215        form.addFieldset(fs);
     216        // Get total number of items to delete
     217        Integer count = 0;
     218        if (dirCount != null)
     219        {
     220            count += dirCount;
     221        }
     222        if (fileCount != null)
     223        {
     224            count += fileCount;
     225        }
     226        if (jobCount != null)
     227        {
     228            count += jobCount;
     229        }
     230        if (spectrumSearchCount != null)
     231        {
     232            count += spectrumSearchCount;
     233        }
     234        // Add info line(s) on number of items of each class to delete
     235        if (count == 0)
     236        {
     237            TextField<String> itemsCount = new DummyField();
     238            itemsCount.setLabel("Empty");
     239            itemsCount.setValue("");
     240            itemsCount.setDisabled(true);
     241            fs.add(itemsCount);
     242        }
     243        if (dirCount != null && dirCount > 0)
     244        {
     245            TextField<Integer> dirItemsCount = new TextField<Integer>(VDIRCOUNT);
     246            dirItemsCount.setLabel("Directories");
     247            dirItemsCount.setValue(dirCount);
     248            dirItemsCount.setDisabled(true);
     249            fs.add(dirItemsCount);
     250        }
     251        if (fileCount != null && fileCount > 0)
     252        {
     253            TextField<Integer> fileItemsCount = new TextField<Integer>(VCOUNT);
     254            fileItemsCount.setLabel("Files");
     255            fileItemsCount.setValue(fileCount);
     256            fileItemsCount.setDisabled(true);
     257            fs.add(fileItemsCount);
     258        }
     259        if (jobCount != null && jobCount > 0)
     260        {
     261            TextField<Integer> jobItemsCount = new TextField<Integer>(VJOBCOUNT);
     262            jobItemsCount.setLabel("Jobs");
     263            jobItemsCount.setValue(jobCount);
     264            jobItemsCount.setDisabled(true);
     265            fs.add(jobItemsCount);
     266        }
     267        if (spectrumSearchCount != null && spectrumSearchCount > 0)
     268        {
     269            TextField<Integer> spectrumSearchItemsCount = new TextField<Integer>(VSPECTRUMSEARCHCOUNT);
     270            spectrumSearchItemsCount.setLabel("SpectrumSearches");
     271            spectrumSearchItemsCount.setValue(spectrumSearchCount);
     272            spectrumSearchItemsCount.setDisabled(true);
     273            fs.add(spectrumSearchItemsCount);
     274        }
     275        return form;
     276    }
     277       
    211278}
  • trunk/client/servlet/src/org/proteios/gui/form/FormFactory.java

    r3928 r3929  
    124124    public static final VBoolean VISMICROTITREPLATE = new VBoolean("isMicrotitrePlate", false);
    125125    public static final VString VRANDOMSTRING = new VString("randomString", 1,15, true);
    126     public static final VInteger VCOUNT = new VInteger("count", 0, true);
    127     public static final VInteger VDIRCOUNT = new VInteger("dirCount", 0, true);
    128     public static final VInteger VJOBCOUNT = new VInteger("jobCount", 0, true);
    129     public static final VInteger VSPECTRUMSEARCHCOUNT = new VInteger("spectrumSearchCount", 0, true);
    130126    public static final VBoolean VREADONLYFORM = new VBoolean("readOnlyForm",false);
    131127    public static final VBoolean VCONFIRM = new VBoolean("confirm", false);
     
    29972993    }
    29982994   
    2999     public Form getTrashCanForm(Integer dirCount, Integer fileCount,
    3000     Integer jobCount, Integer spectrumSearchCount)
    3001     {
    3002         Form form = new Form("trashCanForm");
    3003         Fieldset fs = new Fieldset();
    3004         fs.setTitle("Trash");
    3005         form.addFieldset(fs);
    3006         // Get total number of items to delete
    3007         Integer count = 0;
    3008         if (dirCount != null)
    3009         {
    3010             count += dirCount;
    3011         }
    3012         if (fileCount != null)
    3013         {
    3014             count += fileCount;
    3015         }
    3016         if (jobCount != null)
    3017         {
    3018             count += jobCount;
    3019         }
    3020         if (spectrumSearchCount != null)
    3021         {
    3022             count += spectrumSearchCount;
    3023         }
    3024         // Add info line(s) on number of items of each class to delete
    3025         if (count == 0)
    3026         {
    3027             TextField<String> itemsCount = new DummyField();
    3028             itemsCount.setLabel("Empty");
    3029             itemsCount.setValue("");
    3030             itemsCount.setDisabled(true);
    3031             fs.add(itemsCount);
    3032         }
    3033         if (dirCount != null && dirCount > 0)
    3034         {
    3035             TextField<Integer> dirItemsCount = new TextField<Integer>(VDIRCOUNT);
    3036             dirItemsCount.setLabel("Directories");
    3037             dirItemsCount.setValue(dirCount);
    3038             dirItemsCount.setDisabled(true);
    3039             fs.add(dirItemsCount);
    3040         }
    3041         if (fileCount != null && fileCount > 0)
    3042         {
    3043             TextField<Integer> fileItemsCount = new TextField<Integer>(VCOUNT);
    3044             fileItemsCount.setLabel("Files");
    3045             fileItemsCount.setValue(fileCount);
    3046             fileItemsCount.setDisabled(true);
    3047             fs.add(fileItemsCount);
    3048         }
    3049         if (jobCount != null && jobCount > 0)
    3050         {
    3051             TextField<Integer> jobItemsCount = new TextField<Integer>(VJOBCOUNT);
    3052             jobItemsCount.setLabel("Jobs");
    3053             jobItemsCount.setValue(jobCount);
    3054             jobItemsCount.setDisabled(true);
    3055             fs.add(jobItemsCount);
    3056         }
    3057         if (spectrumSearchCount != null && spectrumSearchCount > 0)
    3058         {
    3059             TextField<Integer> spectrumSearchItemsCount = new TextField<Integer>(
    3060             VSPECTRUMSEARCHCOUNT);
    3061             spectrumSearchItemsCount.setLabel("SpectrumSearches");
    3062             spectrumSearchItemsCount.setValue(spectrumSearchCount);
    3063             spectrumSearchItemsCount.setDisabled(true);
    3064             fs.add(spectrumSearchItemsCount);
    3065         }
    3066         return form;
    3067     }
    30682995   
    30692996    public TextField<Float> newExtractQuantityField(Extract extract)
     
    31803107   
    31813108    /**
    3182         * Returnes a form for the given class. If obj is supplied the form is
    3183         * filled out with values from that object. obj.class must match cls. This
    3184         * method should only return forms for item classes. If cls is null or
    3185         * obj.class doesn't match cls it returnes the NullForm. Also if the given
    3186         * cls is not handled it returnes a NullForm.
     3109        Returnes a form for the given class. If obj is supplied the form is
     3110        filled out with values from that object. obj.class must match cls. This
     3111        method should only return forms for item classes. If cls is null or
     3112        obj.class doesn't match cls it returnes the NullForm. Also if the given
     3113        cls is not handled it returnes a NullForm.
    31873114    */
    31883115    public Form getForm(Class<?> cls, Object obj)
    31893116    {
    31903117        if (cls == null)
    3191         return new NullForm();
    3192         if (obj != null && !cls.equals(obj.getClass()))
    3193         return new NullForm();
     3118    {
     3119          return new NullForm();
     3120    }
     3121        if (obj != null && !cls.equals(obj.getClass()))
     3122    {
     3123          return new NullForm();
     3124    }
    31943125        // Create forms with prefilled values from the given object
    31953126        if (cls.equals(LabeledExtract.class))
Note: See TracChangeset for help on using the changeset viewer.