View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
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.wsdl.actions.project;
14  
15  import java.awt.event.ActionEvent;
16  import java.io.File;
17  import java.io.IOException;
18  
19  import javax.swing.AbstractAction;
20  import javax.swing.Action;
21  
22  import com.eviware.soapui.impl.wsdl.WsdlProject;
23  import com.eviware.soapui.support.UISupport;
24  
25  /***
26   * Renames a WsdlProject
27   * 
28   * @author Ole.Matzura
29   */
30  
31  public class SaveProjectAsAction extends AbstractAction
32  {
33     private final WsdlProject project;
34  
35  	public SaveProjectAsAction( WsdlProject project )
36     {
37        super( "Save Project As" );
38  		this.project = project;
39        putValue( Action.SHORT_DESCRIPTION, "Saves this project to a new file" );
40        putValue( Action.ACCELERATOR_KEY, UISupport.getKeyStroke( "menu shift S" ));
41     }
42     
43     public void actionPerformed(ActionEvent e)
44  	{
45        try
46  		{
47        	File file = UISupport.getFileDialogs().saveAs(this, "Select soapui project file", "xml", "XML", new File( project.getPath()));
48           if( file == null ) return;
49            
50           String fileName = file.getAbsolutePath();
51           if( fileName == null ) return;
52            
53  			if( project.saveTo( fileName ))
54  			{
55              project.getWorkspace().save( true );
56  			}
57  		}
58  		catch (IOException e1)
59  		{
60  			UISupport.showErrorMessage( "Failed to save project; " + e1 ); 
61  		}
62     }
63  }