[264683] PreServiceDevelopCommand locks the workspace root in the main thread thus creating deadlock conditions
diff --git a/bundles/org.eclipse.jst.ws.creation.ui/src/org/eclipse/jst/ws/internal/creation/ui/extension/PreServiceAssembleCommand.java b/bundles/org.eclipse.jst.ws.creation.ui/src/org/eclipse/jst/ws/internal/creation/ui/extension/PreServiceAssembleCommand.java
index afd743a..e2d7657 100644
--- a/bundles/org.eclipse.jst.ws.creation.ui/src/org/eclipse/jst/ws/internal/creation/ui/extension/PreServiceAssembleCommand.java
+++ b/bundles/org.eclipse.jst.ws.creation.ui/src/org/eclipse/jst/ws/internal/creation/ui/extension/PreServiceAssembleCommand.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2005, 2008 IBM Corporation and others.
+ * Copyright (c) 2005, 2009 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -17,21 +17,27 @@
  * 20071218	  200193 gilberta@ca.ibm.com - Gilbert Andrews
  * 20071220   213640 kathy@ca.ibm.com - Kathy Chan
  * 20080325   222473 makandre@ca.ibm.com - Andrew Mak, Create EAR version based on the version of modules to be added
+ * 20090415   264683 danail.branekov@sap.com - Danail Branekov
  *******************************************************************************/
 
 package org.eclipse.jst.ws.internal.creation.ui.extension;
 
+import java.lang.reflect.InvocationTargetException;
+
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.operation.ModalContext;
 import org.eclipse.jst.j2ee.internal.plugin.IJ2EEModuleConstants;
 import org.eclipse.jst.ws.internal.common.J2EEUtils;
 import org.eclipse.jst.ws.internal.consumption.command.common.AssociateModuleWithEARCommand;
 import org.eclipse.jst.ws.internal.consumption.command.common.CreateFacetedProjectCommand;
 import org.eclipse.jst.ws.internal.consumption.common.FacetUtils;
+import org.eclipse.ui.PlatformUI;
 import org.eclipse.wst.common.environment.IEnvironment;
 import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
 import org.eclipse.wst.ws.internal.plugin.WSPlugin;
@@ -116,12 +122,36 @@
 		  
 		  if(initialProject_ != null && FacetUtils.isJavaProject(initialProject_)) {
 			  IProject earProject = ResourcesPlugin.getWorkspace().getRoot().getProject(earProject_);
-			  J2EEUtils.addJavaProjectAsUtilityJar(initialProject_, earProject, monitor);
+			  addJavaProjectAsUtilityInModalCtx(initialProject_, earProject, monitor);
 		  }		 
 	  
 	  }
 	  return status;	  
   }
+  
+  private void addJavaProjectAsUtilityInModalCtx(final IProject projectToAdd, final IProject earProject, final IProgressMonitor monitor)
+	{
+		final IRunnableWithProgress addRunnable = new IRunnableWithProgress()
+		{
+			public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
+			{
+				J2EEUtils.addJavaProjectAsUtilityJar(projectToAdd, earProject, monitor);
+			}
+		};
+
+		try
+		{
+			ModalContext.run(addRunnable, true, monitor, PlatformUI.getWorkbench().getDisplay());
+		} catch (InvocationTargetException e)
+		{
+			// The executed runnable does not throw checked exceptions therefore if this happens, this is a runtime exception
+			throw new RuntimeException(e);
+		} catch (InterruptedException e)
+		{
+			// The executed runnable does not support cancellation and this should never happen
+			throw new IllegalStateException(e);
+		}
+	}
 	
   public void setInitialProject(IProject initialProject)
   {
diff --git a/bundles/org.eclipse.jst.ws.creation.ui/src/org/eclipse/jst/ws/internal/creation/ui/extension/PreServiceDevelopCommand.java b/bundles/org.eclipse.jst.ws.creation.ui/src/org/eclipse/jst/ws/internal/creation/ui/extension/PreServiceDevelopCommand.java
index 1c6dd34..dabde40 100644
--- a/bundles/org.eclipse.jst.ws.creation.ui/src/org/eclipse/jst/ws/internal/creation/ui/extension/PreServiceDevelopCommand.java
+++ b/bundles/org.eclipse.jst.ws.creation.ui/src/org/eclipse/jst/ws/internal/creation/ui/extension/PreServiceDevelopCommand.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2005, 2008 IBM Corporation and others.
+ * Copyright (c) 2005, 2009 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -21,11 +21,13 @@
  * 20080326   221364 kathy@ca.ibm.com - Kathy Chan
  * 20080724   241275 pmoogk@ca.ibm.com - Peter Moogk, Validate WSDL before doing major Web service processing.
  * 20081001   243869 ericdp@ca.ibm.com - Eric D. Peters, Web Service tools allowing mixed J2EE levels
+ * 20090415   264683 danail.branekov@sap.com - Danail Branekov
  *******************************************************************************/
 
 package org.eclipse.jst.ws.internal.creation.ui.extension;
 
 import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.ResourcesPlugin;
@@ -34,6 +36,8 @@
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.operation.ModalContext;
 import org.eclipse.jst.ws.internal.common.J2EEUtils;
 import org.eclipse.jst.ws.internal.consumption.command.common.CreateFacetedProjectCommand;
 import org.eclipse.jst.ws.internal.consumption.common.FacetUtils;
@@ -45,6 +49,7 @@
 import org.eclipse.jst.ws.internal.consumption.ui.wsrt.WebServiceRuntimeExtensionUtils2;
 import org.eclipse.jst.ws.internal.data.TypeRuntimeServer;
 import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.PlatformUI;
 import org.eclipse.wst.command.internal.env.core.common.StatusUtils;
 import org.eclipse.wst.command.internal.env.core.context.ResourceContext;
 import org.eclipse.wst.common.environment.IEnvironment;
@@ -209,10 +214,8 @@
 	  
 	  
 		  if(initialProject_ != null && FacetUtils.isJavaProject(initialProject_)){
-			  J2EEUtils.addJavaProjectAsUtilityJar(initialProject_, project, monitor);
 			  try{
-		  		String uri = initialProject_.getName() + ".jar";
-		  		J2EEUtils.addJAROrModuleDependency(project, uri);
+				addJavaProjectAsUtilityInModalCtx(initialProject_, project, monitor);
 			  } catch (CoreException ce){
 				  String errorMessage = NLS.bind(ConsumptionUIMessages.MSG_ERROR_MODULE_DEPENDENCY, new String[]{project.getName(), initialProject_.getName()});
 				  IStatus errorStatus = StatusUtils.errorStatus(errorMessage);
@@ -228,6 +231,55 @@
 
   }
   
+  /**
+   * Adds the projectToAdd as utility to the ear project specified. The operation is executed in a modal context in order to avoid locking the workspace root in the UI thread 
+   */
+  private void addJavaProjectAsUtilityInModalCtx(final IProject projectToAdd, final IProject earProject, final IProgressMonitor monitor) throws IOException, CoreException
+	{
+		final IRunnableWithProgress addRunnable = new IRunnableWithProgress()
+		{
+			public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
+			{
+				J2EEUtils.addJavaProjectAsUtilityJar(projectToAdd, earProject, monitor);
+				try
+				{
+					final String uri = projectToAdd.getName() + ".jar";
+					J2EEUtils.addJAROrModuleDependency(earProject, uri);
+				} catch (IOException e)
+				{
+					throw new InvocationTargetException(e);
+				} catch (CoreException e)
+				{
+					throw new InvocationTargetException(e);
+				}
+			}
+		};
+		
+		try
+		{
+			ModalContext.run(addRunnable, true, monitor, PlatformUI.getWorkbench().getDisplay());
+		} catch (InvocationTargetException e)
+		{
+			final Throwable cause = e.getCause();
+			// IOExcetpion and CoreException thrown by J2EEUtils.addJAROrModuleDependency
+			if(cause instanceof IOException)
+			{
+				throw (IOException)cause;
+			}
+			if(cause instanceof CoreException)
+			{
+				throw (CoreException)cause;
+			}
+			
+			// Other unexpected exception has occurred, rethrow it as a runtime exception
+			throw new RuntimeException(e);
+		} catch (InterruptedException e)
+		{
+			// The executed runnable does not support cancellation and therefore this can never happen
+			throw new IllegalStateException(e);
+		}
+	}
+  
   public void setServiceTypeRuntimeServer( TypeRuntimeServer typeRuntimeServer )
   {
 	  typeRuntimeServer_ = typeRuntimeServer;