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.iface;
14:
15: import java.util.ArrayList;
16: import java.util.Arrays;
17: import java.util.List;
18:
19: import com.eviware.soapui.impl.WorkspaceImpl;
20: import com.eviware.soapui.impl.wsdl.WsdlInterface;
21: import com.eviware.soapui.impl.wsdl.WsdlProject;
22: import com.eviware.soapui.model.support.ModelSupport;
23: import com.eviware.soapui.support.SoapUIException;
24: import com.eviware.soapui.support.UISupport;
25: import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
26:
27: /**
28: * Clones an Interface to another project
29: *
30: * @author Ole.Matzura
31: */
32:
33: public class CloneInterfaceAction extends
34: AbstractSoapUIAction<WsdlInterface> {
35: public CloneInterfaceAction() {
36: super ("Clone Interface",
37: "Clones this Interface to another project");
38: }
39:
40: public void perform(WsdlInterface iface, Object param) {
41: WorkspaceImpl workspace = iface.getProject().getWorkspace();
42: String[] names = ModelSupport.getNames(workspace
43: .getProjectList(), new String[] { "<Create New>" });
44:
45: List<String> asList = new ArrayList<String>(Arrays
46: .asList(names));
47: asList.remove(iface.getProject().getName());
48:
49: String targetProjectName = UISupport.prompt(
50: "Select target Project for cloned Interface",
51: "Clone Interface", asList);
52: if (targetProjectName == null)
53: return;
54:
55: WsdlProject targetProject = (WsdlProject) workspace
56: .getProjectByName(targetProjectName);
57: if (targetProject == null) {
58: targetProjectName = UISupport
59: .prompt("Enter name for new Project",
60: "Clone TestSuite", "");
61: if (targetProjectName == null)
62: return;
63:
64: try {
65: targetProject = workspace
66: .createProject(targetProjectName);
67: } catch (SoapUIException e) {
68: UISupport.showErrorMessage(e);
69: }
70:
71: if (targetProject == null)
72: return;
73: }
74:
75: WsdlInterface targetIface = targetProject
76: .getInterfaceByBindingName(iface.getBindingName());
77: if (targetIface != null) {
78: UISupport
79: .showErrorMessage("Target Project already contains Interface for binding");
80: } else {
81: UISupport.select(targetProject.importInterface(iface));
82: }
83: }
84: }
|