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