1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.actions.project;
14
15 import java.awt.event.ActionEvent;
16
17 import javax.swing.AbstractAction;
18 import javax.swing.Action;
19 import javax.swing.JFileChooser;
20
21 import com.eviware.soapui.SoapUI;
22 import com.eviware.soapui.impl.wsdl.WsdlProject;
23 import com.eviware.soapui.model.iface.Interface;
24 import com.eviware.soapui.support.ExtensionFileFilter;
25
26 /***
27 * Adds a WsdlInterface to a WsdlProject from a wsdl file
28 *
29 * @author Ole.Matzura
30 */
31
32 public class AddInterfaceActionFromFile extends AbstractAction
33 {
34 private JFileChooser chooser;
35 private final WsdlProject project;
36
37 public AddInterfaceActionFromFile( WsdlProject project )
38 {
39 super( "Add WSDL from file" );
40 this.project = project;
41 putValue( Action.SHORT_DESCRIPTION, "Adds all interfaces in a specified local WSDL file to the current project" );
42 }
43
44 public JFileChooser getChooser()
45 {
46 if( chooser == null )
47 {
48 chooser = new JFileChooser();
49 chooser.setDialogTitle("Select WSDL file");
50 chooser.setAcceptAllFileFilterUsed( true );
51 chooser.setFileFilter( new ExtensionFileFilter( ".wsdl", "WSDL Files (*.wsdl)"));
52 }
53
54 return chooser;
55 }
56
57 public void actionPerformed(ActionEvent e)
58 {
59 JFileChooser chooser = getChooser();
60 if( chooser.showOpenDialog( SoapUI.getInstance().getFrame() ) != JFileChooser.APPROVE_OPTION ) return;
61 String url = chooser.getSelectedFile().getAbsolutePath();
62 if( url == null ) return;
63
64 Interface[] ifaces = project.importWsdl( "file:" + url );
65 if( ifaces.length > 0 )
66 SoapUI.getInstance().selectModelItem( ifaces[0] );
67 }
68 }