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 for creating a new Workspace
25: *
26: * @author ole.matzura
27: */
28:
29: public class NewWorkspaceAction extends
30: AbstractSoapUIAction<WorkspaceImpl> {
31: public static final String SOAPUI_ACTION_ID = "NewWorkspaceAction";
32:
33: public NewWorkspaceAction() {
34: super ("New Workspace", "Creates a new workspace");
35: }
36:
37: public void perform(WorkspaceImpl workspace, Object param) {
38: if (SoapUI.getTestMonitor().hasRunningTests()) {
39: UISupport
40: .showErrorMessage("Cannot create and switch workspace white tests are running");
41: return;
42: }
43:
44: String name = UISupport.prompt("Enter name of new workspace",
45: "New Workspace", "");
46: if (name == null)
47: return;
48:
49: File newPath = UISupport.getFileDialogs().saveAs(this ,
50: "New Workspace", ".xml", "soapUI Workspace (*.xml)",
51: new File(name + "-workspace.xml"));
52: if (newPath == null)
53: return;
54:
55: if (SoapUI.getDesktop().closeAll()) {
56: if (newPath.exists()) {
57: if (!UISupport.confirm("Workspace exists, overwrite?",
58: "New Workspace")) {
59: return;
60: }
61:
62: if (!newPath.delete()) {
63: UISupport
64: .showErrorMessage("Failed to delete existing workspace");
65: return;
66: }
67: }
68:
69: Boolean val = UISupport.confirmOrCancel(
70: "Save All Projects before Switching Workspace?",
71: "Switch Workspace");
72: if (val == null)
73: return;
74:
75: workspace.save(val.booleanValue());
76:
77: try {
78: workspace.changeWorkspace(newPath);
79: SoapUI.getSettings().setString(
80: SoapUI.CURRENT_SOAPUI_WORKSPACE,
81: newPath.getAbsolutePath());
82: workspace.setName(name);
83: } catch (SoapUIException e) {
84: UISupport.showErrorMessage(e);
85: }
86:
87: }
88: }
89: }
|