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 for creating a new Workspace
    25   *
    26   * @author ole.matzura
    27   */
    28
    29  public class NewWorkspaceAction extends AbstractSoapUIAction<WorkspaceImpl>
    30  {
    31  	public static final String SOAPUI_ACTION_ID = "NewWorkspaceAction";
    32
    33  	public NewWorkspaceAction()
    34  	{
    35  		super( "New Workspace", "Creates a new workspace" );
    36  	}
    37
    38  	public void perform( WorkspaceImpl workspace, Object param )
    39  	{
    40  		if( SoapUI.getTestMonitor().hasRunningTests() )
    41  		{
    42  			UISupport.showErrorMessage( "Cannot create and switch workspace white tests are running" );
    43  			return;
    44  		}
    45
    46  		String name = UISupport.prompt( "Enter name of new workspace", "New Workspace", "" );
    47  		if( name == null )
    48  			return;
    49
    50  		File newPath = UISupport.getFileDialogs().saveAs(
    51              this, "New Workspace", ".xml", "soapUI Workspace (*.xml)",
    52  					new File(name + "-workspace.xml") );
    53  		if( newPath == null )
    54  			return;
    55
    56  		if( SoapUI.getDesktop().closeAll())
    57  		{
    58  			if( newPath.exists() )
    59  			{
    60  				if( !UISupport.confirm( "Workspace exists, overwrite?", "New Workspace" ))
    61  				{
    62  					return;
    63  				}
    64
    65  				if( !newPath.delete())
    66  				{
    67  					UISupport.showErrorMessage( "Failed to delete existing workspace" );
    68  					return;
    69  				}
    70  			}
    71
    72  			Boolean val = UISupport.confirmOrCancel( "Save All Projects before Switching Workspace?", "Switch Workspace" );
    73  			if( val == null )
    74  				return;
    75
    76  			workspace.save( val.booleanValue() );
    77
    78  			try
    79  			{
    80  				workspace.changeWorkspace( newPath );
    81  				SoapUI.getSettings().setString( SoapUI.CURRENT_SOAPUI_WORKSPACE, newPath.getAbsolutePath() );
    82  				workspace.setName( name );
    83  			}
    84  			catch( SoapUIException e )
    85  			{
    86  				UISupport.showErrorMessage( e );
    87  			}
    88
    89  		}
    90  	}
    91  }