[253264] [Extensibility] Provide extensibility in the refactoring context menu
diff --git a/bundles/org.eclipse.wst.xsd.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.wst.xsd.ui/META-INF/MANIFEST.MF
index e74cec9..58b1452 100644
--- a/bundles/org.eclipse.wst.xsd.ui/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.wst.xsd.ui/META-INF/MANIFEST.MF
@@ -45,6 +45,7 @@
  org.eclipse.wst.xsd.ui.internal.preferences;x-internal:=true,
  org.eclipse.wst.xsd.ui.internal.refactor;x-internal:=true,
  org.eclipse.wst.xsd.ui.internal.refactor.actions;x-internal:=true,
+ org.eclipse.wst.xsd.ui.internal.refactor.handlers,
  org.eclipse.wst.xsd.ui.internal.refactor.rename;x-internal:=true,
  org.eclipse.wst.xsd.ui.internal.refactor.structure;x-internal:=true,
  org.eclipse.wst.xsd.ui.internal.refactor.util;x-internal:=true,
@@ -79,6 +80,7 @@
  org.eclipse.ltk.ui.refactoring;bundle-version="[3.2.0,4.0.0)",
  org.eclipse.wst.xsd.core;bundle-version="[1.1.300,1.2.0)",
  org.eclipse.search;bundle-version="[3.2.0,4.0.0)",
+ org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)",
  org.eclipse.core.filesystem;bundle-version="[1.2.0,2.0.0)"
 Import-Package: com.ibm.icu.util;version="3.8.1"
 Bundle-ActivationPolicy: lazy
diff --git a/bundles/org.eclipse.wst.xsd.ui/plugin.properties b/bundles/org.eclipse.wst.xsd.ui/plugin.properties
index ba4dbfa..0d877a8 100644
--- a/bundles/org.eclipse.wst.xsd.ui/plugin.properties
+++ b/bundles/org.eclipse.wst.xsd.ui/plugin.properties
@@ -790,11 +790,11 @@
 refactoring.menu.label=Refac&tor
 refactoring.renameAction.label=Re&name...
 context.text.editor.xsd.name=Editing XSD context
-command.xsd.refactor.rename.element.name=Rename XSD element
+command.xsd.refactor.rename.element.name=&Rename XSD element
 command.xsd.refactor.rename.element.description=Rename XSD element
-command.xsd.refactor.makeElementGlobal.element.name=Make local element global
+command.xsd.refactor.makeElementGlobal.element.name=Make Local Element &Global
 command.xsd.refactor.makeElementGlobal.element.description=Promotes local element to global level and replaces its references
-command.xsd.refactor.makeTypeGlobal.element.name=Make anonymous type global
+command.xsd.refactor.makeTypeGlobal.element.name=Make &Anonymous Type Global
 command.xsd.refactor.makeTypeGlobal.element.description=Promotes anonymous type to global level and replaces its references
 command.xsd.refactor.renameTargetNamespace.name=Rename Target Namespace
 command.xsd.refactor.renameTargetNamespace.description=Changes the target namespace of the schema
@@ -841,4 +841,10 @@
 XMLSchemaEditorModes = XML Schema Editor Modes
 ##
 XSD_Source_target_name=XML Schema Source
-XSD_hyperlink=XML Schema Content
\ No newline at end of file
+XSD_hyperlink=XML Schema Content
+
+
+XSD_DESIGN_VIEW_DESCRIPTION=XSD Editor Design View
+XSD_DESIGN_VIEW=XSD Editor Design View
+XSD_SOURCE_VIEW_DESCRIPTION=XSD Editor Source View
+XSD_SOURCE_VIEW=XSD Editor Source View
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xsd.ui/plugin.xml b/bundles/org.eclipse.wst.xsd.ui/plugin.xml
index 05d7ef2..03449f6 100644
--- a/bundles/org.eclipse.wst.xsd.ui/plugin.xml
+++ b/bundles/org.eclipse.wst.xsd.ui/plugin.xml
@@ -385,73 +385,11 @@
             label="%search.references.label"
             class="org.eclipse.wst.xsd.ui.internal.search.actions.XSDSearchReferencesGroupActionDelegate"> 
          </action>
-         <action
-            id="org.eclipse.wst.xsd.ui.refactoring.menu.refactorGroup.object" 
-            enablesFor="1"
-            style="pulldown"
-            menubarPath="refactoring-slot"
-            label="%refactoringActionSet.label" 
-            class="org.eclipse.wst.xsd.ui.internal.refactor.actions.XSDRefactorGroupActionDelegate"> 
-         </action>   
+  
       </objectContribution>         
-      <!-- here we add the 'refactor' menu item to the source view -->
-      <viewerContribution
-        id="org.eclipse.wst.xsd.ui.refactoring.menu.source"
-        targetID="org.eclipse.wst.xsd.core.xsdsource.source.EditorContext">
-	    <action id="org.eclipse.wst.xsd.ui.refactoring.menu.refactorGroup.source"
-       		style="pulldown"
-            menubarPath="additions"
-            label="%refactoring.menu.label" 
-            class="org.eclipse.wst.xsd.ui.internal.refactor.actions.XSDRefactorGroupActionDelegate"> 
-  	    </action>
-       </viewerContribution>
-		<viewerContribution
-			targetID="org.eclipse.wst.xsd.core.xsdsource.source.RulerContext"
-			id="org.eclipse.wst.xsd.ui.ruler.context.actions">
-			<action
-				label="%AddTask.label"
-				helpContextId="org.eclipse.ui.AddTask_action_context"
-				class="org.eclipse.ui.texteditor.TaskRulerAction"
-				tooltip="%AddTask.tooltip"
-				menubarPath="additions"
-				id="org.eclipse.ui.texteditor.TaskRulerAction">
-			</action>
-			<action
-				label="%AddBookmark.label"
-				helpContextId="org.eclipse.ui.bookmark_action_context"
-				class="org.eclipse.ui.texteditor.BookmarkRulerAction"
-				tooltip="%AddBookmark.tooltip"
-				menubarPath="additions"
-				id="org.eclipse.ui.texteditor.BookmarkRulerAction">
-			</action>
-		</viewerContribution>
-
+    
      </extension>
 
-	
-	<!-- 
-		The following extension to the file context menu is temporary until resource 
-		navigator will provide allow to extend refactor menu        
-	-->
-	
-	<!--extension point="org.eclipse.ui.popupMenus">
-	 <objectContribution
-		objectClass="org.eclipse.core.resources.IFile"
-		nameFilter="*.xsd"
-		id="org.wst.xsd.ui.rename">
-		<menu id="refactorXSDResource" path="additions" label="%refactoring.menu.label">
-		  <separator name="refactor"/>
-		</menu>
-	<action
-		label="%refactoring.renameAction.label"
-		menubarPath="refactorXSDResource/refactor"
-		class="org.eclipse.wst.xsd.ui.internal.refactor.actions.RenameResourceActionDelegate"
-		enablesFor="1"
-		id="org.eclipse.wst.xsd.ui.refactoring.actions.RenameResource">
-	 </action>
-	 </objectContribution>
-	</extension-->	
-
 	<extension point="org.eclipse.ui.commands">
 		<command
 			name="%command.xsd.refactor.rename.element.name"
@@ -511,6 +449,120 @@
            </visibleWhen>         
         </command>        
      </menuContribution>
+     <menuContribution locationURI="popup:refactorPopupMenuId">
+        <command
+              commandId="org.eclipse.wst.xsd.ui.refactor.rename.element"
+              label="%refactoring.renameAction.label">
+           <visibleWhen
+                 checkEnabled="false">
+           </visibleWhen>
+        </command>
+    </menuContribution>
+    <menuContribution
+          locationURI="popup:org.eclipse.wst.xsd.ui.refactorMenuId">
+          <command
+                commandId="org.eclipse.wst.xsd.ui.refactor.rename.element"
+                label="%refactoring.renameAction.label">
+             <visibleWhen
+                   checkEnabled="false">
+             </visibleWhen>
+        </command>
+    </menuContribution>
+	<menuContribution
+          locationURI="menu:refactorMenuId">
+       <command
+             commandId="org.eclipse.wst.xsd.ui.refactor.rename.element"
+             label="%refactoring.renameAction.label">
+          <visibleWhen
+                checkEnabled="false">
+                <or>
+	                <reference
+	                      definitionId="org.eclipse.wst.xsd.ui.editor.active.designView.definition">
+	                </reference>
+	                <reference
+	                      definitionId="org.eclipse.wst.xsd.ui.editor.active.sourceView.definition">
+	                </reference>
+                </or>
+          </visibleWhen>
+          
+        </command>
+    </menuContribution>
+    <menuContribution locationURI="popup:refactorPopupMenuId">
+        <command
+              commandId="org.eclipse.wst.xsd.ui.refactor.makeElementGlobal"
+              label="%command.xsd.refactor.makeElementGlobal.element.name">
+           <visibleWhen
+                 checkEnabled="false">
+           </visibleWhen>
+        </command>
+    </menuContribution>
+    <menuContribution
+          locationURI="popup:org.eclipse.wst.xsd.ui.refactorMenuId">
+          <command
+                commandId="org.eclipse.wst.xsd.ui.refactor.makeElementGlobal"
+                label="%command.xsd.refactor.makeElementGlobal.element.name">
+             <visibleWhen
+                   checkEnabled="false">
+             </visibleWhen>
+        </command>
+    </menuContribution>
+	<menuContribution
+          locationURI="menu:refactorMenuId">
+       <command
+             commandId="org.eclipse.wst.xsd.ui.refactor.makeElementGlobal"
+             label="%command.xsd.refactor.makeElementGlobal.element.name">
+          <visibleWhen
+                checkEnabled="false">
+                <or>
+	                <reference
+	                      definitionId="org.eclipse.wst.xsd.ui.editor.active.designView.definition">
+	                </reference>
+	                <reference
+	                      definitionId="org.eclipse.wst.xsd.ui.editor.active.sourceView.definition">
+	                </reference>
+                </or>
+          </visibleWhen>
+          
+        </command>
+    </menuContribution>
+     <menuContribution locationURI="popup:refactorPopupMenuId">
+        <command
+              commandId="org.eclipse.wst.xsd.ui.refactor.makeTypeGlobal"
+              label="%command.xsd.refactor.makeTypeGlobal.element.name">
+           <visibleWhen
+                 checkEnabled="false">
+           </visibleWhen>
+        </command>
+    </menuContribution>
+    <menuContribution
+          locationURI="popup:org.eclipse.wst.xsd.ui.refactorMenuId">
+          <command
+                commandId="org.eclipse.wst.xsd.ui.refactor.makeTypeGlobal"
+                label="%command.xsd.refactor.makeTypeGlobal.element.name">
+             <visibleWhen
+                   checkEnabled="false">
+             </visibleWhen>
+        </command>
+    </menuContribution>
+	<menuContribution
+          locationURI="menu:refactorMenuId">
+       <command
+             commandId="org.eclipse.wst.xsd.ui.refactor.makeTypeGlobal"
+             label="%command.xsd.refactor.makeTypeGlobal.element.name">
+          <visibleWhen
+                checkEnabled="false">
+                <or>
+	                <reference
+	                      definitionId="org.eclipse.wst.xsd.ui.editor.active.designView.definition">
+	                </reference>
+	                <reference
+	                      definitionId="org.eclipse.wst.xsd.ui.editor.active.sourceView.definition">
+	                </reference>
+                </or>
+          </visibleWhen>
+          
+        </command>
+    </menuContribution>
   </extension>
 
  <extension point="org.eclipse.ui.navigator.navigatorContent">
@@ -518,4 +570,112 @@
 		<enablement></enablement>
 	</commonWizard>
  </extension>
+ <extension
+         point="org.eclipse.ui.handlers">
+      <handler
+            class="org.eclipse.wst.xsd.ui.internal.refactor.handlers.RenameHandler"
+            commandId="org.eclipse.wst.xsd.ui.refactor.rename.element">
+         <enabledWhen>
+                <with
+	                   variable="selection">
+                 <test
+                       property="org.eclipse.wst.xsd.ui.refactor.renameEnabled">
+                 </test>
+	                
+	             </with>             
+		</enabledWhen>
+      </handler>
+     <handler
+            class="org.eclipse.wst.xsd.ui.internal.refactor.handlers.MakeLocalElementGlobalHandler"
+            commandId="org.eclipse.wst.xsd.ui.refactor.makeElementGlobal">
+         <enabledWhen>
+                <with
+	                   variable="selection">
+                 <test
+                       property="org.eclipse.wst.xsd.ui.refactor.makeLocalElementGlobalEnabled">
+                 </test>
+	                
+	             </with>             
+		</enabledWhen>
+      </handler>
+      <handler
+            class="org.eclipse.wst.xsd.ui.internal.refactor.handlers.MakeAnonymousTypeGobalHandler"
+            commandId="org.eclipse.wst.xsd.ui.refactor.makeTypeGlobal">
+         <enabledWhen>
+                <with
+	                   variable="selection">
+                 <test
+                       property="org.eclipse.wst.xsd.ui.refactor.makeAnonymousTypeGlobalEnabled">
+                 </test>
+	                
+	             </with>             
+		</enabledWhen>
+      </handler>
+   </extension>
+   <extension
+         point="org.eclipse.core.expressions.propertyTesters">
+      <propertyTester
+            class="org.eclipse.wst.xsd.ui.internal.refactor.RenameEnablementTester"
+            id="org.eclipse.wst.xsd.ui.refactor.rename.enablement"
+            namespace="org.eclipse.wst.xsd.ui.refactor"
+            properties="renameEnabled"
+            type="org.eclipse.jface.viewers.ISelection">
+      </propertyTester>
+      <propertyTester
+            class="org.eclipse.wst.xsd.ui.internal.refactor.MakeLocalElementGlobalEnablementTester"
+            id="org.eclipse.wst.xsd.ui.refactor.makeLocalElementGlobalEnabled"
+            namespace="org.eclipse.wst.xsd.ui.refactor"
+            properties="makeLocalElementGlobalEnabled"
+            type="org.eclipse.jface.viewers.ISelection">
+      </propertyTester>
+       <propertyTester
+            class="org.eclipse.wst.xsd.ui.internal.refactor.MakeAnonymousTypsGlobalEnablementTester"
+            id="org.eclipse.wst.xsd.ui.refactor.makeAnonymousTypeGlobalEnabled"
+            namespace="org.eclipse.wst.xsd.ui.refactor"
+            properties="makeAnonymousTypeGlobalEnabled"
+            type="org.eclipse.jface.viewers.ISelection">
+      </propertyTester>
+      
+   </extension>
+   <extension
+         point="org.eclipse.ui.contexts">
+      <context
+            description="%XSD_DESIGN_VIEW_DESCRIPTION"
+            id="org.eclipse.wst.xsd.ui.editor.designView"
+            name="%XSD_DESIGN_VIEW">
+      </context>
+            <context
+            description="%XSD_SOURCE_VIEW_DESCRIPTION"
+            id="org.eclipse.wst.xsd.ui.editor.sourceView"
+            name="%XSD_SOURCE_VIEW">
+      </context>
+   </extension>
+   <extension
+         point="org.eclipse.core.expressions.definitions">
+      <definition
+            id="org.eclipse.wst.xsd.ui.editor.active.designView.definition">
+         <with
+               variable="activeContexts">
+            <iterate
+                  operator="or">
+               <equals
+                     value="org.eclipse.wst.xsd.ui.editor.designView">
+               </equals>
+            </iterate>
+         </with>
+      </definition>
+      <definition
+            id="org.eclipse.wst.xsd.ui.editor.active.sourceView.definition">
+         <with
+               variable="activeContexts">
+            <iterate
+                  operator="or">
+               <equals
+                     value="org.eclipse.wst.xsd.ui.editor.sourceView">
+               </equals>
+            </iterate>
+         </with>
+      </definition>
+   </extension>  
+   
 </plugin>
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/DesignViewContextMenuProvider.java b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/DesignViewContextMenuProvider.java
index af85cb2..a13e440 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/DesignViewContextMenuProvider.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/DesignViewContextMenuProvider.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
@@ -29,6 +29,8 @@
 import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.IActionProvider;
 import org.eclipse.wst.xsd.ui.internal.adt.editor.ContextMenuParticipant;
 import org.eclipse.wst.xsd.ui.internal.adt.editor.EditorModeManager;
+import org.eclipse.wst.xsd.ui.internal.adt.editor.Messages;
+import org.eclipse.wst.xsd.ui.internal.refactor.IXSDRefactorConstants;
 
 
 public class DesignViewContextMenuProvider extends ContextMenuProvider
@@ -111,7 +113,8 @@
           }
         }
         menu.add(new Separator());       
-        menu.add(new Separator("refactoring-slot"));  //$NON-NLS-1$
+        IMenuManager subMenu = new MenuManager(Messages._UI_REFACTOR_CONTEXT_MENU, IXSDRefactorConstants.REFACTOR_CONTEXT_MENU_ID); //$NON-NLS-1$
+        menu.add(subMenu);
         menu.add(new Separator());       
         menu.add(new Separator("search-slot"));        //$NON-NLS-1$
         menu.add(new Separator());
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/editor/ADTMultiPageEditor.java b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/editor/ADTMultiPageEditor.java
index 34ff17a..dbd3b7c 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/editor/ADTMultiPageEditor.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/editor/ADTMultiPageEditor.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2001, 2008 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
@@ -34,6 +34,8 @@
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.contexts.IContextActivation;
+import org.eclipse.ui.contexts.IContextService;
 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
 import org.eclipse.wst.xsd.ui.internal.adt.actions.BaseSelectionAction;
 import org.eclipse.wst.xsd.ui.internal.adt.actions.SetInputToGraphView;
@@ -52,6 +54,9 @@
   private int currentPage = -1;
   protected Button tableOfContentsButton;
   protected ADTFloatingToolbar floatingToolbar;
+  private IContextActivation contextActivation;
+  public final static String DESIGN_VIEW_CONTEXT = "org.eclipse.wst.xsd.ui.editor.designView"; //$NON-NLS-1$
+  public final static String SOURCE_VIEW_CONTEXT = "org.eclipse.wst.xsd.ui.editor.sourceView"; //$NON-NLS-1$
   
   /**
    * Creates a multi-page editor example.
@@ -210,9 +215,13 @@
 
   protected void pageChange(int newPageIndex)
   {
+	deactivateContext(contextActivation);
     currentPage = newPageIndex;
     super.pageChange(newPageIndex);
     
+    String context = getContext(currentPage);
+    contextActivation = activateContext(context);
+    
     if (newPageIndex == DESIGN_PAGE_INDEX)
     {
       ISelection selection = graphicalViewer.getSelectionManager().getSelection();
@@ -332,6 +341,33 @@
       XSDEditorPlugin.getPlugin().setDesignPageAsDefault();
     }
     floatingToolbar = null;
+	deactivateContext(contextActivation);
     super.dispose();
   }
+  protected String getContext(int pageIndex) {
+	  if (pageIndex == DESIGN_PAGE_INDEX) {
+		  return DESIGN_VIEW_CONTEXT;
+	  } else if (pageIndex == SOURCE_PAGE_INDEX) {
+		  return SOURCE_VIEW_CONTEXT;
+	  }
+	  
+	  return null;
+  }
+  private IContextActivation activateContext(String context) {
+	  IContextService contextService = (IContextService) getSite().getService(IContextService.class);
+
+	  if (contextService != null && context != null) {
+		  return contextActivation = contextService.activateContext(context);
+	  }
+	  return null;
+  }
+  
+  private void deactivateContext(IContextActivation contextActivation) {
+	  IContextService contextService = (IContextService) getSite().getService(IContextService.class);
+
+	  if (contextService != null && contextActivation != null) {
+		  contextService.deactivateContext(contextActivation);
+	  }
+  }
+
 }
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/editor/Messages.java b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/editor/Messages.java
index fce3ae6..1dd9e3a 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/editor/Messages.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/editor/Messages.java
@@ -49,4 +49,5 @@
   public static String _UI_ACTION_CAPTURE_SCREEN_DEFAULT_FILE_NAME;
   public static String _UI_ACTION_CAPTURE_SCREEN_FILE_SAVE_DIALOG_TITLE;
   public static String _UI_HOVER_BACK_TO_SCHEMA;
+  public static String _UI_REFACTOR_CONTEXT_MENU;
 }
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/editor/messages.properties b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/editor/messages.properties
index 27455d9..f85a63f 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/editor/messages.properties
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/editor/messages.properties
@@ -33,3 +33,4 @@
 _UI_ACTION_CAPTURE_SCREEN_FILE_SAVE_DIALOG_TITLE=Export Diagram as Image
 _UI_HOVER_BACK_TO_SCHEMA=Show schema index view
 _UI_ACTION_SELECT_ALL=Select &All
+_UI_REFACTOR_CONTEXT_MENU=Refac&tor
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/RefactoringSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/RefactoringSection.java
index 644ef65..b9efd04 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/RefactoringSection.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/RefactoringSection.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2006, 2009 IBM Corporation and others.
+ * Copyright (c) 2006, 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
@@ -23,7 +23,7 @@
 import org.eclipse.wst.xsd.ui.internal.common.util.Messages;
 import org.eclipse.wst.xsd.ui.internal.editor.ISelectionMapper;
 import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin;
-import org.eclipse.wst.xsd.ui.internal.refactor.actions.RenameComponentAction;
+import org.eclipse.wst.xsd.ui.internal.refactor.handlers.RenameHandler;
 import org.eclipse.xsd.XSDSchema;
 
 public abstract class RefactoringSection extends AbstractSection implements IHyperlinkListener
@@ -45,9 +45,8 @@
     ISelection selection = new StructuredSelection(input);
     ISelectionMapper mapper = (ISelectionMapper) editor.getAdapter(ISelectionMapper.class);
     selection = mapper != null ? mapper.mapSelection(selection) : selection;
-    RenameComponentAction action = new RenameComponentAction(selection, schema);
-    action.update(selection);
-    action.run();
+    RenameHandler renameHandler = new RenameHandler();
+    renameHandler.execute(selection, schema);
   }
 
   protected void showLink(boolean isVisible)
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/IXSDRefactorConstants.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/IXSDRefactorConstants.java
new file mode 100644
index 0000000..79dfec1
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/IXSDRefactorConstants.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.ui.internal.refactor;
+
+public interface IXSDRefactorConstants {
+	String REFACTOR_CONTEXT_MENU_ID = "org.eclipse.wst.xsd.ui.refactorMenuId"; //$NON-NLS-1$
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/MakeAnonymousTypsGlobalEnablementTester.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/MakeAnonymousTypsGlobalEnablementTester.java
new file mode 100644
index 0000000..a257bb7
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/MakeAnonymousTypsGlobalEnablementTester.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.ui.internal.refactor;
+
+
+import org.eclipse.xsd.XSDAttributeDeclaration;
+import org.eclipse.xsd.XSDComplexTypeDefinition;
+import org.eclipse.xsd.XSDConcreteComponent;
+import org.eclipse.xsd.XSDElementDeclaration;
+import org.eclipse.xsd.XSDSchema;
+import org.eclipse.xsd.XSDSimpleTypeDefinition;
+
+
+public class MakeAnonymousTypsGlobalEnablementTester extends RefactorEnablementTester
+{
+
+  protected boolean canEnable(XSDConcreteComponent selectedObject, XSDSchema schema)
+  {
+    if (selectedObject == null)
+    {
+      return false;
+    }
+
+    XSDSchema selectedComponentSchema = null;
+    boolean enable = false;
+    selectedComponentSchema = selectedObject.getSchema();
+
+    if (selectedComponentSchema != null && selectedComponentSchema == schema)
+    {
+      enable = true;
+    }
+
+    if (enable && selectedObject instanceof XSDComplexTypeDefinition)
+    {
+      XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition)selectedObject;
+      XSDConcreteComponent parent = typeDef.getContainer();
+      if (parent instanceof XSDElementDeclaration)
+      {
+        return true;
+      }
+    }
+    else if (enable && selectedObject instanceof XSDSimpleTypeDefinition)
+    {
+      XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition)selectedObject;
+      XSDConcreteComponent parent = typeDef.getContainer();
+      if (parent instanceof XSDElementDeclaration)
+      {
+        return true;
+      }
+      else if (parent instanceof XSDAttributeDeclaration)
+      {
+        return true;
+      }
+    }
+    return false;
+  }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/MakeLocalElementGlobalEnablementTester.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/MakeLocalElementGlobalEnablementTester.java
new file mode 100644
index 0000000..e4f4696
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/MakeLocalElementGlobalEnablementTester.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.ui.internal.refactor;
+
+
+import org.eclipse.xsd.XSDConcreteComponent;
+import org.eclipse.xsd.XSDElementDeclaration;
+import org.eclipse.xsd.XSDSchema;
+
+
+public class MakeLocalElementGlobalEnablementTester extends RefactorEnablementTester
+{
+  protected boolean canEnable(XSDConcreteComponent selectedObject, XSDSchema schema)
+  {
+    if (selectedObject == null)
+    {
+      return false;
+    }
+    
+    boolean enable = false;
+    XSDSchema selectedComponentSchema = null;
+    selectedComponentSchema = selectedObject.getSchema();
+    if (selectedComponentSchema != null && selectedComponentSchema == schema)
+    {
+      enable = true;
+    }
+
+    if (enable && selectedObject instanceof XSDElementDeclaration)
+    {
+      XSDElementDeclaration element = (XSDElementDeclaration)selectedObject;
+      if (!element.isElementDeclarationReference() && !element.isGlobal())
+      {
+        return true;
+      }
+    }
+
+    return false;
+  }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/RefactorEnablementTester.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/RefactorEnablementTester.java
new file mode 100644
index 0000000..b912ca0
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/RefactorEnablementTester.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.ui.internal.refactor;
+
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter;
+import org.eclipse.xsd.XSDConcreteComponent;
+import org.eclipse.xsd.XSDSchema;
+import org.w3c.dom.Node;
+
+
+public abstract class RefactorEnablementTester extends PropertyTester
+{
+
+  public boolean test(Object receiver, String property, Object[] args, Object expectedValue)
+  {
+    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+    if (window == null)
+    {
+      return false;
+    }
+
+    IWorkbenchPage activePage = window.getActivePage();
+    if (activePage == null)
+    {
+      return false;
+    }
+
+    IEditorPart editor = activePage.getActiveEditor();
+    if (editor == null)
+    {
+      return false;
+    }
+
+    XSDSchema schema = (XSDSchema)editor.getAdapter(XSDSchema.class);
+
+    if (receiver instanceof IStructuredSelection)
+    {
+      IStructuredSelection fStructuredSelection = (IStructuredSelection)receiver;
+      receiver = fStructuredSelection.getFirstElement();
+
+      if (receiver instanceof XSDBaseAdapter)
+      {
+        receiver = ((XSDBaseAdapter)receiver).getTarget();
+      }
+
+      if (receiver instanceof XSDConcreteComponent)
+      {
+        return canEnable((XSDConcreteComponent)receiver, schema);
+      }
+      else if (receiver instanceof Node)
+      {
+        Node node = (Node)receiver;
+        if (schema != null)
+        {
+          XSDConcreteComponent concreteComponent = schema.getCorrespondingComponent(node);
+          return canEnable(concreteComponent, schema);
+        }
+      }
+
+      return true;
+    }
+    return false;
+  }
+
+  protected abstract boolean canEnable(XSDConcreteComponent selectedObject, XSDSchema schema);
+
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/RenameEnablementTester.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/RenameEnablementTester.java
new file mode 100644
index 0000000..33308e4
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/RenameEnablementTester.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.ui.internal.refactor;
+
+
+import org.eclipse.xsd.XSDAttributeDeclaration;
+import org.eclipse.xsd.XSDConcreteComponent;
+import org.eclipse.xsd.XSDElementDeclaration;
+import org.eclipse.xsd.XSDNamedComponent;
+import org.eclipse.xsd.XSDSchema;
+import org.eclipse.xsd.XSDTypeDefinition;
+
+
+public class RenameEnablementTester extends RefactorEnablementTester
+{
+  protected boolean canEnable(XSDConcreteComponent selectedObject, XSDSchema schema)
+  {
+    if (selectedObject == null)
+    {
+      return false;
+    }
+
+    XSDNamedComponent selectedComponent = null;
+    boolean enable = false;
+
+    XSDSchema selectedComponentSchema = null;
+    selectedComponentSchema = selectedObject.getSchema();
+    if (selectedComponentSchema != null && selectedComponentSchema == schema)
+    {
+      enable = true;
+    }
+
+    if (enable && selectedObject instanceof XSDNamedComponent)
+    {
+      selectedComponent = (XSDNamedComponent)selectedObject;
+
+      if (selectedComponent instanceof XSDElementDeclaration)
+      {
+        XSDElementDeclaration element = (XSDElementDeclaration)selectedComponent;
+        if (element.isElementDeclarationReference())
+        {
+          return false;
+        }
+      }
+      if (selectedComponent instanceof XSDTypeDefinition)
+      {
+        XSDTypeDefinition type = (XSDTypeDefinition)selectedComponent;
+        XSDConcreteComponent parent = type.getContainer();
+        if (parent instanceof XSDElementDeclaration)
+        {
+          XSDElementDeclaration element = (XSDElementDeclaration)parent;
+          if (element.getAnonymousTypeDefinition().equals(type))
+          {
+            return false;
+          }
+        }
+        else if (parent instanceof XSDAttributeDeclaration)
+        {
+          XSDAttributeDeclaration element = (XSDAttributeDeclaration)parent;
+          if (element.getAnonymousTypeDefinition().equals(type))
+          {
+            return false;
+          }
+        }
+      }
+      return true;
+    }
+    return false;
+  }
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/MakeAnonymousTypeGlobalAction.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/MakeAnonymousTypeGlobalAction.java
index cb3f3bf..8914764 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/MakeAnonymousTypeGlobalAction.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/MakeAnonymousTypeGlobalAction.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 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
@@ -17,6 +17,7 @@
 import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
 import org.eclipse.wst.xml.core.internal.document.DocumentImpl;
 import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin;
+import org.eclipse.wst.xsd.ui.internal.refactor.handlers.MakeAnonymousTypeGobalHandler;
 import org.eclipse.wst.xsd.ui.internal.refactor.structure.MakeAnonymousTypeGlobalCommand;
 import org.eclipse.wst.xsd.ui.internal.refactor.structure.MakeTypeGlobalProcessor;
 import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactoringWizardMessages;
@@ -30,6 +31,9 @@
 import org.eclipse.xsd.XSDTypeDefinition;
 import org.w3c.dom.Node;
 
+/**
+ * @deprecated Use {@link MakeAnonymousTypeGobalHandler}
+ */
 public class MakeAnonymousTypeGlobalAction extends XSDSelectionDispatchAction {
 
 	private String fParentName;
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/MakeLocalElementGlobalAction.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/MakeLocalElementGlobalAction.java
index 847b127..49d877c 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/MakeLocalElementGlobalAction.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/MakeLocalElementGlobalAction.java
@@ -14,12 +14,16 @@
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.wst.xml.core.internal.document.DocumentImpl;
 import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringMessages;
+import org.eclipse.wst.xsd.ui.internal.refactor.handlers.MakeLocalElementGlobalHandler;
 import org.eclipse.wst.xsd.ui.internal.refactor.structure.MakeLocalElementGlobalCommand;
 import org.eclipse.xsd.XSDConcreteComponent;
 import org.eclipse.xsd.XSDElementDeclaration;
 import org.eclipse.xsd.XSDSchema;
 import org.w3c.dom.Node;
 
+/**
+ * @deprecated Use {@link MakeLocalElementGlobalHandler}
+ */
 public class MakeLocalElementGlobalAction extends XSDSelectionDispatchAction {
 
 	XSDElementDeclaration fSelectedComponent;
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/RenameComponentAction.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/RenameComponentAction.java
index 8fca361..e0447ef 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/RenameComponentAction.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/actions/RenameComponentAction.java
@@ -23,6 +23,7 @@
 import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin;
 import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringComponent;
 import org.eclipse.wst.xsd.ui.internal.refactor.XMLRefactoringComponent;
+import org.eclipse.wst.xsd.ui.internal.refactor.handlers.RenameHandler;
 import org.eclipse.wst.xsd.ui.internal.refactor.rename.RenameComponentProcessor;
 import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactoringWizardMessages;
 import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard;
@@ -33,6 +34,9 @@
 import org.eclipse.xsd.XSDTypeDefinition;
 import org.w3c.dom.Node;
 
+/**
+ * @deprecated Use {@link RenameHandler} 
+ */
 public class RenameComponentAction extends XSDSelectionDispatchAction {
 
 	private XSDNamedComponent selectedComponent;
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/MakeAnonymousTypeGobalHandler.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/MakeAnonymousTypeGobalHandler.java
new file mode 100644
index 0000000..efd8087
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/MakeAnonymousTypeGobalHandler.java
@@ -0,0 +1,138 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.ui.internal.refactor.handlers;
+
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.wst.xml.core.internal.document.DocumentImpl;
+import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter;
+import org.eclipse.wst.xsd.ui.internal.refactor.structure.MakeAnonymousTypeGlobalCommand;
+import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactoringWizardMessages;
+import org.eclipse.xsd.XSDAttributeDeclaration;
+import org.eclipse.xsd.XSDComplexTypeDefinition;
+import org.eclipse.xsd.XSDConcreteComponent;
+import org.eclipse.xsd.XSDElementDeclaration;
+import org.eclipse.xsd.XSDSchema;
+import org.eclipse.xsd.XSDSimpleTypeDefinition;
+import org.eclipse.xsd.XSDTypeDefinition;
+import org.w3c.dom.Node;
+
+
+public class MakeAnonymousTypeGobalHandler extends RefactoringHandler
+{
+  private String parentName;
+  private boolean isComplexType = true;
+
+  public Object doExecute(ISelection selection, XSDSchema schema)
+  {
+    if (selection != null)
+    {
+      Object selectedObject = ((StructuredSelection)selection).getFirstElement();
+      
+      if (selectedObject instanceof XSDBaseAdapter)
+      {
+        selectedObject = ((XSDBaseAdapter)selectedObject).getTarget();
+      }
+      
+      XSDConcreteComponent concreteComp = null;
+
+      if (selectedObject instanceof Node)
+      {
+        Node node = (Node)selectedObject;
+        concreteComp = schema.getCorrespondingComponent(node);
+      }
+      else if (selectedObject instanceof XSDConcreteComponent)
+      {
+        concreteComp = ((XSDConcreteComponent)selectedObject);
+      }
+
+      if (concreteComp != null)
+      {
+        if (concreteComp instanceof XSDComplexTypeDefinition)
+        {
+
+          isComplexType = true;
+          XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition)concreteComp;
+          XSDConcreteComponent parent = typeDef.getContainer();
+          if (parent instanceof XSDElementDeclaration)
+          {
+            parentName = ((XSDElementDeclaration)parent).getName();
+            run(selection, schema, typeDef);
+          }
+          else if (concreteComp instanceof XSDSimpleTypeDefinition)
+          {
+            isComplexType = false;
+            XSDSimpleTypeDefinition simpleTypeDef = (XSDSimpleTypeDefinition)concreteComp;
+            XSDConcreteComponent parentComp = simpleTypeDef.getContainer();
+            if (parentComp instanceof XSDElementDeclaration)
+            {
+              parentName = ((XSDElementDeclaration)parent).getName();
+
+            }
+            else if (parent instanceof XSDAttributeDeclaration)
+            {
+              parentName = ((XSDAttributeDeclaration)parent).getName();
+
+            }
+            run(selection, schema, simpleTypeDef);
+          }
+        }
+      }
+    }
+
+    return null;
+  }
+
+  private String getNewDefaultName()
+  {
+    if (parentName != null && !"".equals(parentName)) { //$NON-NLS-1$
+      if (isComplexType)
+      {
+        return parentName + "ComplexType"; //$NON-NLS-1$
+      }
+      else
+      {
+        return parentName + "SimpleType"; //$NON-NLS-1$
+      }
+    }
+    else
+    {
+      if (isComplexType)
+      {
+        return "NewComplexType"; //$NON-NLS-1$
+      }
+      else
+      {
+        return "NewSimpleType"; //$NON-NLS-1$
+      }
+    }
+
+  }
+
+  public void run(ISelection selection, XSDSchema schema, XSDTypeDefinition selectedComponent)
+  {
+    if (selectedComponent == null)
+    {
+      return;
+    }
+
+    if (selectedComponent.getSchema() == null)
+    {
+      schema.updateElement(true);
+    }
+    DocumentImpl doc = (DocumentImpl)selectedComponent.getElement().getOwnerDocument();
+    doc.getModel().beginRecording(this, RefactoringWizardMessages.MakeAnonymousTypeGlobalAction_text);
+    MakeAnonymousTypeGlobalCommand command = new MakeAnonymousTypeGlobalCommand(selectedComponent, getNewDefaultName());
+    command.run();
+    doc.getModel().endRecording(this);
+  }
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/MakeLocalElementGlobalHandler.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/MakeLocalElementGlobalHandler.java
new file mode 100644
index 0000000..8578d88
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/MakeLocalElementGlobalHandler.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.ui.internal.refactor.handlers;
+
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.wst.xml.core.internal.document.DocumentImpl;
+import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter;
+import org.eclipse.wst.xsd.ui.internal.refactor.structure.MakeLocalElementGlobalCommand;
+import org.eclipse.xsd.XSDConcreteComponent;
+import org.eclipse.xsd.XSDElementDeclaration;
+import org.eclipse.xsd.XSDSchema;
+import org.w3c.dom.Node;
+
+
+public class MakeLocalElementGlobalHandler extends RefactoringHandler
+{
+
+  public Object doExecute(ISelection selection, XSDSchema schema)
+  {
+    if (selection != null)
+    {
+      Object selectedObject = ((StructuredSelection)selection).getFirstElement();
+      if (selectedObject instanceof XSDBaseAdapter)
+      {
+        selectedObject = ((XSDBaseAdapter)selectedObject).getTarget();
+      }
+      if (selectedObject instanceof XSDElementDeclaration)
+      {
+        run(selection, (XSDElementDeclaration)selectedObject);
+      }
+      else if (selectedObject instanceof Node)
+      {
+        Node node = (Node)selectedObject;
+        XSDConcreteComponent concreteComponent = schema.getCorrespondingComponent(node);
+        if (concreteComponent instanceof XSDElementDeclaration)
+          run(selection, (XSDElementDeclaration)concreteComponent);
+      }
+
+    }
+    return null;
+  }
+
+  public void run(ISelection selection, XSDElementDeclaration selectedComponent)
+  {
+    DocumentImpl doc = (DocumentImpl)selectedComponent.getElement().getOwnerDocument();
+    doc.getModel().beginRecording(this, "MakeLocalElementGlobalHandler.text");
+    MakeLocalElementGlobalCommand command = new MakeLocalElementGlobalCommand(selectedComponent);
+    command.run();
+    doc.getModel().endRecording(this);
+  }
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/RefactoringHandler.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/RefactoringHandler.java
new file mode 100644
index 0000000..bbe02fc
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/RefactoringHandler.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.wst.xsd.ui.internal.refactor.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.xsd.XSDSchema;
+
+public abstract class RefactoringHandler extends AbstractHandler
+{
+  public Object execute(ExecutionEvent event) throws ExecutionException {
+    
+    IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
+    if (workbenchWindow == null) return null;
+
+    IWorkbenchPage activePage = workbenchWindow.getActivePage();
+    if (activePage == null) return null;
+
+    IEditorPart editor = activePage.getActiveEditor();
+    if (editor == null) return null;
+    XSDSchema schema = (XSDSchema)editor.getAdapter(XSDSchema.class);
+     
+    ISelection selection = activePage.getSelection();
+    
+    return doExecute(selection, schema);
+  }
+
+  protected abstract Object doExecute(ISelection selection, XSDSchema schema);
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/RenameHandler.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/RenameHandler.java
new file mode 100644
index 0000000..c06bd43
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/handlers/RenameHandler.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.ui.internal.refactor.handlers;
+
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring;
+import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
+import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
+import org.eclipse.wst.common.ui.internal.dialogs.SaveDirtyFilesDialog;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
+import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter;
+import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin;
+import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringComponent;
+import org.eclipse.wst.xsd.ui.internal.refactor.XMLRefactoringComponent;
+import org.eclipse.wst.xsd.ui.internal.refactor.rename.RenameComponentProcessor;
+import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactoringWizardMessages;
+import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard;
+import org.eclipse.xsd.XSDConcreteComponent;
+import org.eclipse.xsd.XSDNamedComponent;
+import org.eclipse.xsd.XSDSchema;
+import org.w3c.dom.Node;
+
+
+public class RenameHandler extends RefactoringHandler
+{
+
+  protected Object doExecute(ISelection selection, XSDSchema schema)
+  {
+    return execute(selection, schema);
+  }
+
+  public Object execute(ISelection selection, XSDSchema schema)
+  {
+    if (selection != null)
+    {
+
+      Object selectedObject = ((StructuredSelection)selection).getFirstElement();
+      if (selectedObject instanceof XSDBaseAdapter)
+      {
+        selectedObject = ((XSDBaseAdapter)selectedObject).getTarget();
+      }
+
+      if (selectedObject instanceof XSDNamedComponent)
+      {
+        run(selection, schema, (XSDNamedComponent)selectedObject);
+      }
+      else if (selectedObject instanceof Node)
+      {
+        Node node = (Node)selectedObject;
+        if (schema != null)
+        {
+          XSDConcreteComponent concreteComponent = schema.getCorrespondingComponent(node);
+          if (concreteComponent instanceof XSDNamedComponent)
+          {
+            run(selection, schema, (XSDNamedComponent)concreteComponent);
+          }
+        }
+      }
+    }
+    return null;
+
+  }
+
+  public void run(ISelection selection, XSDSchema schema, XSDNamedComponent selectedComponent)
+  {
+    if (selectedComponent.getName() == null)
+    {
+      selectedComponent.setName(new String());
+    }
+    if (selectedComponent.getSchema() == null)
+    {
+      if (schema != null)
+      {
+        schema.updateElement(true);
+      }
+
+    }
+
+    boolean rc = SaveDirtyFilesDialog.saveDirtyFiles();
+    if (!rc)
+    {
+      return;
+    }
+    RefactoringComponent component = new XMLRefactoringComponent(
+      selectedComponent,
+      (IDOMElement)selectedComponent.getElement(),
+      selectedComponent.getName(),
+      selectedComponent.getTargetNamespace());
+
+    RenameComponentProcessor processor = new RenameComponentProcessor(component, selectedComponent.getName());
+    RenameRefactoring refactoring = new RenameRefactoring(processor);
+    try
+    {
+      RefactoringWizard wizard = new RenameRefactoringWizard(
+        refactoring,
+        RefactoringWizardMessages.RenameComponentWizard_defaultPageTitle,
+        RefactoringWizardMessages.RenameComponentWizard_inputPage_description,
+        null);
+      RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
+      op.run(XSDEditorPlugin.getShell(), wizard.getDefaultPageTitle());
+
+    }
+    catch (InterruptedException e)
+    {
+      // do nothing. User action got canceled
+    }
+  }
+}