View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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.actions;
14  
15  import java.io.IOException;
16  import java.util.ArrayList;
17  import java.util.List;
18  
19  import com.eviware.soapui.SoapUI;
20  import com.eviware.soapui.impl.WorkspaceImpl;
21  import com.eviware.soapui.model.project.Project;
22  import com.eviware.soapui.support.UISupport;
23  import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
24  
25  /***
26   * Action to save all projects
27   * 
28   * @author ole.matzura
29   */
30  
31  public class CloseOpenProjectsAction extends AbstractSoapUIAction<WorkspaceImpl>
32  {
33  	public static final String SOAPUI_ACTION_ID = "CloseOpenProjectsAction";
34  
35  	public CloseOpenProjectsAction()
36  	{
37  		super( "Close All Open Projects", "Closes all open projects in the current Workspace" );
38  	}
39  
40  	public void perform( WorkspaceImpl workspace, Object param )
41  	{
42  		List<Project> openProjects = new ArrayList<Project>();
43  		for( Project project : workspace.getProjectList() )
44  			if( project.isOpen() )
45  				openProjects.add( project );
46  
47  		if( openProjects.isEmpty() )
48  		{
49  			UISupport.showErrorMessage( "No open projects in workspace" );
50  			return;
51  		}
52  
53  		Boolean coc = UISupport.confirmOrCancel( "Save projects before closing?", getName() );
54  		if( coc == null )
55  			return;
56  
57  		for( Project project : openProjects )
58  		{
59  			try
60  			{
61  				if( coc )
62  					project.save();
63  
64  				workspace.closeProject( project );
65  			}
66  			catch( IOException e )
67  			{
68  				SoapUI.logError( e );
69  			}
70  		}
71  	}
72  }