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.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"), ".xml", "soapUI Workspace (*.xml)",
57 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 }