View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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.SoapUI;
18  import com.eviware.soapui.impl.WorkspaceImpl;
19  import com.eviware.soapui.support.MessageSupport;
20  import com.eviware.soapui.support.SoapUIException;
21  import com.eviware.soapui.support.UISupport;
22  import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
23  
24  /***
25   * Action to swtich the current workspace
26   * 
27   * @author ole.matzura
28   */
29  
30  public class SwitchWorkspaceAction extends AbstractSoapUIAction<WorkspaceImpl>
31  {
32  	public static final String SOAPUI_ACTION_ID = "SwitchWorkspaceAction";
33  	public static final MessageSupport messages = MessageSupport.getMessages( SwitchWorkspaceAction.class );
34  
35  	public SwitchWorkspaceAction()
36  	{
37  		super( messages.get( "SwitchWorkspaceAction.Title" ), messages.get( "SwitchWorkspaceAction.Description" ) );
38  	}
39  
40  	public void perform( WorkspaceImpl workspace, Object param )
41  	{
42  		if( SoapUI.getTestMonitor().hasRunningTests() )
43  		{
44  			UISupport.showErrorMessage( messages.get( "SwitchWorkspaceAction.WhileTestsAreRunningError" ) );
45  			return;
46  		}
47  
48  		File newPath = null;
49  
50  		if( param != null )
51  		{
52  			newPath = new File( param.toString() );
53  		}
54  		else
55  		{
56  			newPath = UISupport.getFileDialogs().open( this, messages.get( "SwitchWorkspaceAction.FileOpenTitle" ),
57  					".xml", "soapUI Workspace (*.xml)", workspace.getPath() );
58  		}
59  
60  		if( newPath != null )
61  		{
62  			if( SoapUI.getDesktop().closeAll() )
63  			{
64  				boolean save = true;
65  
66  				if( !newPath.exists() )
67  				{
68  					if( !UISupport.confirm( messages.get( "SwitchWorkspaceAction.Confirm.Label", newPath.getName() ),
69  							messages.get( "SwitchWorkspaceAction.Confirm.Title" ) ) )
70  					{
71  						return;
72  					}
73  
74  					save = false;
75  				}
76  				else if( workspace.getOpenProjectList().size() > 0 )
77  				{
78  					Boolean val = UISupport.confirmOrCancel( messages.get( "SwitchWorkspaceAction.SaveOpenProjects.Label" ),
79  							messages.get( "SwitchWorkspaceAction.SaveOpenProjects.Title" ) );
80  					if( val == null )
81  						return;
82  
83  					save = val.booleanValue();
84  				}
85  
86  				workspace.save( !save );
87  
88  				try
89  				{
90  					workspace.switchWorkspace( newPath );
91  					SoapUI.getSettings().setString( SoapUI.CURRENT_SOAPUI_WORKSPACE, newPath.getAbsolutePath() );
92  					UISupport.select( workspace );
93  				}
94  				catch( SoapUIException e )
95  				{
96  					UISupport.showErrorMessage( e );
97  				}
98  			}
99  		}
100 	}
101 }