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
    56     	if( retval.booleanValue() )
    57        {
    58           try
    59  			{
    60  				project.save();
    61  			}
    62  			catch( IOException e1 )
    63  			{
    64  				UISupport.showErrorMessage( e1 );
    65  			}
    66        }
    67
    68        project.getWorkspace().removeProject( project );
    69     }
    70
    71  	private boolean hasRunningTests( WsdlProject project )
    72  	{
    73  		for( int c = 0; c < project.getTestSuiteCount(); c++ )
    74  		{
    75  			TestSuite testSuite = project.getTestSuiteAt( c );
    76  			for( int i = 0; i < testSuite.getTestCaseCount(); i++ )
    77  			{
    78  				if( SoapUI.getTestMonitor().hasRunningTest( testSuite.getTestCaseAt( i )))
    79  				{
    80  					return true;
    81  				}
    82  			}
    83  		}
    84
    85  		for( MockService mockService : project.getMockServices() )
    86  		{
    87  			if( SoapUI.getTestMonitor().hasRunningMock( mockService ))
    88  			{
    89  				return true;
    90  			}
    91  		}
    92
    93  		return false;
    94  	}
    95  }