[221376] Deadlock at the FacetedProjectFramework probably while trying to change the runtime
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/FacetedProjectFrameworkImpl.java b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/FacetedProjectFrameworkImpl.java
index 32366c3..26768d3 100644
--- a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/FacetedProjectFrameworkImpl.java
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/FacetedProjectFrameworkImpl.java
@@ -661,22 +661,22 @@
         if( project.isAccessible() &&
             project.isNatureEnabled( FacetedProjectNature.NATURE_ID ) )
         {
+            FacetedProject fproj = null;
+            
             synchronized( this.projects )
             {
-                FacetedProject fproj = this.projects.get( project.getName() );
+                fproj = this.projects.get( project.getName() );
                 
                 if( fproj == null )
                 {
                     fproj = new FacetedProject( project );
                     this.projects.put( project.getName(), fproj );
                 }
-                else
-                {
-                    fproj.refresh();
-                }
-                
-                return fproj;
             }
+
+            fproj.refresh();
+            
+            return fproj;
         }
 
         return null;
diff --git a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/FacetsPropertyPage.java b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/FacetsPropertyPage.java
index e006e84..c828a45 100644
--- a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/FacetsPropertyPage.java
+++ b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/FacetsPropertyPage.java
@@ -17,6 +17,7 @@
 import static org.eclipse.wst.common.project.facet.ui.internal.util.GridLayoutUtil.gdhhint;
 import static org.eclipse.wst.common.project.facet.ui.internal.util.GridLayoutUtil.gl;
 import static org.eclipse.wst.common.project.facet.ui.internal.util.GridLayoutUtil.glmargins;
+import static org.eclipse.wst.common.project.facet.ui.internal.util.SwtUtil.runOnDisplayThread;
 
 import java.lang.reflect.InvocationTargetException;
 import java.util.Set;
@@ -236,9 +237,17 @@
 	
 	private void handleProjectModifiedEvent()
 	{
-		updateApplyButton();
-		getContainer().updateButtons();
-		updateFurtherConfigHyperlink();
+        final Runnable runnable = new Runnable()
+        {
+            public void run()
+            {
+                updateApplyButton();
+                getContainer().updateButtons();
+                updateFurtherConfigHyperlink();
+            }
+        };
+        
+        runOnDisplayThread( this.topComposite.getDisplay(), runnable );
 	}
 	
 	private void updateFurtherConfigHyperlink()
diff --git a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/FacetsSelectionPanel.java b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/FacetsSelectionPanel.java
index 7de0fc5..0b3e21b 100644
--- a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/FacetsSelectionPanel.java
+++ b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/FacetsSelectionPanel.java
@@ -20,7 +20,7 @@
 import static org.eclipse.wst.common.project.facet.ui.internal.util.GridLayoutUtil.gdwhint;
 import static org.eclipse.wst.common.project.facet.ui.internal.util.GridLayoutUtil.gl;
 import static org.eclipse.wst.common.project.facet.ui.internal.util.GridLayoutUtil.glmargins;
-import static org.eclipse.wst.common.project.facet.ui.internal.util.SwtUtil.getPreferredWidth;
+import static org.eclipse.wst.common.project.facet.ui.internal.util.SwtUtil.*;
 
 import java.lang.reflect.Method;
 import java.net.URL;
@@ -1063,7 +1063,8 @@
                 }
             };
             
-            getDisplay().syncExec( uiRunnable );
+            getDisplay().asyncExec( uiRunnable );
+            
             return;
         }
         
@@ -1106,14 +1107,18 @@
         switch( event.getType() )
         {
             case FIXED_FACETS_CHANGED:
-            {
-                refresh();
-                
-                break;
-            }
             case TARGETED_RUNTIMES_CHANGED:
             {
-                refresh();
+                final Runnable runnable = new Runnable()
+                {
+                    public void run()
+                    {
+                        refresh();
+                    }
+                };
+                
+                runOnDisplayThread( getDisplay(), runnable );
+                
                 break;
             }
         }
diff --git a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/util/SwtUtil.java b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/util/SwtUtil.java
index b12c62f..f116724 100644
--- a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/util/SwtUtil.java
+++ b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/util/SwtUtil.java
@@ -13,6 +13,7 @@
 
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
 
 /**
  * @author <a href="mailto:kosta@bea.com">Konstantin Komissarchik</a>
@@ -24,5 +25,18 @@
     {
         return control.computeSize( SWT.DEFAULT, SWT.DEFAULT ).x;
     }
+    
+    public static void runOnDisplayThread( final Display display,
+                                           final Runnable runnable )
+    {
+        if( display.getThread() == Thread.currentThread() )
+        {
+            runnable.run();
+        }
+        else
+        {
+            display.asyncExec( runnable );
+        }
+    }
 
 }