[242635] Remove unnecessary UI dependencies from org.eclipse.jst.ws.consumption
diff --git a/bundles/org.eclipse.jst.ws.consumption.ui/plugin.xml b/bundles/org.eclipse.jst.ws.consumption.ui/plugin.xml
index fb4161d..65aa263 100644
--- a/bundles/org.eclipse.jst.ws.consumption.ui/plugin.xml
+++ b/bundles/org.eclipse.jst.ws.consumption.ui/plugin.xml
@@ -759,5 +759,10 @@
               property="ListServers"
               transform="org.eclipse.wst.command.internal.env.ant.String2BooleanTransformer"
               />  	
-      </extension> 
+      </extension>
+      
+     <extension
+           point="org.eclipse.jst.ws.consumption.internalFacetOperationDelegate">
+  			<FacetOperationDelegate class="org.eclipse.jst.ws.internal.consumption.ui.common.FacetOperationDelegate" />
+     </extension> 
 </plugin>
diff --git a/bundles/org.eclipse.jst.ws.consumption.ui/src/org/eclipse/jst/ws/internal/consumption/ui/common/FacetOperationDelegate.java b/bundles/org.eclipse.jst.ws.consumption.ui/src/org/eclipse/jst/ws/internal/consumption/ui/common/FacetOperationDelegate.java
new file mode 100644
index 0000000..2048192
--- /dev/null
+++ b/bundles/org.eclipse.jst.ws.consumption.ui/src/org/eclipse/jst/ws/internal/consumption/ui/common/FacetOperationDelegate.java
@@ -0,0 +1,307 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * yyyymmdd bug      Email and other contact information
+ * -------- -------- -----------------------------------------------------------
+ * 20090303   242635 mahutch@ca.ibm.com - Mark Hutchinson, Remove unnecessary UI dependencies from org.eclipse.jst.ws.consumption
+ *******************************************************************************/
+package org.eclipse.jst.ws.internal.consumption.ui.common;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jst.ws.internal.consumption.ConsumptionMessages;
+import org.eclipse.jst.ws.internal.consumption.common.FacetUtils;
+import org.eclipse.jst.ws.internal.consumption.common.IFacetOperationDelegate;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.wst.command.internal.env.core.common.StatusUtils;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
+import org.osgi.framework.Bundle;
+
+public class FacetOperationDelegate implements IFacetOperationDelegate {
+
+	public IStatus addFacetsToProject(final IFacetedProject fproject, final Set projectFacetVersions) {
+		final IStatus[] status = new IStatus[1];
+		status[0] = Status.OK_STATUS;
+		final Set actions = FacetUtils.getInstallActions(projectFacetVersions);
+
+		// Create a runnable that applies the install actions to the faceted project
+		IRunnableWithProgress runnable = new IRunnableWithProgress() {
+			public void run(IProgressMonitor shellMonitor) throws InvocationTargetException, InterruptedException {
+				try {
+					fproject.modify(actions, shellMonitor);
+				} catch (CoreException e) {
+					status[0] = getErrorStatusForAddingFacets(fproject.getProject().getName(), projectFacetVersions, e);
+				}
+			}
+		};
+
+		// Run the runnable in another thread unless there is no UI thread (Ant scenarios)
+		if (displayPresent()) {
+			try {
+				PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);
+			} catch (InvocationTargetException ite) {
+				status[0] = getErrorStatusForAddingFacets(fproject.getProject().getName(), projectFacetVersions, ite);
+			} catch (InterruptedException ie) {
+				status[0] = getErrorStatusForAddingFacets(fproject.getProject().getName(), projectFacetVersions, ie);
+			}
+		} else {
+			try {
+				fproject.modify(actions, null);
+			} catch (CoreException e) {
+				status[0] = getErrorStatusForAddingFacets(fproject.getProject().getName(), projectFacetVersions, e);
+			}
+		}
+
+		return status[0];
+	}
+
+	public IStatus createNewFacetedProject(final String projectName) {
+		final IStatus[] status = new IStatus[1];
+		status[0] = Status.OK_STATUS;
+		IProject project = ProjectUtilities.getProject(projectName);
+		if (!project.exists()) {
+			// Create a runnable that creates a new faceted project.
+			IRunnableWithProgress runnable = new IRunnableWithProgress() {
+				public void run(IProgressMonitor shellMonitor) throws InvocationTargetException, InterruptedException {
+					try {
+						IFacetedProject fProject = ProjectFacetsManager.create(projectName, null, shellMonitor);
+						if (fProject == null) {
+							status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }));
+						}
+					} catch (CoreException e) {
+						status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }), e);
+					}
+				}
+			};
+
+			// Run the runnable in another thread unless there is no UI thread (Ant scenarios)
+			try {
+				if (displayPresent()) {
+					PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);
+				} else {
+					try {
+						IFacetedProject fProject = ProjectFacetsManager.create(projectName, null, null);
+						if (fProject == null) {
+							status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }));
+						}
+					} catch (CoreException e) {
+						status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }), e);
+					}
+				}
+			} catch (InvocationTargetException ite) {
+				status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }), ite);
+			} catch (InterruptedException ie) {
+				status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }), ie);
+			}
+		}
+
+		return status[0];
+	}
+
+	public IStatus setFacetRuntimeOnProject(final IFacetedProject fProject, final IRuntime fRuntime) {
+		final IStatus[] status = new IStatus[1];
+		status[0] = Status.OK_STATUS;
+
+		// Create a runnable that sets the facet runtime on the faceted project
+		IRunnableWithProgress runnable = new IRunnableWithProgress() {
+			public void run(IProgressMonitor shellMonitor) throws InvocationTargetException, InterruptedException {
+				try {
+					fProject.setTargetedRuntimes(Collections.singleton(fRuntime), shellMonitor);
+				} catch (CoreException e) {
+					status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_SETTING_RUNTIME, new String[] { fProject.getProject().getName(), fRuntime.getName() }), e);
+				}
+			}
+		};
+
+		// Run the runnable in another thread unless there is no UI thread (Ant scenarios)
+		if (displayPresent()) {
+			try {
+				PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);
+			} catch (InvocationTargetException ite) {
+				status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_SETTING_RUNTIME, new String[] { fProject.getProject().getName(), fRuntime.getName() }), ite);
+			} catch (InterruptedException ie) {
+				status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_SETTING_RUNTIME, new String[] { fProject.getProject().getName(), fRuntime.getName() }), ie);
+			}
+		} else {
+			try {
+				fProject.setTargetedRuntimes(Collections.singleton(fRuntime), null);
+
+			} catch (CoreException e) {
+				status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_SETTING_RUNTIME, new String[] { fProject.getProject().getName(), fRuntime.getName() }), e);
+			}
+		}
+
+		return status[0];
+	}
+
+	public IStatus setFixedFacetsOnProject(final IFacetedProject fProject, final Set fixedFacets) {
+		final IStatus[] status = new IStatus[1];
+		status[0] = Status.OK_STATUS;
+
+		// Create a runnable that sets the fixed facets on the faceted project
+		IRunnableWithProgress runnable = new IRunnableWithProgress() {
+			public void run(IProgressMonitor shellMonitor) throws InvocationTargetException, InterruptedException {
+				try {
+					fProject.setFixedProjectFacets(fixedFacets);
+				} catch (CoreException e) {
+					status[0] = getErrorStatusForSettingFixedFacets(fProject.getProject().getName(), fixedFacets, e);
+				}
+			}
+		};
+
+		// Run the runnable in another thread unless there is no UI thread (Ant scenarios)
+		if (displayPresent()) {
+			try {
+				PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);
+			} catch (InvocationTargetException ite) {
+				status[0] = getErrorStatusForSettingFixedFacets(fProject.getProject().getName(), fixedFacets, ite);
+			} catch (InterruptedException ie) {
+				status[0] = getErrorStatusForSettingFixedFacets(fProject.getProject().getName(), fixedFacets, ie);
+			}
+		} else {
+			try {
+				fProject.setFixedProjectFacets(fixedFacets);
+			} catch (CoreException e) {
+				status[0] = getErrorStatusForSettingFixedFacets(fProject.getProject().getName(), fixedFacets, e);
+			}
+		}
+
+		return status[0];
+	}
+
+	// Check to see if SWT is active and the Display is present or not
+	private static boolean displayPresent() {
+		Bundle b = Platform.getBundle("org.eclipse.swt");
+		if (b == null) {
+			return false;
+		}
+		if ((b.getState() != Bundle.RESOLVED && b.getState() != Bundle.ACTIVE)) {
+			return false;
+		}
+		try {
+			if (Display.getCurrent() == null) {
+				return false;
+			} else {
+				return true;
+			}
+		} catch (NoClassDefFoundError e1) {
+			return false;
+		} catch (Exception e) { 
+			// if the Display class cannot be loaded for whatever reason
+			return false;
+
+		}
+	}
+
+	// the following private methods had to be copied from FacetUtils
+	/**
+	 * Returns a translatable delimited list of facet labels derived from the
+	 * provided set of facets
+	 * 
+	 * @param facets
+	 *            a set containing elements of type {@link IProjectFacet}
+	 * @return String a delimited list of facet labels
+	 */
+	private static String getFacetListMessageString(Set facets) {
+		String facetListMessage = "";
+		int size = facets.size();
+		if (size > 0) {
+			Iterator itr = facets.iterator();
+			IProjectFacet firstProjectFacet = (IProjectFacet) itr.next();
+			facetListMessage = firstProjectFacet.getLabel();
+
+			// Continue appending to facetListMessage until all the facet labels
+			// are in the list.
+			while (itr.hasNext()) {
+				IProjectFacet projectFacet = (IProjectFacet) itr.next();
+				String pfLabel = projectFacet.getLabel();
+				facetListMessage = NLS.bind(ConsumptionMessages.MSG_FACETS, new String[] { facetListMessage, pfLabel });
+			}
+		}
+
+		return facetListMessage;
+	}
+
+	/**
+	 * Returns an error status indicating that the facets could not be set as
+	 * fixed facets on the faceted project
+	 * 
+	 * @param projectName
+	 *            a project name to insert in the error message in the IStatus
+	 * @param facets
+	 *            a set containing elements of type {@link IProjectFacet}. The
+	 *            facets in this set will be listed in the error message in the
+	 *            IStatus.
+	 * @param t
+	 *            a Throwable which will be inserted in the IStatus
+	 * @return an IStatus with severity IStatus.ERROR
+	 */
+	private static IStatus getErrorStatusForSettingFixedFacets(String projectName, Set facets, Throwable t) {
+		IStatus status = Status.OK_STATUS;
+		int size = facets.size();
+		if (size > 0) {
+			String facetList = getFacetListMessageString(facets);
+			status = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_FIXED_FACETS, new String[] { projectName, facetList }), t);
+		}
+
+		return status;
+	}
+
+	/**
+	 * Returns an error status indicating that the facet versions could not be
+	 * added to the faceted project
+	 * 
+	 * @param projectName
+	 *            a project name to insert in the error message in the IStatus
+	 * @param projectFacetVersions
+	 *            a set containing elements of type {@link IProjectFacetVersion}
+	 *            . The facets in this set will be listed in the error message
+	 *            in the IStatus.
+	 * @param t
+	 *            a Throwable which will be inserted in the IStatus
+	 * @return an IStatus with severity IStatus.ERROR
+	 */
+	private static IStatus getErrorStatusForAddingFacets(String projectName, Set projectFacetVersions, Throwable t) {
+		IStatus status = Status.OK_STATUS;
+		int size = projectFacetVersions.size();
+		if (size > 0) {
+			Set facets = new HashSet();
+			// Iterate over projectFacetVersions to form a set of IProjectFacets
+			Iterator itr = projectFacetVersions.iterator();
+			while (itr.hasNext()) {
+				IProjectFacetVersion projectFacet = (IProjectFacetVersion) itr.next();
+				IProjectFacet facet = projectFacet.getProjectFacet();
+				facets.add(facet);
+			}
+			String facetList = getFacetListMessageString(facets);
+			status = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_ADDING_FACETS_TO_PROJECT, new String[] { projectName, facetList }), t);
+		}
+
+		return status;
+	}
+
+}
diff --git a/bundles/org.eclipse.jst.ws.consumption/META-INF/MANIFEST.MF b/bundles/org.eclipse.jst.ws.consumption/META-INF/MANIFEST.MF
index 1ba2aca..b46c3cd 100644
--- a/bundles/org.eclipse.jst.ws.consumption/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.jst.ws.consumption/META-INF/MANIFEST.MF
@@ -40,7 +40,6 @@
  org.eclipse.wst.command.env.core;bundle-version="[1.0.101,1.1.0)",
  org.eclipse.wst.command.env;bundle-version="[1.0.101,1.1.0)",
  org.eclipse.jem.workbench;bundle-version="[2.0.0,3.0.0)",
- org.eclipse.jface;bundle-version="[3.2.0,4.0.0)",
  org.eclipse.wst.ws;bundle-version="[1.0.100,1.2.0)",
  org.eclipse.wst.ws.parser;bundle-version="[1.0.100,1.1.0)",
  org.eclipse.wst.server.core;bundle-version="[1.0.102,2.0.0)",
@@ -56,8 +55,8 @@
  org.eclipse.wst.common.environment;bundle-version="[1.0.100,1.1.0)",
  org.eclipse.wst.common.project.facet.core;bundle-version="[1.1.0,2.0.0)",
  org.eclipse.jst.server.core;bundle-version="[1.0.102,2.0.0)",
- org.eclipse.ui;bundle-version="[3.2.0,4.0.0)";resolution:=optional,
- org.eclipse.emf.codegen;bundle-version="[2.2.0,3.0.0)"
+ org.eclipse.emf.codegen;bundle-version="[2.2.0,3.0.0)",
+ org.eclipse.core.commands;bundle-version="[3.5.0,3.6.0)"
 Eclipse-LazyStart: true
 Bundle-RequiredExecutionEnvironment: J2SE-1.4
 Bundle-ActivationPolicy: lazy
diff --git a/bundles/org.eclipse.jst.ws.consumption/plugin.properties b/bundles/org.eclipse.jst.ws.consumption/plugin.properties
index f2c1bac..946c786 100644
--- a/bundles/org.eclipse.jst.ws.consumption/plugin.properties
+++ b/bundles/org.eclipse.jst.ws.consumption/plugin.properties
@@ -1,12 +1,15 @@
 ###############################################################################
-# Copyright (c) 2000, 2005 IBM Corporation and others.
+# Copyright (c) 2000, 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
 # http://www.eclipse.org/legal/epl-v10.html
 #
 # Contributors:
-#     IBM Corporation - initial API and implementation
+# IBM Corporation - initial API and implementation
+# yyyymmdd bug      Email and other contact information
+# -------- -------- -----------------------------------------------------------
+# 20090302   242635 mahutch@ca.ibm.com - Mark Hutchinson, Remove unnecessary UI dependencies from org.eclipse.jst.ws.consumption
 ###############################################################################
 
 #
@@ -17,3 +20,4 @@
 XP_WSFINDER=org.eclipse.jst.ws.internal.consumption.wsfinder
 XP_WEB_SERVICE_START_SERVER_TYPE=WebServiceStartServerType
 XP_SERVER_DEFAULTER=Server Defaulter
+XP_FACET_OP_DELEGATE=Facet Operation Delegate
diff --git a/bundles/org.eclipse.jst.ws.consumption/plugin.xml b/bundles/org.eclipse.jst.ws.consumption/plugin.xml
index f6640aa..da2c8dd 100644
--- a/bundles/org.eclipse.jst.ws.consumption/plugin.xml
+++ b/bundles/org.eclipse.jst.ws.consumption/plugin.xml
@@ -17,6 +17,11 @@
    <extension-point
       id="serverDefaulter"
       name="%XP_SERVER_DEFAULTER"/>
+      
+   <!-- The following extension point is internal and likely to be removed in a future release. -->
+   <extension-point id="internalFacetOperationDelegate"
+   		name="%XP_FACET_OP_DELEGATE"
+   		schema="schema/facetOperationDelegate.exsd"/>
 
    
    <extension
diff --git a/bundles/org.eclipse.jst.ws.consumption/schema/facetOperationDelegate.exsd b/bundles/org.eclipse.jst.ws.consumption/schema/facetOperationDelegate.exsd
new file mode 100644
index 0000000..45b3400
--- /dev/null
+++ b/bundles/org.eclipse.jst.ws.consumption/schema/facetOperationDelegate.exsd
@@ -0,0 +1,80 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.jst.ws.consumption" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+      <appinfo>
+         <meta.schema plugin="org.eclipse.jst.ws.consumption" id="internalFacetOperationDelegate" name="Facet Operation Delegate"/>
+      </appinfo>
+      <documentation>
+         &lt;b&gt;Internal Extension Point:&lt;/b&gt; This internal extension point allows an IFacetOperationDelegate to be plugged in that is delegated some facet operations. &lt;b&gt;Do not use this extension point.&lt;/b&gt;
+      </documentation>
+   </annotation>
+
+   <element name="extension">
+      <annotation>
+         <appinfo>
+            <meta.element internal="true" />
+         </appinfo>
+      </annotation>
+      <complexType>
+         <sequence>
+            <element ref="FacetOperationDelegate"/>
+         </sequence>
+         <attribute name="point" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="id" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="name" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appinfo>
+                  <meta.attribute translatable="true"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="FacetOperationDelegate">
+      <annotation>
+         <documentation>
+            This element specifies the FacetOperationDelegate
+         </documentation>
+      </annotation>
+      <complexType>
+         <attribute name="class" type="string" use="required">
+            <annotation>
+               <documentation>
+                  Class that provides the implementation of IFacetOperationDelegate
+               </documentation>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="since"/>
+      </appinfo>
+      <documentation>
+         WTP 3.1
+      </documentation>
+   </annotation>
+
+
+
+
+
+</schema>
diff --git a/bundles/org.eclipse.jst.ws.consumption/src/org/eclipse/jst/ws/internal/consumption/common/FacetUtils.java b/bundles/org.eclipse.jst.ws.consumption/src/org/eclipse/jst/ws/internal/consumption/common/FacetUtils.java
index fbf5796..1189868 100644
--- a/bundles/org.eclipse.jst.ws.consumption/src/org/eclipse/jst/ws/internal/consumption/common/FacetUtils.java
+++ b/bundles/org.eclipse.jst.ws.consumption/src/org/eclipse/jst/ws/internal/consumption/common/FacetUtils.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2008 IBM Corporation and others.
+ * Copyright (c) 2007, 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
@@ -15,11 +15,11 @@
  * 20080325   222473 makandre@ca.ibm.com - Andrew Mak, Create EAR version based on the version of modules to be added
  * 20080429   213730 trungha@ca.ibm.com - Trung Ha
  * 20080507   229532 kathy@ca.ibm.com - Kathy Chan
+ * 20090303   242635 mahutch@ca.ibm.com - Mark Hutchinson, Remove unnecessary UI dependencies from org.eclipse.jst.ws.consumption
  *******************************************************************************/
 
 package org.eclipse.jst.ws.internal.consumption.common;
 
-import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
@@ -30,6 +30,10 @@
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Platform;
@@ -37,7 +41,6 @@
 import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
-import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jst.j2ee.internal.common.J2EEVersionUtil;
 import org.eclipse.jst.j2ee.internal.ejb.project.operations.EjbFacetInstallDataModelProvider;
 import org.eclipse.jst.j2ee.internal.ejb.project.operations.IEjbFacetInstallDataModelProperties;
@@ -54,8 +57,6 @@
 import org.eclipse.jst.ws.internal.common.ResourceUtils;
 import org.eclipse.jst.ws.internal.consumption.ConsumptionMessages;
 import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.PlatformUI;
 import org.eclipse.wst.command.internal.env.core.common.StatusUtils;
 import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
 import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
@@ -70,7 +71,6 @@
 import org.eclipse.wst.common.project.facet.core.IFacetedProject.Action.Type;
 import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
 import org.eclipse.wst.common.project.facet.core.runtime.RuntimeManager;
-import org.osgi.framework.Bundle;
 
 import com.ibm.icu.util.StringTokenizer;
 
@@ -92,6 +92,8 @@
 public class FacetUtils
 {
 
+  private static IFacetOperationDelegate delegate; //if a delegate is plugged in, delegate some operations to it
+  private static boolean failedToLoadDelegate = false;
   /**
    * Returns an array of valid projects. Valid projects include projects with the facets nature or
    * projects with the Java nature.
@@ -768,34 +770,9 @@
     status[0] = Status.OK_STATUS;
     final Set actions = getInstallActions(projectFacetVersions);
     
-    // Create a runnable that applies the install actions to the faceted project
-    IRunnableWithProgress runnable = new IRunnableWithProgress()
-    {
-      public void run(IProgressMonitor shellMonitor) throws InvocationTargetException, InterruptedException
-      {
-        try
-        {
-          fproject.modify(actions, shellMonitor);
-        } catch (CoreException e)
-        {
-          status[0] = getErrorStatusForAddingFacets(fproject.getProject().getName(), projectFacetVersions, e);
-        }
-      }
-    };    
-        
-    // Run the runnable in another thread unless there is no UI thread (Ant scenarios)    
-    if (displayPresent())
-    {    	
-	    try
-	    {
-	      PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);
-	    } catch (InvocationTargetException ite)
-	    {
-	      status[0] = getErrorStatusForAddingFacets(fproject.getProject().getName(), projectFacetVersions, ite);
-	    } catch (InterruptedException ie)
-	    {
-	      status[0] = getErrorStatusForAddingFacets(fproject.getProject().getName(), projectFacetVersions, ie);
-	    }
+    if (isExtensionPresent())
+    {    
+    	status[0] = delegate.addFacetsToProject(fproject, projectFacetVersions);
 	}
 	else
 	{
@@ -857,57 +834,29 @@
     final IStatus[] status = new IStatus[1];
     status[0] = Status.OK_STATUS;
     IProject project = ProjectUtilities.getProject(projectName);
+    
     if (!project.exists())
     {
-      // Create a runnable that creates a new faceted project.
-      IRunnableWithProgress runnable = new IRunnableWithProgress()
-      {
-        public void run(IProgressMonitor shellMonitor) throws InvocationTargetException, InterruptedException
-        {
-          try
-          {
-            IFacetedProject fProject = ProjectFacetsManager.create(projectName, null, shellMonitor);
-            if (fProject == null)
-            {
-              status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }));
-            }
-          } catch (CoreException e)
-          {
-            status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }), e);
-          }
-        }
-      };
-
-    // Run the runnable in another thread unless there is no UI thread (Ant scenarios)    	  
-      try
-      {
-    	  if (displayPresent())
-    	  {
-    		  PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);    		  
-    	  }
-    	  else
-    	  {
-    		  try
+		if (isExtensionPresent())
+		{
+		  status[0] = delegate.createNewFacetedProject(projectName);
+	  	}
+	  	else
+	  	{
+  		  try
+  		  {
+              IFacetedProject fProject = ProjectFacetsManager.create(projectName, null, null);
+              if (fProject == null)
               {
-                IFacetedProject fProject = ProjectFacetsManager.create(projectName, null, null);
-                if (fProject == null)
-                {
-                  status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }));
-                }
-              } catch (CoreException e)
-              {
-                status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }), e);
-              }  
-    	  }        
-      } catch (InvocationTargetException ite)
-      {
-        status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }), ite);
-      } catch (InterruptedException ie)
-      {
-        status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }), ie);
-      }
+                status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }));
+              }
+  		  } 
+  		  catch (CoreException e)
+  		  {
+              status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }), e);
+  		  }  
+	  	}        
     }
-
     return status[0];
   }
   
@@ -927,34 +876,9 @@
     final IStatus[] status = new IStatus[1];
     status[0] = Status.OK_STATUS;
 
-    //Create a runnable that sets the fixed facets on the faceted project
-    IRunnableWithProgress runnable = new IRunnableWithProgress()
+    if (isExtensionPresent())
     {
-      public void run(IProgressMonitor shellMonitor) throws InvocationTargetException, InterruptedException
-      {
-        try
-        {
-          fProject.setFixedProjectFacets(fixedFacets);
-        } catch (CoreException e)
-        {
-          status[0] = getErrorStatusForSettingFixedFacets(fProject.getProject().getName(), fixedFacets, e);
-        }
-      }
-    };
-
-    // Run the runnable in another thread unless there is no UI thread (Ant scenarios)
-    if (displayPresent())
-    {
-    	try
-        {
-          PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);
-        } catch (InvocationTargetException ite)
-        {
-          status[0] = getErrorStatusForSettingFixedFacets(fProject.getProject().getName(), fixedFacets, ite);
-        } catch (InterruptedException ie)
-        {
-          status[0] = getErrorStatusForSettingFixedFacets(fProject.getProject().getName(), fixedFacets, ie);
-        }	
+    	status[0] = delegate.setFixedFacetsOnProject(fProject, fixedFacets);
     }
     else
     {
@@ -1008,34 +932,9 @@
     final IStatus[] status = new IStatus[1];
     status[0] = Status.OK_STATUS;
 
-    //Create a runnable that sets the facet runtime on the faceted project
-    IRunnableWithProgress runnable = new IRunnableWithProgress()
+    if (isExtensionPresent())
     {
-      public void run(IProgressMonitor shellMonitor) throws InvocationTargetException, InterruptedException
-      {
-        try
-        {
-        	fProject.setTargetedRuntimes(Collections.singleton(fRuntime), shellMonitor);
-        } catch (CoreException e)
-        {
-          status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_SETTING_RUNTIME, new String[] { fProject.getProject().getName(), fRuntime.getName() }), e);
-        }
-      }
-    };
-
-    // Run the runnable in another thread unless there is no UI thread (Ant scenarios)
-    if (displayPresent())
-    {
-    	try
-        {
-          PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);
-        } catch (InvocationTargetException ite)
-        {
-          status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_SETTING_RUNTIME, new String[] { fProject.getProject().getName(), fRuntime.getName() }), ite);
-        } catch (InterruptedException ie)
-        {
-          status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_SETTING_RUNTIME, new String[] { fProject.getProject().getName(), fRuntime.getName() }), ie);
-        }	
+    	status[0] = delegate.setFacetRuntimeOnProject(fProject, fRuntime);
     }
     else 
     {
@@ -1046,9 +945,7 @@
         {
           status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_SETTING_RUNTIME, new String[] { fProject.getProject().getName(), fRuntime.getName() }), e);
         }
-    }
-        
-    
+    }    
     return status[0];
   }
   
@@ -1471,26 +1368,34 @@
   		return rfv;
   	}
 	
-	// Check to see if SWT is active and the Display is present or not
-	private static boolean displayPresent() {
-		Bundle b = Platform.getBundle("org.eclipse.swt");
-	    if (b==null) {
-	    	return false;
-	    }
-	    if ((b.getState() != Bundle.RESOLVED && b.getState() != Bundle.ACTIVE) ) {
-	    	return false;
-	    }
-	    try {
-	    	if (Display.getCurrent() == null) {
-	    		return false;
-	    	} else {
-	    		return true;
-	    	}
-	    } catch (NoClassDefFoundError e1) {
-	    	return false;
-	    } catch (Exception e) {  // if the Display class cannot be loaded for whatever reason
-	    	return false;
-	    
-	    } 
+	private static boolean isExtensionPresent() {
+		
+		if (failedToLoadDelegate) {
+			return false;
+		} if (delegate != null) {
+			return true;
+		}
+		IExtensionRegistry registry = Platform.getExtensionRegistry();  
+		IExtensionPoint point = registry.getExtensionPoint("org.eclipse.jst.ws.consumption.internalFacetOperationDelegate");
+		if (point == null) {
+			failedToLoadDelegate = true;
+			return false;
+		}
+		IExtension[] extensions = point.getExtensions();
+
+		//this extension point is internal, we know there will only be zero or one plugged in
+		if (extensions.length > 0 && extensions[0] != null) {
+			IConfigurationElement[] elements = extensions[0].getConfigurationElements();
+			if (elements.length > 0 && elements[0] != null) {
+				try {
+					delegate = (IFacetOperationDelegate)elements[0].createExecutableExtension("class");
+					return true;
+				} catch (CoreException e) {
+					//do nothing, just report that we failed to load the extension
+				}
+			}
+		}
+		failedToLoadDelegate = true;//set this so we don't try to load it again
+		return false;
 	}
 }
diff --git a/bundles/org.eclipse.jst.ws.consumption/src/org/eclipse/jst/ws/internal/consumption/common/IFacetOperationDelegate.java b/bundles/org.eclipse.jst.ws.consumption/src/org/eclipse/jst/ws/internal/consumption/common/IFacetOperationDelegate.java
new file mode 100644
index 0000000..3d6a69d
--- /dev/null
+++ b/bundles/org.eclipse.jst.ws.consumption/src/org/eclipse/jst/ws/internal/consumption/common/IFacetOperationDelegate.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * yyyymmdd bug      Email and other contact information
+ * -------- -------- -----------------------------------------------------------
+ * 20090303   242635 mahutch@ca.ibm.com - Mark Hutchinson, Remove unnecessary UI dependencies from org.eclipse.jst.ws.consumption
+ *******************************************************************************/
+package org.eclipse.jst.ws.internal.consumption.common;
+
+import java.util.Set;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
+
+public interface IFacetOperationDelegate {
+
+	/**
+	  * Adds the provided set of facet versions to the provided faceted project
+	  * 
+	  * @param fproject A faceted project which exists in the workspace
+	  * @param projectFacetVersions A set containing elements of type {@link IProjectFacetVersion}
+	  * @return An IStatus with a severity of IStatus.OK if the facet 
+	  * versions were added successfully. Otherwise, an IStatus with a severity of
+	  * IStatus.ERROR. 
+	  */
+	 public IStatus addFacetsToProject(final IFacetedProject fproject, final Set projectFacetVersions);
+	 
+	 /**
+	   * Creates a new faceted project with the provided name
+	   * 
+	   * @param projectName A String containing the name of the project to be created
+	   * @return An IStatus with a severity of IStatus.OK if the faceted project
+	   * was created successfully or if a project of the provided name already
+	   * exists in the workspace. Otherwise, an IStatus with severity of
+	   * IStatus.ERROR. 
+	   */
+	  public IStatus createNewFacetedProject(final String projectName);
+	  
+	  /**
+	   * Sets the provided set of facets as fixed on the faceted project
+	   * 
+	   * @param fProject A faceted project which exists in the workspace
+	   * @param fixedFacets A set containing elements of type {@link IProjectFacet}
+	   * @return An IStatus with a severity of IStatus.OK if the facets 
+	   * were successfully set as fixed facets on the faceted project. 
+	   * Otherwise, an IStatus with a severity of IStatus.ERROR.
+	   * 
+	   * @see IFacetedProject#setFixedProjectFacets
+	   */
+	  public IStatus setFixedFacetsOnProject(final IFacetedProject fProject, final Set fixedFacets);
+	  
+	  /**
+	   * Binds the faceted project to the facet runtime
+	   * 
+	   * @param fProject A faceted project which exists in the workspace
+	   * @param fRuntime A facet runtime
+	   * @return An IStatus with a severity of IStatus.OK if the faceted project
+	   * was bound to the facet runtime successfully. Otherwise, an IStatus with severity of
+	   * IStatus.ERROR. 
+	   */
+	  public IStatus setFacetRuntimeOnProject(final IFacetedProject fProject, final IRuntime fRuntime);
+	
+}