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.wsdl.actions.project;
14:
15: import java.io.IOException;
16:
17: import com.eviware.soapui.SoapUI;
18: import com.eviware.soapui.impl.wsdl.WsdlProject;
19: import com.eviware.soapui.model.mock.MockService;
20: import com.eviware.soapui.model.testsuite.TestSuite;
21: import com.eviware.soapui.support.UISupport;
22: import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
23:
24: /**
25: * Removes a WsdlProject from the workspace
26: *
27: * @author Ole.Matzura
28: */
29:
30: public class RemoveProjectAction extends
31: AbstractSoapUIAction<WsdlProject> {
32: public static final String SOAPUI_ACTION_ID = "RemoveProjectAction";
33:
34: public RemoveProjectAction() {
35: super ("Remove", "Removes this project from the workspace");
36: }
37:
38: public void perform(WsdlProject project, Object param) {
39: if (hasRunningTests(project)) {
40: UISupport
41: .showErrorMessage("Cannot remove Interface due to running tests");
42: return;
43: }
44:
45: Boolean retval = Boolean.FALSE;
46:
47: if (!project.isDisabled()) {
48: retval = UISupport.confirmOrCancel("Save project ["
49: + project.getName() + "] before removing?",
50: "Remove Project");
51: if (retval == null)
52: return;
53: }
54:
55: if (retval.booleanValue()) {
56: try {
57: project.save();
58: } catch (IOException e1) {
59: UISupport.showErrorMessage(e1);
60: }
61: }
62:
63: project.getWorkspace().removeProject(project);
64: }
65:
66: private boolean hasRunningTests(WsdlProject project) {
67: for (int c = 0; c < project.getTestSuiteCount(); c++) {
68: TestSuite testSuite = project.getTestSuiteAt(c);
69: for (int i = 0; i < testSuite.getTestCaseCount(); i++) {
70: if (SoapUI.getTestMonitor().hasRunningTest(
71: testSuite.getTestCaseAt(i))) {
72: return true;
73: }
74: }
75: }
76:
77: for (MockService mockService : project.getMockServices()) {
78: if (SoapUI.getTestMonitor().hasRunningMock(mockService)) {
79: return true;
80: }
81: }
82:
83: return false;
84: }
85: }
|