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.actions;
    14
    15  import java.io.File;
    16
    17  import com.eviware.soapui.SoapUI;
    18  import com.eviware.soapui.impl.WorkspaceImpl;
    19  import com.eviware.soapui.support.SoapUIException;
    20  import com.eviware.soapui.support.UISupport;
    21  import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
    22
    23  /***
    24   * Action to swtich the current workspace
    25   *
    26   * @author ole.matzura
    27   */
    28
    29  public class SwitchWorkspaceAction extends AbstractSoapUIAction<WorkspaceImpl>
    30  {
    31  	public static final String SOAPUI_ACTION_ID = "SwitchWorkspaceAction";
    32
    33  	public SwitchWorkspaceAction()
    34  	{
    35  		super( "Switch Workspace", "Loads another workspace file" );
    36  	}
    37
    38  	public void perform( WorkspaceImpl workspace, Object param )
    39  	{
    40  		if( SoapUI.getTestMonitor().hasRunningTests() )
    41  		{
    42  			UISupport.showErrorMessage( "Cannot switch workspace white tests are running" );
    43  			return;
    44  		}
    45
    46  		File newPath = null;
    47
    48  		if( param != null )
    49  		{
    50  			newPath = new File( param.toString() );
    51  		}
    52  		else
    53  		{
    54  			newPath = UISupport.getFileDialogs().open( this, "Switch Workspace", ".xml", "soapUI Workspace (*.xml)",
    55  					workspace.getPath() );
    56  		}
    57
    58  		if( newPath != null )
    59  		{
    60  			if( SoapUI.getDesktop().closeAll())
    61  			{
    62  				boolean save = true;
    63
    64  				if( !newPath.exists() )
    65  				{
    66  					if( !UISupport.confirm( "Create new Workspace in file [" + newPath.getName() + "]",
    67  								"Switch Workspace" ))
    68  					{
    69  						return;
    70  					}
    71
    72  					save = false;
    73  				}
    74  				else if( workspace.getOpenProjectList().size() > 0 )
    75  				{
    76  					Boolean val = UISupport.confirmOrCancel( "Save Open Projects before Switching Workspace?", "Switch Workspace" );
    77  					if( val == null )
    78  						return;
    79
    80  					save = val.booleanValue();
    81  				}
    82
    83  				workspace.save( !save );
    84
    85  				try
    86  				{
    87  					workspace.switchWorkspace( newPath );
    88  					SoapUI.getSettings().setString( SoapUI.CURRENT_SOAPUI_WORKSPACE, newPath.getAbsolutePath() );
    89  					UISupport.select( workspace );
    90  				}
    91  				catch( SoapUIException e )
    92  				{
    93  					UISupport.showErrorMessage( e );
    94  				}
    95  			}
    96  		}
    97  	}
    98  }