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 import java.io.File;
17
18 import javax.swing.AbstractAction;
19 import javax.swing.Action;
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.UISupport;
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 final WsdlProject project;
35
36 public AddInterfaceActionFromFile( WsdlProject project )
37 {
38 super( "Add WSDL from File" );
39 this.project = project;
40 putValue( Action.SHORT_DESCRIPTION, "Adds all interfaces in a specified local WSDL file to the current project" );
41 putValue( Action.ACCELERATOR_KEY, UISupport.getKeyStroke( "menu F" ));
42 }
43
44 public void actionPerformed(ActionEvent e)
45 {
46 File file = UISupport.getFileDialogs().open(this, "Select WSDL file",
47 ".wsdl", "WSDL Files (*.wsdl)");
48 if( file == null ) return;
49
50 String url = file.getAbsolutePath();
51 if( url == null ) return;
52
53 try
54 {
55 Boolean createRequests = UISupport.confirmOrCancel( "Create default requests for all operations", "Import WSDL" );
56 if( createRequests == null )
57 return;
58
59 Interface[] ifaces = project.importWsdl("file:" + url, createRequests );
60 if ( ifaces.length > 0)
61 SoapUI.selectModelItem(ifaces[0]);
62 }
63 catch (Exception ex)
64 {
65 UISupport.showErrorMessage( ex.getMessage() + ":" + ex.getCause() );
66 }
67 }
68 }