View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
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.io.File;
16  
17  import com.eviware.soapui.impl.WorkspaceImpl;
18  import com.eviware.soapui.impl.wsdl.WsdlProject;
19  import com.eviware.soapui.impl.wsdl.support.HelpUrls;
20  import com.eviware.soapui.support.UISupport;
21  import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
22  import com.eviware.x.form.XFormDialog;
23  import com.eviware.x.form.XFormField;
24  import com.eviware.x.form.XFormFieldListener;
25  import com.eviware.x.form.support.ADialogBuilder;
26  import com.eviware.x.form.support.AField;
27  import com.eviware.x.form.support.AForm;
28  import com.eviware.x.form.support.AField.AFieldType;
29  
30  /***
31   * Action for creating a new WSDL project
32   * 
33   * @author Ole.Matzura
34   */
35  
36  public class NewWsdlProjectAction extends AbstractSoapUIAction<WorkspaceImpl>
37  {
38  	public static final String SOAPUI_ACTION_ID = "NewWsdlProjectAction";
39  	private XFormDialog dialog;
40  
41  	public NewWsdlProjectAction()
42     {
43        super("New WSDL Project", "Creates a new WSDL Project in this workspace"); 
44     }
45     
46  	public void perform( WorkspaceImpl workspace, Object param )
47  	{
48     	if( dialog == null )
49     	{
50  			dialog = ADialogBuilder.buildDialog( Form.class );
51  			dialog.setValue( Form.CREATEREQUEST, Boolean.toString( true ) );
52  			dialog.getFormField( Form.INITIALWSDL ).addFormFieldListener( new XFormFieldListener(){
53  
54  				public void valueChanged( XFormField sourceField, String newValue, String oldValue )
55  				{
56  					dialog.getFormField( Form.CREATEREQUEST ).setEnabled( newValue.trim().length() > 0 );
57  				}} );
58     	}
59     	else 
60     	{
61     		dialog.setValue( Form.PROJECTNAME, "" );
62     		dialog.setValue( Form.INITIALWSDL, "" );
63     	}
64     	
65     	while( dialog.show() )
66     	{
67     		try
68     		{
69     			String projectName = dialog.getValue( Form.PROJECTNAME ).trim();
70     			if( projectName.length() == 0 )
71     			{
72     				UISupport.showErrorMessage( "Missing name for project" );
73     			}
74     			else
75     			{
76  					WsdlProject project = dialog.getBooleanValue( Form.CREATEPROJECTFILE ) ? 
77  								workspace.createProject( projectName ) : workspace.createProject( projectName, null );
78  								
79  	   			if( project != null )
80  	            {
81  	   				String url = dialog.getValue( Form.INITIALWSDL ).trim();
82  	   				if( url.length() > 0 )
83  	   				{
84  	   					if( new File( url ).exists() )
85  	   						url = "file:" + url;
86  	   					
87  	      				project.importWsdl( url, dialog.getValue( Form.CREATEREQUEST ).equals( "true" ));
88  	   				}
89  	   				
90  	   			   UISupport.select(project);
91  	   			   break;
92  	            }
93     			}
94     		}
95     		catch (Exception ex)
96     		{
97     			UISupport.showErrorMessage( ex );
98     		}
99     	}
100 	}
101    
102    @AForm( name="New WSDL Project", description = "Creates a new WSDL Project in this workspace", 
103    			helpUrl=HelpUrls.NEWPROJECT_HELP_URL, icon=UISupport.TOOL_ICON_PATH)
104 	private class Form 
105 	{
106 		@AField(name = "Project Name", description = "The name of the project to create", type = AFieldType.STRING )
107 		public final static String PROJECTNAME = "Project Name";
108 		
109 		@AField(name = "Initial WSDL", description = "URL or filename of initial WSDL", type = AFieldType.FILE )
110 		public final static String INITIALWSDL = "Initial WSDL";
111 		
112 		@AField(name = "Create Requests", description = "Create sample requests for all operations?", 
113 					type = AFieldType.BOOLEAN, enabled = false )
114 		public final static String CREATEREQUEST = "Create Requests";
115 		
116 		@AField(name = "Create Project File", description = "Creates a file for the project (can always be created later)", 
117 					type = AFieldType.BOOLEAN )
118 		public final static String CREATEPROJECTFILE = "Create Project File";
119 	}
120 }