View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 eviware.com
    3    *
    4    *  soapUI is free software; you can redistribute it and/or modify it under the
    5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
    6    *  the Free Software Foundation.
    7    *
    8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
    9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    10   *  See the GNU Lesser General Public License for more details at gnu.org.
    11   */
    12
    13  package com.eviware.x.impl.swing;
    14
    15  import java.awt.event.ActionEvent;
    16
    17  import javax.swing.AbstractAction;
    18  import javax.swing.Action;
    19  import javax.swing.ImageIcon;
    20  import javax.swing.KeyStroke;
    21
    22  import com.eviware.soapui.support.HelpActionMarker;
    23  import com.eviware.soapui.support.Tools;
    24  import com.eviware.soapui.support.UISupport;
    25  import com.eviware.soapui.support.action.swing.ActionList;
    26  import com.eviware.soapui.support.action.swing.DefaultActionList;
    27  import com.eviware.x.form.XForm;
    28  import com.eviware.x.form.XFormDialog;
    29  import com.eviware.x.form.XFormDialogBuilder;
    30
    31  public class SwingXFormDialogBuilder extends XFormDialogBuilder
    32  {
    33     private String name;
    34  	private SwingXFormDialog dialog;
    35
    36     public SwingXFormDialogBuilder(String name)
    37     {
    38        this.name = name;
    39     }
    40
    41     public XForm createForm(String name)
    42     {
    43        XForm form = new SwingXFormImpl(name);
    44        addForm(form);
    45        return form;
    46     }
    47
    48     public XFormDialog buildDialog(ActionList actions, String description, ImageIcon icon )
    49     {
    50     	XForm[] forms = getForms();
    51  		dialog = forms.length > 1 ? new JTabbedFormDialog( name, forms, actions, description, icon ) :
    52  				new JFormDialog( name, forms[0], actions, description, icon );
    53
    54  		return dialog;
    55     }
    56
    57  	public ActionList buildOkCancelActions()
    58  	{
    59  		DefaultActionList actions = new DefaultActionList("Actions");
    60  		actions.addAction( new OKAction() );
    61  		actions.addAction( new CancelAction() );
    62  		return actions;
    63  	}
    64
    65  	public ActionList buildOkCancelHelpActions(String url)
    66  	{
    67  		DefaultActionList actions = new DefaultActionList("Actions");
    68  		actions.addAction( new HelpAction( url ));
    69  		actions.addAction( new OKAction() );
    70  		actions.addAction( new CancelAction() );
    71
    72  		return actions;
    73  	}
    74
    75  	protected final class OKAction extends AbstractAction
    76  	{
    77  		public OKAction()
    78  		{
    79  			super( "OK" );
    80  		}
    81
    82  		public void actionPerformed(ActionEvent e)
    83  		{
    84  			if( dialog != null )
    85  			{
    86  				dialog.setReturnValue( XFormDialog.OK_OPTION );
    87  				dialog.setVisible( false );
    88  			}
    89  		}
    90  	}
    91
    92  	protected final class CancelAction extends AbstractAction
    93  	{
    94  		public CancelAction()
    95  		{
    96  			super( "Cancel" );
    97  		}
    98
    99  		public void actionPerformed(ActionEvent e)
    100 		{
    101 			if( dialog != null )
    102 			{
    103 				dialog.setReturnValue( XFormDialog.CANCEL_OPTION );
    104 				dialog.setVisible( false );
    105 			}
    106 		}
    107 	}
    108
    109 	public final class HelpAction extends AbstractAction implements HelpActionMarker
    110 	{
    111 		private final String url;
    112
    113 		public HelpAction( String url )
    114 		{
    115 			this( "Online Help", url, UISupport.getKeyStroke( "F1" ) );
    116 		}
    117
    118 		public HelpAction( String title, String url )
    119 		{
    120 			this( title, url, null );
    121 		}
    122
    123 		public HelpAction( String title, String url, KeyStroke accelerator )
    124 	   {
    125 	      super( title );
    126 			this.url = url;
    127 	      putValue( Action.SHORT_DESCRIPTION, "Show online help" );
    128 	      if( accelerator != null )
    129 	      	putValue( Action.ACCELERATOR_KEY, accelerator );
    130
    131 	      putValue( Action.SMALL_ICON, UISupport.HELP_ICON );
    132 	   }
    133
    134 	   public void actionPerformed(ActionEvent e)
    135 		{
    136 	   	Tools.openURL( url );
    137 		}
    138 	}
    139 }