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.io.IOException;
    16
    17  import com.eviware.soapui.SoapUI;
    18  import com.eviware.soapui.impl.wsdl.WsdlProject;
    19  import com.eviware.soapui.model.mock.MockService;
    20  import com.eviware.soapui.model.testsuite.TestSuite;
    21  import com.eviware.soapui.support.UISupport;
    22  import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
    23
    24  /***
    25   * Removes a WsdlProject from the workspace
    26   *
    27   * @author Ole.Matzura
    28   */
    29
    30  public class RemoveProjectAction extends AbstractSoapUIAction<WsdlProject>
    31  {
    32  	public static final String SOAPUI_ACTION_ID = "RemoveProjectAction";
    33
    34  	public RemoveProjectAction()
    35     {
    36        super( "Remove", "Removes this project from the workspace" );
    37     }
    38
    39     public void perform( WsdlProject project, Object param )
    40     {
    41     	if( hasRunningTests( project ))
    42     	{
    43     		UISupport.showErrorMessage( "Cannot remove Interface due to running tests" );
    44     		return;
    45     	}
    46
    47     	Boolean retval = Boolean.FALSE;
    48
    49     	if( !project.isDisabled())
    50     	{
    51  	   	retval = UISupport.confirmOrCancel( "Save project [" + project.getName() + "] before removing?", "Remove Project" );
    52  	   	if( retval == null )
    53  	   		return;
    54     	}
    55     	else
    56     	{
    57     		if( !UISupport.confirm( "Remove project [" + project.getName() + "] from workspace", "Remove Project" ))
    58     			return;
    59     	}
    60
    61     	if( retval.booleanValue() )
    62        {
    63           try
    64  			{
    65  				project.save();
    66  			}
    67  			catch( IOException e1 )
    68  			{
    69  				UISupport.showErrorMessage( e1 );
    70  			}
    71        }
    72
    73        project.getWorkspace().removeProject( project );
    74     }
    75
    76  	private boolean hasRunningTests( WsdlProject project )
    77  	{
    78  		for( int c = 0; c < project.getTestSuiteCount(); c++ )
    79  		{
    80  			TestSuite testSuite = project.getTestSuiteAt( c );
    81  			for( int i = 0; i < testSuite.getTestCaseCount(); i++ )
    82  			{
    83  				if( SoapUI.getTestMonitor().hasRunningTest( testSuite.getTestCaseAt( i )))
    84  				{
    85  					return true;
    86  				}
    87  			}
    88  		}
    89
    90  		for( MockService mockService : project.getMockServices() )
    91  		{
    92  			if( SoapUI.getTestMonitor().hasRunningMock( mockService ))
    93  			{
    94  				return true;
    95  			}
    96  		}
    97
    98  		return false;
    99  	}
    100 }