1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.actions;
14
15 import java.io.File;
16
17 import com.eviware.soapui.impl.WorkspaceImpl;
18 import com.eviware.soapui.impl.wsdl.WsdlProject;
19 import com.eviware.soapui.support.UISupport;
20 import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
21 import com.eviware.x.form.XFormDialog;
22 import com.eviware.x.form.XFormField;
23 import com.eviware.x.form.XFormFieldListener;
24 import com.eviware.x.form.support.ADialogBuilder;
25 import com.eviware.x.form.support.AField;
26 import com.eviware.x.form.support.AForm;
27 import com.eviware.x.form.support.AField.AFieldType;
28
29 /***
30 * Action for creating a new WSDL project
31 *
32 * @author Ole.Matzura
33 */
34
35 public class NewWsdlProjectAction extends AbstractSoapUIAction<WorkspaceImpl>
36 {
37 public static final String SOAPUI_ACTION_ID = "NewWsdlProjectAction";
38 private XFormDialog dialog;
39
40 public NewWsdlProjectAction()
41 {
42 super("New WSDL Project", "Creates a new WSDL Project in this workspace");
43 }
44
45 public void perform( WorkspaceImpl workspace, Object param )
46 {
47 if( dialog == null )
48 {
49 dialog = ADialogBuilder.buildDialog( Form.class );
50 dialog.setValue( Form.CREATEREQUEST, Boolean.toString( true ) );
51 dialog.getFormField( Form.INITIALWSDL ).addFormFieldListener( new XFormFieldListener(){
52
53 public void valueChanged( XFormField sourceField, String newValue, String oldValue )
54 {
55 dialog.getFormField( Form.CREATEREQUEST ).setEnabled( newValue.trim().length() > 0 );
56 }} );
57 }
58 else
59 {
60 dialog.setValue( Form.PROJECTNAME, "" );
61 dialog.setValue( Form.INITIALWSDL, "" );
62 }
63
64 if( dialog.show() )
65 {
66 try
67 {
68 WsdlProject project = workspace.createProject( dialog.getValue( Form.PROJECTNAME ));
69 if( project != null )
70 {
71 String url = dialog.getValue( Form.INITIALWSDL ).trim();
72 if( url.length() > 0 )
73 {
74 if( new File( url ).exists() )
75 url = "file:" + url;
76
77 project.importWsdl( url, dialog.getValue( Form.CREATEREQUEST ).equals( "true" ));
78 }
79
80 UISupport.select(project);
81 }
82 }
83 catch (Exception ex)
84 {
85 UISupport.showErrorMessage( ex );
86 }
87 }
88 }
89
90 @AForm( name="New WSDL Project", description = "Creates a new WSDL Project in this workspace")
91 private class Form
92 {
93 @AField(name = "Project Name", description = "The name of the project to create", type = AFieldType.STRING )
94 public final static String PROJECTNAME = "Project Name";
95
96 @AField(name = "Initial WSDL", description = "URL or filename of initial WSDL", type = AFieldType.FILE )
97 public final static String INITIALWSDL = "Initial WSDL";
98
99 @AField(name = "Create Requests", description = "Create sample requests for all operations?",
100 type = AFieldType.BOOLEAN, enabled = false )
101 public final static String CREATEREQUEST = "Create Requests";
102 }
103
104
105 }