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.wsdl.actions.mockservice;
14  
15  import java.awt.event.ActionEvent;
16  
17  import com.eviware.soapui.impl.wsdl.actions.iface.AbstractSwingAction;
18  import com.eviware.soapui.impl.wsdl.mock.WsdlMockService;
19  import com.eviware.x.form.XFormDialog;
20  import com.eviware.x.form.support.ADialogBuilder;
21  import com.eviware.x.form.support.AField;
22  import com.eviware.x.form.support.AForm;
23  import com.eviware.x.form.support.AField.AFieldType;
24  
25  public class MockServiceOptionsAction extends AbstractSwingAction<WsdlMockService>
26  {
27  	private XFormDialog dialog;
28  
29  	public MockServiceOptionsAction( WsdlMockService modelItem )
30  	{
31  		super( "Options", "Sets options for this MockService", "/options.gif", modelItem );
32  	}
33  
34  	@Override
35  	public void actionPerformed( ActionEvent arg0, WsdlMockService mockService )
36  	{
37  		if( dialog == null )
38  			dialog = ADialogBuilder.buildDialog( OptionsForm.class );
39  
40  		dialog.setValue( OptionsForm.PATH, mockService.getPath() );
41  		dialog.setIntValue( OptionsForm.PORT, mockService.getPort() );
42  		
43  		boolean enabled = mockService.getMockRunner() == null;
44  		
45  		dialog.getFormField( OptionsForm.PATH ).setEnabled( enabled );
46  		dialog.getFormField( OptionsForm.PORT ).setEnabled( enabled );
47  		
48  		if( dialog.show() )
49  		{
50  			mockService.setPath( dialog.getValue( OptionsForm.PATH ) );
51  			mockService.setPort( dialog.getIntValue( OptionsForm.PORT, mockService.getPort() ) );
52  		}
53  	}
54  
55  	@AForm( name="MockService Options", description="Set options for this MockService" )
56  	private class OptionsForm
57  	{
58  		@AField( name="Path", description="The path this MockService will mount on")
59  		public final static String PATH = "Path";
60  
61  		@AField( name="Port", description="The port this MockService will mount on", type=AFieldType.INT )
62  		public final static String PORT = "Port";
63  	}
64  }