1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.actions;
14
15 import java.awt.event.ActionEvent;
16 import java.io.File;
17
18 import javax.swing.AbstractAction;
19 import javax.swing.Action;
20
21 import com.eviware.soapui.SoapUI;
22 import com.eviware.soapui.impl.WorkspaceImpl;
23 import com.eviware.soapui.impl.wsdl.WsdlProject;
24 import com.eviware.soapui.support.UISupport;
25
26 /***
27 * Actions for importing an existing soapui-project file into the current workspace
28 *
29 * @author Ole.Matzura
30 */
31
32 public class ImportWsdlProjectAction extends AbstractAction
33 {
34 private final WorkspaceImpl workspace;
35
36 public ImportWsdlProjectAction( WorkspaceImpl workspace )
37 {
38 super( "Import Project" );
39 this.workspace = workspace;
40
41 putValue( Action.SHORT_DESCRIPTION, "Adds an existing project into this workspace" );
42 putValue( Action.ACCELERATOR_KEY, UISupport.getKeyStroke( "menu I") );
43 }
44
45 public void actionPerformed(ActionEvent e)
46 {
47 File file = UISupport.getFileDialogs().openXML(this, "Select soapui project file");
48 if( file == null ) return;
49
50 String fileName = file.getAbsolutePath();
51 if( fileName == null ) return;
52
53 ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
54 Thread.currentThread().setContextClassLoader( SoapUI.class.getClassLoader() );
55
56 try
57 {
58 WsdlProject project = (WsdlProject) workspace.importProject(fileName);
59 if( project != null )
60 SoapUI.selectModelItem(project);
61 }
62 catch (Exception ex)
63 {
64 UISupport.showErrorMessage( ex );
65 }
66 finally
67 {
68 Thread.currentThread().setContextClassLoader( contextClassLoader );
69 }
70 }
71 }