View Javadoc

1   /*
2    *  soapUI, copyright (C) 2006 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.actions;
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.WorkspaceImpl;
23  import com.eviware.soapui.impl.wsdl.WsdlProject;
24  import com.eviware.soapui.support.UISupport;
25  import com.eviware.x.form.XFormDialog;
26  import com.eviware.x.form.XFormField;
27  import com.eviware.x.form.XFormFieldListener;
28  import com.eviware.x.form.support.ADialogBuilder;
29  import com.eviware.x.form.support.AField;
30  import com.eviware.x.form.support.AForm;
31  import com.eviware.x.form.support.AField.AFieldType;
32  
33  /***
34   * Actions for creating a new WSDL project
35   * 
36   * @author Ole.Matzura
37   */
38  
39  public class NewWsdlProjectAction extends AbstractAction
40  {
41  	private final WorkspaceImpl workspace;
42  	private XFormDialog dialog;
43  
44  	public NewWsdlProjectAction( WorkspaceImpl workspace )
45     {
46        super("New WSDL Project");
47  		this.workspace = workspace;
48        
49        putValue( Action.SHORT_DESCRIPTION, "Creates a new WSDL Project in this workspace"); 
50        putValue( Action.ACCELERATOR_KEY, UISupport.getKeyStroke( "menu N"));
51     }
52     
53     public void actionPerformed(ActionEvent e)
54  	{
55     	if( dialog == null )
56     	{
57  			dialog = ADialogBuilder.buildDialog( Form.class );
58  			dialog.setValue( Form.CREATEREQUEST, Boolean.toString( true ) );
59  			dialog.getFormField( Form.INITIALWSDL ).addFormFieldListener( new XFormFieldListener(){
60  
61  				public void valueChanged( XFormField sourceField, String newValue, String oldValue )
62  				{
63  					dialog.getFormField( Form.CREATEREQUEST ).setEnabled( newValue.trim().length() > 0 );
64  				}} );
65     	}
66     	else 
67     	{
68     		dialog.setValue( Form.PROJECTNAME, "" );
69     		dialog.setValue( Form.INITIALWSDL, "" );
70     	}
71     	
72     	if( dialog.show() )
73     	{
74     		try
75     		{
76     			WsdlProject project = workspace.createProject( dialog.getValue( Form.PROJECTNAME ));
77     			if( project != null )
78              {
79     				String url = dialog.getValue( Form.INITIALWSDL ).trim();
80     				if( url.length() > 0 )
81     				{
82     					if( new File( url ).exists() )
83     						url = "file:" + url;
84     					
85        				project.importWsdl( url, dialog.getValue( Form.CREATEREQUEST ).equals( "true" ));
86     				}
87     				
88     			   SoapUI.selectModelItem(project);
89              }
90     		}
91     		catch (Exception ex)
92     		{
93     			UISupport.showErrorMessage( ex );
94     		}
95     	}
96  	}
97     
98     @AForm( name="New WSDL Project", description = "Creates a new WSDL Project in this workspace")
99  	private class Form 
100 	{
101 		@AField(name = "Project Name", description = "The name of the project ot create", type = AFieldType.STRING )
102 		public final static String PROJECTNAME = "Project Name";
103 		
104 		@AField(name = "Initial WSDL", description = "URL or filename of initial WSDL", type = AFieldType.FILE )
105 		public final static String INITIALWSDL = "Initial WSDL";
106 		
107 		@AField(name = "Create Requests", description = "Create sample requests for all operations?", 
108 					type = AFieldType.BOOLEAN, enabled = false )
109 		public final static String CREATEREQUEST = "Create Requests";
110 	}
111 }