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.soapui.support.components;
    14
    15  import java.awt.event.ActionEvent;
    16  import java.io.File;
    17
    18  import javax.swing.AbstractAction;
    19  import javax.swing.JButton;
    20  import javax.swing.JPanel;
    21  import javax.swing.JTextField;
    22
    23  import com.eviware.soapui.support.UISupport;
    24  import com.jgoodies.forms.builder.ButtonBarBuilder;
    25
    26  public class FileFormComponent extends JPanel implements JFormComponent
    27  {
    28  	private JTextField textField;
    29
    30  	public FileFormComponent( String tooltip )
    31  	{
    32  		ButtonBarBuilder builder = new ButtonBarBuilder( this );
    33  		textField = new JTextField( 30 );
    34  		textField.setToolTipText( tooltip );
    35  		builder.addGriddedGrowing( textField );
    36  		builder.addRelatedGap();
    37  		builder.addFixed( new JButton( new SelectDirectoryAction()) );
    38  	}
    39
    40  	public void setValue(String value)
    41  	{
    42  		textField.setText( value );
    43  	}
    44
    45  	public JTextField getTextField()
    46  	{
    47  		return textField;
    48  	}
    49
    50  	public String getValue()
    51  	{
    52  		return textField.getText();
    53  	}
    54
    55  	public class SelectDirectoryAction extends AbstractAction
    56  	{
    57  		public SelectDirectoryAction()
    58  		{
    59  			super( "Browse..." );
    60  		}
    61
    62  		public void actionPerformed(ActionEvent e)
    63  		{
    64           File file = UISupport.getFileDialogs().open(this, "Select file", null, null, null );
    65           if( file != null )
    66  		   {
    67  		     	textField.setText( file.getAbsolutePath());
    68  		   }
    69  		}
    70  	}
    71  }