Changeset 2680 for molgenis_distro


Ignore:
Timestamp:
03/08/10 13:32:16 (2 years ago)
Author:
mswertz
Message:

Examples of custom command and inputs

Location:
molgenis_distro/3.3/handwritten/java/commands
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • molgenis_distro/3.3/handwritten/java/commands/MyCommand.java

    r2416 r2680  
    11package commands; 
    22 
    3 import java.util.ArrayList; 
     3import java.io.IOException; 
     4import java.io.PrintWriter; 
     5import java.text.ParseException; 
    46import java.util.List; 
    57 
     8import org.molgenis.framework.db.Database; 
    69import org.molgenis.framework.db.DatabaseException; 
    710import org.molgenis.framework.ui.FormModel; 
    8 import org.molgenis.framework.ui.commands.SimpleCommand; 
     11import org.molgenis.framework.ui.ScreenModel; 
     12import org.molgenis.framework.ui.ScreenModel.Show; 
     13import org.molgenis.framework.ui.commands.AddCommand; 
    914import org.molgenis.framework.ui.html.ActionInput; 
    1015import org.molgenis.framework.ui.html.HtmlInput; 
     16import org.molgenis.util.Tuple; 
    1117 
    12 public class MyCommand extends SimpleCommand 
     18import app.ui.ExperimentsForm; 
     19 
     20/** 
     21 * Customized version of the 'Add' command. 
     22 */ 
     23public class MyCommand extends AddCommand 
    1324{ 
    14         @Override 
    15         public List<HtmlInput> getActions() 
     25        public MyCommand(FormModel s) 
    1626        { 
    17                 List<HtmlInput> actions = new ArrayList<HtmlInput>(); 
    18                  
    19                 //ActionInput close = new ActionInput("close"); 
    20                 ///close.setIcon("path/to/image"); 
    21                 //close.setLabel("My Command Example"); 
    22                  
    23                 return actions; 
     27                //override the standard add function 
     28                super("edit_new", s); 
    2429        } 
    2530 
     
    2732        public List<HtmlInput> getInputs() throws DatabaseException 
    2833        { 
    29                 //no inputs here 
    30                 return null; 
     34                //reuse the inputs from Experiment 
     35                List<HtmlInput> inputs = new ExperimentsForm().getInputs(); 
     36                 
     37                //you could now replace some of these inputs with your own 
     38                //e.g. create a custom 'PubmedInput' 
     39                inputs.add(new PubmedInput("pubmed")); 
     40                 
     41                return inputs; 
    3142        } 
    32  
     43         
     44        @Override 
     45        public List<HtmlInput> getActions() 
     46        { 
     47                //get the standard inputs 
     48                List<HtmlInput> actions = super.getActions(); 
     49                 
     50                //add an extra button 
     51//              ActionInput close = new ActionInput("close"); 
     52//              close.setIcon("path/to/image"); 
     53//              close.setLabel("My Command Example"); 
     54//              actions.add(close); 
     55                 
     56                return actions; 
     57        } 
     58         
     59        @Override 
     60        public ScreenModel.Show handleRequest(Database db, Tuple request, PrintWriter downloadStream) throws ParseException, DatabaseException, IOException 
     61        { 
     62                Show result = super.handleRequest(db, request, downloadStream); 
     63                 
     64                //return SHOW_MAIN if this request should be handled in the main screen 
     65                //return SHOW_DIALOG if you want to keep the dialog open 
     66                return result; 
     67        } 
    3368} 
Note: See TracChangeset for help on using the changeset viewer.