01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * 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.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
30: AbstractSoapUIAction<WorkspaceImpl> {
31: public static final String SOAPUI_ACTION_ID = "SwitchWorkspaceAction";
32:
33: public SwitchWorkspaceAction() {
34: super ("Switch Workspace", "Switch to another workspace file");
35: }
36:
37: public void perform(WorkspaceImpl workspace, Object param) {
38: if (SoapUI.getTestMonitor().hasRunningTests()) {
39: UISupport
40: .showErrorMessage("Cannot switch workspace white tests are running");
41: return;
42: }
43:
44: File newPath = UISupport.getFileDialogs().open(this ,
45: "Switch Workspace", ".xml", "soapUI Workspace (*.xml)",
46: workspace.getPath());
47:
48: if (newPath != null) {
49: if (SoapUI.getDesktop().closeAll()) {
50: boolean save = true;
51:
52: if (!newPath.exists()) {
53: if (!UISupport.confirm(
54: "Create new Workspace in file ["
55: + newPath.getName() + "]",
56: "Switch Workspace")) {
57: return;
58: }
59:
60: save = false;
61: } else if (workspace.getProjectCount() > 0) {
62: Boolean val = UISupport
63: .confirmOrCancel(
64: "Save All Projects before Switching Workspace?",
65: "Switch Workspace");
66: if (val == null)
67: return;
68:
69: save = val.booleanValue();
70: }
71:
72: workspace.save(!save);
73:
74: try {
75: workspace.changeWorkspace(newPath);
76: SoapUI.getSettings().setString(
77: SoapUI.CURRENT_SOAPUI_WORKSPACE,
78: newPath.getAbsolutePath());
79: UISupport.select(workspace);
80: } catch (SoapUIException e) {
81: UISupport.showErrorMessage(e);
82: }
83: }
84: }
85: }
86: }
|