1
2
3
4
5
6
7
8
9
10
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.SoapUIException;
20 import com.eviware.soapui.support.UISupport;
21 import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
22
23 /***
24 * Action to swtich the current workspace
25 *
26 * @author ole.matzura
27 */
28
29 public class SwitchWorkspaceAction extends AbstractSoapUIAction<WorkspaceImpl>
30 {
31 public static final String SOAPUI_ACTION_ID = "SwitchWorkspaceAction";
32
33 public SwitchWorkspaceAction()
34 {
35 super( "Switch Workspace", "Switch to another workspace file" );
36 }
37
38 public void perform( WorkspaceImpl workspace, Object param )
39 {
40 if( SoapUI.getTestMonitor().hasRunningTests() )
41 {
42 UISupport.showErrorMessage( "Cannot switch workspace white tests are running" );
43 return;
44 }
45
46 File newPath = UISupport.getFileDialogs().open( this, "Switch Workspace", ".xml", "soapUI Workspace (*.xml)",
47 workspace.getPath() );
48
49 if( newPath != null )
50 {
51 if( SoapUI.getDesktop().closeAll())
52 {
53 boolean save = true;
54
55 if( !newPath.exists() )
56 {
57 if( !UISupport.confirm( "Create new Workspace in file [" + newPath.getName() + "]",
58 "Switch Workspace" ))
59 {
60 return;
61 }
62
63 save = false;
64 }
65 else if( workspace.getProjectCount() > 0 )
66 {
67 Boolean val = UISupport.confirmOrCancel( "Save All Projects before Switching Workspace?", "Switch Workspace" );
68 if( val == null )
69 return;
70
71 save = val.booleanValue();
72 }
73
74 workspace.save( !save );
75
76 try
77 {
78 workspace.changeWorkspace( newPath );
79 SoapUI.getSettings().setString( SoapUI.CURRENT_SOAPUI_WORKSPACE, newPath.getAbsolutePath() );
80 UISupport.select( workspace );
81 }
82 catch( SoapUIException e )
83 {
84 UISupport.showErrorMessage( e );
85 }
86 }
87 }
88 }
89 }