View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 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.impl.wsdl.AbstractWsdlModelItem;
24  import com.eviware.soapui.impl.wsdl.support.PathUtils;
25  import com.eviware.soapui.support.StringUtils;
26  import com.eviware.soapui.support.UISupport;
27  import com.jgoodies.forms.builder.ButtonBarBuilder;
28  
29  public class FileFormComponent extends JPanel implements JFormComponent
30  {
31  	private JTextField textField;
32  	private AbstractWsdlModelItem<?> modelItem;
33  
34  	public FileFormComponent( String tooltip )
35  	{
36  		ButtonBarBuilder builder = new ButtonBarBuilder( this );
37  		textField = new JTextField( 30 );
38  		textField.setToolTipText( tooltip );
39  		builder.addGriddedGrowing( textField );
40  		builder.addRelatedGap();
41  		builder.addFixed( new JButton( new SelectFileAction()) );
42  	}
43  	
44  	public void setValue(String value)
45  	{
46  		textField.setText( value );
47  	}
48  
49  	public JTextField getTextField()
50  	{
51  		return textField;
52  	}
53  
54  	public String getValue()
55  	{
56  		return textField.getText();
57  	}
58  	
59  	public void setFile( File file )
60  	{
61  		setValue( file.getAbsolutePath() );
62  	}
63  	
64  	public void setModelItem( AbstractWsdlModelItem<?> modelItem )
65  	{
66  		this.modelItem = modelItem;
67  	}
68  	
69  	public class SelectFileAction extends AbstractAction
70  	{
71  		public SelectFileAction()
72  		{
73  			super( "Browse..." );
74  		}
75  		
76  		public void actionPerformed(ActionEvent e)
77  		{
78           String value = FileFormComponent.this.getValue();
79  			File file = UISupport.getFileDialogs().open(this, "Select file", null, null, 
80           		StringUtils.hasContent( value ) ? value : 
81           		PathUtils.getExpandedResourceRoot(modelItem)
82  			);
83           if( file != null )
84  		   {
85  		     	setFile( file );
86  		   }
87  		}
88  	}
89  }