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