1
2
3
4
5
6
7
8
9
10
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 : PathUtils.getExpandedResourceRoot( modelItem ) );
81 if( file != null )
82 {
83 setFile( file );
84 }
85 }
86 }
87 }