View Javadoc

1   /*
2    *  soapUI, copyright (C) 2006 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  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.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  }