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.wsdl.panels.mockoperation.actions;
14  
15  import java.awt.event.ActionEvent;
16  
17  import javax.swing.Action;
18  
19  import com.eviware.soapui.impl.wsdl.WsdlOperation;
20  import com.eviware.soapui.impl.wsdl.WsdlRequest;
21  import com.eviware.soapui.impl.wsdl.actions.iface.AbstractSwingAction;
22  import com.eviware.soapui.impl.wsdl.mock.WsdlMockOperation;
23  import com.eviware.soapui.model.support.ModelSupport;
24  import com.eviware.soapui.settings.WsdlSettings;
25  import com.eviware.soapui.support.UISupport;
26  
27  public class OpenRequestForMockOperationAction extends AbstractSwingAction<WsdlMockOperation>
28  {
29  	public OpenRequestForMockOperationAction( WsdlMockOperation mockOperation )
30  	{
31  		super( "Open Request", "Opens/Creates a request for this MockOperation with correct endpoint", mockOperation );
32  		putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/open_request.gif" ) );
33  	}
34  
35  	public void actionPerformed( ActionEvent arg0, WsdlMockOperation mockOperation)
36  	{
37  		WsdlOperation operation = mockOperation.getOperation();
38  		if( operation == null )
39  		{
40  			UISupport.showErrorMessage( "Missing operation for this mock response" );
41  			return;
42  		}
43  		
44  		String[] names = ModelSupport.getNames( operation.getRequests(), new String[] { "-> Create New" } );
45  		
46  		String name = ( String ) UISupport.prompt(  "Select Request for Operation [" + operation.getName() + "] " +
47  				"to open or create", "Open Request", names );
48  		if( name != null )
49  		{
50  			WsdlRequest request = operation.getRequestByName( name );
51  			if( request == null )
52  			{
53  				name = UISupport.prompt( "Specify name of new request", "Open Request", "Request " + (operation.getRequestCount()+1 ));
54  				if( name == null )
55  					return;
56  				
57  			   boolean createOptional = operation.getSettings().getBoolean(WsdlSettings.XML_GENERATION_ALWAYS_INCLUDE_OPTIONAL_ELEMENTS);
58  		      if (!createOptional)
59  		    	  createOptional =  UISupport.confirm(	"Create optional elements from schema?", "Create Request" );
60  		      
61  		      request = operation.addNewRequest( name );
62  		      String requestContent = operation.createRequest( createOptional );
63  		      if(requestContent != null)
64  		      {
65  		      	request.setRequestContent( requestContent );
66  		      }
67  			}
68  			
69  			request.setEndpoint( mockOperation.getMockService().getLocalEndpoint() );
70  			UISupport.selectAndShow( request );
71  		}
72  	}
73  }