[194624] XSD preview of the Element or Type is difficult to close
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/dialogs/XSDGraphViewerDialog.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/dialogs/XSDGraphViewerDialog.java
index fa66e20..37203f0 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/dialogs/XSDGraphViewerDialog.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/dialogs/XSDGraphViewerDialog.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2008 IBM Corporation and others.
+ * Copyright (c) 2007, 2010 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
@@ -32,6 +32,7 @@
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorPart;
@@ -71,7 +72,7 @@
 
   public XSDGraphViewerDialog(Shell parentShell, String titleText, String infoText, Object model, String ID)
   {
-    super(parentShell, HOVER_SHELLSTYLE, true, true, true, false, titleText, infoText);
+    super(parentShell, HOVER_SHELLSTYLE, true, true, true, true, false, titleText, infoText);
     setModel(model);
     linkListener = new OpenEditorLinkListener();
     this.infoText = infoText;
@@ -97,13 +98,15 @@
   {
     super.fillDialogMenu(dialogMenu);
     dialogMenu.add(new Separator());
+    dialogMenu.add(new ClosePopup());
+    dialogMenu.add(new Separator());
     dialogMenu.add(new SetOpenInEditor());
   }
 
   protected Control createDialogArea(Composite parent)
   {
     viewer = new ScrollingGraphicalViewer();
-    Composite c = new Composite(parent, SWT.NONE);
+    Composite c = (Composite)super.createDialogArea(parent);
 
     if (isHighContrast)
     {
@@ -119,6 +122,11 @@
     viewer.setRootEditPart(root);
 
     viewer.createControl(c);
+
+    // The graphical viewer tool tip processing creates an extra shell which
+    // interferes with the PopupDialog's deactivation logic. 
+    removeMouseListeners(viewer.getControl());    
+
     if (isHighContrast)
     {
       viewer.getControl().setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
@@ -137,6 +145,30 @@
     getShell().addControlListener(moveListener);
     return c;
   }
+
+  private void removeMouseListeners(Control control)
+  {
+    Listener[] listeners = control.getListeners(SWT.MouseEnter);
+    control.removeListener(SWT.MouseEnter, listeners[0]);
+    
+    listeners = control.getListeners(SWT.MouseExit);
+    control.removeListener(SWT.MouseExit, listeners[0]);    
+
+    listeners = control.getListeners(SWT.MouseHover);
+    control.removeListener(SWT.MouseHover, listeners[0]);    
+
+    listeners = control.getListeners(SWT.MouseMove);
+    control.removeListener(SWT.MouseMove, listeners[0]);    
+
+    listeners = control.getListeners(SWT.MouseDown);
+    control.removeListener(SWT.MouseDown, listeners[0]);    
+
+    listeners = control.getListeners(SWT.MouseUp);
+    control.removeListener(SWT.MouseUp, listeners[0]);    
+    
+    listeners = control.getListeners(SWT.MouseDoubleClick);
+    control.removeListener(SWT.MouseDoubleClick, listeners[0]);
+  }
   
   protected Control createInfoTextArea(Composite parent)
   {
@@ -199,6 +231,18 @@
     }
   }
   
+  private class ClosePopup extends Action {
+    public ClosePopup()
+    {
+      super(Messages._UI_ACTION_CLOSE_SCHEMA_PREVIEW_POPUP);
+    }
+
+    public void run()
+    {
+      close();
+    }
+  }
+  
   protected IDialogSettings getDialogSettings()
   {
     IDialogSettings settings= XSDEditorPlugin.getDefault().getDialogSettings().getSection(uniqueID);
@@ -259,6 +303,11 @@
   
   public boolean close()
   {
+    if (getShell() == null || getShell().isDisposed()) 
+    {
+      return true;
+    }
+    
     getShell().removeControlListener(moveListener);
     if (link != null)
       link.removeHyperlinkListener(linkListener);
@@ -356,4 +405,9 @@
     }
     return null;
   }
+  
+  protected Control getFocusControl()
+  {
+    return link;
+  }  
 }
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/Messages.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/Messages.java
index 7110fa3..5f5b65b 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/Messages.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/Messages.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2001, 2009 IBM Corporation and others.
+ * Copyright (c) 2001, 2010 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
@@ -122,6 +122,7 @@
   public static String _UI_FORM;
   public static String _UI_USAGE;
   public static String _UI_ACTION_CHANGE;
+  public static String _UI_ACTION_CLOSE_SCHEMA_PREVIEW_POPUP;
   public static String _UI_ACTION_NAMESPACE_INFORMATION_CHANGE;
   public static String _UI_LABEL_ABSTRACT;
   public static String _UI_LABEL_BLOCK;
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/messages.properties b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/messages.properties
index 789580e..ab3fe6d 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/messages.properties
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/messages.properties
@@ -1,5 +1,5 @@
 ###############################################################################
-# Copyright (c) 2001, 2009 IBM Corporation and others.
+# Copyright (c) 2001, 2010 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
@@ -111,6 +111,7 @@
 # The following string will be used for the undo action.  An
 # example label is: Undo Abstract Change
 _UI_ACTION_CHANGE={0} Change
+_UI_ACTION_CLOSE_SCHEMA_PREVIEW_POPUP=&Close
 _UI_ACTION_NAMESPACE_INFORMATION_CHANGE=Namespace Information Change
 _UI_LABEL_ABSTRACT=Abstract
 _UI_LABEL_BLOCK=Block