diff options
author | vbaciu | 2010-03-04 01:48:46 +0000 |
---|---|---|
committer | vbaciu | 2010-03-04 01:48:46 +0000 |
commit | 0e72306725d9dfab4d7f1c94f1b261ee7853563e (patch) | |
tree | c0dfddd94c51cd3d235780db857a3e7c3d32f2ad | |
parent | 0bb65e62bb9d49f60d2409dd661fe61bb9efb98b (diff) | |
download | webtools.webservices-0e72306725d9dfab4d7f1c94f1b261ee7853563e.tar.gz webtools.webservices-0e72306725d9dfab4d7f1c94f1b261ee7853563e.tar.xz webtools.webservices-0e72306725d9dfab4d7f1c94f1b261ee7853563e.zip |
[302640] [Extensibility] Provide extensibility in the refactoring context menu
14 files changed, 562 insertions, 56 deletions
diff --git a/bundles/org.eclipse.wst.wsdl.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.wst.wsdl.ui/META-INF/MANIFEST.MF index 96c6f57f4..7e7cb375d 100644 --- a/bundles/org.eclipse.wst.wsdl.ui/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.wst.wsdl.ui/META-INF/MANIFEST.MF @@ -43,6 +43,7 @@ Export-Package: org.eclipse.wst.wsdl.ui.internal;x-internal:=true, org.eclipse.wst.wsdl.ui.internal.reconciler;x-internal:=true, org.eclipse.wst.wsdl.ui.internal.refactor;x-internal:=true, org.eclipse.wst.wsdl.ui.internal.refactor.actions;x-internal:=true, + org.eclipse.wst.wsdl.ui.internal.refactor.handlers, org.eclipse.wst.wsdl.ui.internal.search;x-internal:=true, org.eclipse.wst.wsdl.ui.internal.search.actions;x-internal:=true, org.eclipse.wst.wsdl.ui.internal.soap.customizations;x-internal:=true, @@ -89,6 +90,7 @@ Require-Bundle: org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)", org.eclipse.search;bundle-version="[3.2.0,4.0.0)", org.eclipse.wst.ws.service.policy.ui;bundle-version="[1.0.0,2.0.0)", org.eclipse.core.filesystem;bundle-version="[1.2.0,2.0.0)", - org.eclipse.wst.ws.service.policy;bundle-version="[1.0.0,2.0.0)" + org.eclipse.wst.ws.service.policy;bundle-version="[1.0.0,2.0.0)", + org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.4 diff --git a/bundles/org.eclipse.wst.wsdl.ui/plugin.properties b/bundles/org.eclipse.wst.wsdl.ui/plugin.properties index 6f32efc7f..d0a85ed7e 100644 --- a/bundles/org.eclipse.wst.wsdl.ui/plugin.properties +++ b/bundles/org.eclipse.wst.wsdl.ui/plugin.properties @@ -27,6 +27,12 @@ AddTask.tooltip=Add Task... WSDLEditorModes=WSDL Editor Modes command.wsdl.refactor.rename.element.name=Rename WSDL component +command.wsdl.refactor.rename.element.description=Renames WSDL component +command.wsdl.refactor.rename.element.label=Re&name... +WSDL_DESIGN_VIEW_DESCRIPTION=WSDL Editor Design View +WSDL_DESIGN_VIEW=WSDL Editor Design View +WSDL_SOURCE_VIEW_DESCRIPTION=WSDL Editor Source View +WSDL_SOURCE_VIEW=WSDL Editor Source View _UI_PLUGIN_NAME=WSDL UI providerName=Eclipse.org @@ -36,7 +42,6 @@ WSDL_hyperlink=WSDL Content SOAP=SOAP HTTP=HTTP References=&References -command.wsdl.refactor.rename.element.description=Renames WSDL component _UI_RELOAD_DEPENDENCIES.tooltip = Reload Dependencies extensibilityElementFilter.name = Extensiblity Element Filter renameParticipant.name = WSDL Rename Particpant diff --git a/bundles/org.eclipse.wst.wsdl.ui/plugin.xml b/bundles/org.eclipse.wst.wsdl.ui/plugin.xml index 2986c57a0..e2fceb756 100644 --- a/bundles/org.eclipse.wst.wsdl.ui/plugin.xml +++ b/bundles/org.eclipse.wst.wsdl.ui/plugin.xml @@ -235,22 +235,7 @@ namespaceURI="http://schemas.xmlsoap.org/wsdl/mime/"> </category> </extension> - - <extension point="org.eclipse.ui.popupMenus"> - <objectContribution - id="org.eclipse.wst.wsdl.ui.refactoring.menu.objectContrib" - objectClass="org.eclipse.wst.wsdl.ui.internal.adapters.WSDLBaseAdapter"> - <action - id="org.eclipse.wst.wsdleditor.refactoring.menu.refactorGroup.object" - enablesFor="1" - style="pulldown" - menubarPath="refactoring-slot-temp" - label="%_UI_LABEL_REFACTOR" - class="org.eclipse.wst.wsdl.ui.internal.refactor.actions.WSDLRefactorGroupActionDelegate"> - </action> - </objectContribution> - </extension> - + <extension point="org.eclipse.ui.popupMenus"> <objectContribution id="org.eclipse.wst.wsdl.ui.searchReferences.menu.objectContrib" @@ -342,32 +327,46 @@ </renameParticipant> </extension> - <!-- Refactoring UI extensions --> - <extension point="org.eclipse.ui.popupMenus"> - <objectContribution - id="org.eclipse.wst.wsdl.ui.refactoring.menu.objectContrib" - objectClass="org.eclipse.wst.wsdl.WSDLElement"> - <action - id="org.eclipse.wst.wsdl.ui.refactoring.menu.refactorGroup.object" - enablesFor="1" - style="pulldown" - menubarPath="additions" - label="%refactoring.menu.label" - class="org.eclipse.wst.wsdl.ui.internal.refactor.actions.WSDLRefactorGroupActionDelegate"> - </action> - </objectContribution> - - <viewerContribution - id="org.eclipse.wst.xsd.ui.refactoring.menu.source" - targetID="org.eclipse.wst.wsdl.wsdlsource.source.EditorContext"> - <action id="org.eclipse.wst.wsdl.ui.refactoring.menu.refactorGroup.source" - style="pulldown" - menubarPath="additions" - label="%refactoring.menu.label" - class="org.eclipse.wst.wsdl.ui.internal.refactor.actions.WSDLRefactorGroupActionDelegate"> - </action> - </viewerContribution> - </extension> + <!-- Refactoring UI extensions --> + <extension point="org.eclipse.ui.menus"> + <menuContribution locationURI="popup:refactorPopupMenuId"> + <command + commandId="org.eclipse.wst.wsdl.ui.refactor.rename.element" + label="%command.wsdl.refactor.rename.element.label"> + <visibleWhen + checkEnabled="true"> + </visibleWhen> + </command> + </menuContribution> + <menuContribution + locationURI="popup:org.eclipse.wst.wsdl.ui.refactorMenuId"> + <command + commandId="org.eclipse.wst.wsdl.ui.refactor.rename.element" + label="%command.wsdl.refactor.rename.element.label"> + <visibleWhen + checkEnabled="true"> + </visibleWhen> + </command> + </menuContribution> + <menuContribution + locationURI="menu:refactorMenuId"> + <command + commandId="org.eclipse.wst.wsdl.ui.refactor.rename.element" + label="%command.wsdl.refactor.rename.element.label"> + <visibleWhen + checkEnabled="false"> + <or> + <reference + definitionId="org.eclipse.wst.wsdl.ui.editor.active.designView.definition"> + </reference> + <reference + definitionId="org.eclipse.wst.wsdl.ui.editor.active.sourceView.definition"> + </reference> + </or> + </visibleWhen> + </command> + </menuContribution> + </extension> <extension point="org.eclipse.ui.commands"> <command @@ -535,4 +534,66 @@ bindingOptionsPageClass="org.eclipse.wst.wsdl.ui.internal.contentgenerator.ui.HttpBindingOptionsPage"> </contentGeneratorUI> </extension> + <extension + point="org.eclipse.ui.handlers"> + <handler + class="org.eclipse.wst.wsdl.ui.internal.refactor.handlers.RenameHandler" + commandId="org.eclipse.wst.wsdl.ui.refactor.rename.element"> + <enabledWhen> + <with variable="selection"> + <test property="org.eclipse.wst.wsdl.ui.refactor.renameEnabled"/> + </with> + </enabledWhen> + </handler> + </extension> + <extension + point="org.eclipse.core.expressions.propertyTesters"> + <propertyTester + class="org.eclipse.wst.wsdl.ui.internal.refactor.RenameEnablementTester" + id="org.eclipse.wst.wsdl.ui.refactor.rename.enablement" + namespace="org.eclipse.wst.wsdl.ui.refactor" + properties="renameEnabled" + type="org.eclipse.jface.viewers.ISelection"> + </propertyTester> + </extension> + <extension + point="org.eclipse.ui.contexts"> + <context + description="%WSDL_DESIGN_VIEW_DESCRIPTION" + id="org.eclipse.wst.wsdl.ui.editor.designView" + name="%WSDL_DESIGN_VIEW"> + </context> + <context + description="%WSDL_SOURCE_VIEW_DESCRIPTION" + id="org.eclipse.wst.wsdl.ui.editor.sourceView" + name="%WSDL_SOURCE_VIEW"> + </context> + </extension> + <extension + point="org.eclipse.core.expressions.definitions"> + <definition + id="org.eclipse.wst.wsdl.ui.editor.active.designView.definition"> + <with + variable="activeContexts"> + <iterate + operator="or"> + <equals + value="org.eclipse.wst.wsdl.ui.editor.designView"> + </equals> + </iterate> + </with> + </definition> + <definition + id="org.eclipse.wst.wsdl.ui.editor.active.sourceView.definition"> + <with + variable="activeContexts"> + <iterate + operator="or"> + <equals + value="org.eclipse.wst.wsdl.ui.editor.sourceView"> + </equals> + </iterate> + </with> + </definition> + </extension> </plugin> diff --git a/bundles/org.eclipse.wst.wsdl.ui/src-asd/org/eclipse/wst/wsdl/ui/internal/asd/ASDMultiPageEditor.java b/bundles/org.eclipse.wst.wsdl.ui/src-asd/org/eclipse/wst/wsdl/ui/internal/asd/ASDMultiPageEditor.java index 73103ad0d..c66f3f876 100644 --- a/bundles/org.eclipse.wst.wsdl.ui/src-asd/org/eclipse/wst/wsdl/ui/internal/asd/ASDMultiPageEditor.java +++ b/bundles/org.eclipse.wst.wsdl.ui/src-asd/org/eclipse/wst/wsdl/ui/internal/asd/ASDMultiPageEditor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2001, 2007 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 @@ -31,6 +31,8 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.contexts.IContextActivation; +import org.eclipse.ui.contexts.IContextService; import org.eclipse.ui.ide.FileStoreEditorInput; import org.eclipse.ui.views.contentoutline.IContentOutlinePage; import org.eclipse.wst.wsdl.ui.internal.WSDLEditorPlugin; @@ -69,6 +71,9 @@ public abstract class ASDMultiPageEditor extends CommonMultiPageEditor protected DesignViewContextMenuProvider menuProvider; protected IDescription model; private int currentPage = -1; + private IContextActivation contextActivation; + public final static String DESIGN_VIEW_CONTEXT = "org.eclipse.wst.wsdl.ui.editor.designView"; //$NON-NLS-1$ + public final static String SOURCE_VIEW_CONTEXT = "org.eclipse.wst.wsdl.ui.editor.sourceView"; //$NON-NLS-1$ /** * Creates a multi-page editor example. @@ -314,8 +319,23 @@ public abstract class ASDMultiPageEditor extends CommonMultiPageEditor } protected void pageChange(int newPageIndex) { + // Note: createPages() will call this method; so the first context is activated here instead at createPages(). + deactivateContext(contextActivation); currentPage = newPageIndex; super.pageChange(newPageIndex); + + String context = getContext(currentPage); + contextActivation = activateContext(context); + } + + 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; } public void dispose() { @@ -325,7 +345,26 @@ public abstract class ASDMultiPageEditor extends CommonMultiPageEditor else { WSDLEditorPlugin.getInstance().setDefaultPage(WSDLEditorPlugin.DESIGN_PAGE); } + + deactivateContext(contextActivation); + + super.dispose(); + } + + 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); - super.dispose(); + if (contextService != null && contextActivation != null) { + contextService.deactivateContext(contextActivation); + } } } diff --git a/bundles/org.eclipse.wst.wsdl.ui/src-asd/org/eclipse/wst/wsdl/ui/internal/asd/Messages.java b/bundles/org.eclipse.wst.wsdl.ui/src-asd/org/eclipse/wst/wsdl/ui/internal/asd/Messages.java index 2b35718e5..3eeb21b36 100644 --- a/bundles/org.eclipse.wst.wsdl.ui/src-asd/org/eclipse/wst/wsdl/ui/internal/asd/Messages.java +++ b/bundles/org.eclipse.wst.wsdl.ui/src-asd/org/eclipse/wst/wsdl/ui/internal/asd/Messages.java @@ -80,4 +80,5 @@ public class Messages { public static String _UI_ACTION_SHOW_PROPERTIES; public static String _ERROR_LABEL_PREFIX_EXISTS; public static String _UI_LABEL_BINDING_IN_PROPERTIES_SECTION; + public static String _UI_REFACTOR_CONTEXT_MENU; } diff --git a/bundles/org.eclipse.wst.wsdl.ui/src-asd/org/eclipse/wst/wsdl/ui/internal/asd/design/DesignViewContextMenuProvider.java b/bundles/org.eclipse.wst.wsdl.ui/src-asd/org/eclipse/wst/wsdl/ui/internal/asd/design/DesignViewContextMenuProvider.java index 6e0d22e27..0fab2b2ae 100644 --- a/bundles/org.eclipse.wst.wsdl.ui/src-asd/org/eclipse/wst/wsdl/ui/internal/asd/design/DesignViewContextMenuProvider.java +++ b/bundles/org.eclipse.wst.wsdl.ui/src-asd/org/eclipse/wst/wsdl/ui/internal/asd/design/DesignViewContextMenuProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2001, 2006 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 @@ -27,10 +27,12 @@ import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.PlatformUI; import org.eclipse.wst.wsdl.ui.internal.asd.ASDEditorPlugin; +import org.eclipse.wst.wsdl.ui.internal.asd.Messages; import org.eclipse.wst.wsdl.ui.internal.asd.actions.BaseSelectionAction; import org.eclipse.wst.wsdl.ui.internal.asd.actions.ShowPropertiesViewAction; import org.eclipse.wst.wsdl.ui.internal.asd.design.editparts.ColumnEditPart; import org.eclipse.wst.wsdl.ui.internal.asd.design.editparts.model.IActionProvider; +import org.eclipse.wst.wsdl.ui.internal.refactor.IWSDLRefactorConstants; import org.eclipse.wst.xsd.ui.internal.adt.editor.ContextMenuParticipant; import org.eclipse.wst.xsd.ui.internal.adt.editor.EditorModeManager; @@ -125,7 +127,8 @@ public class DesignViewContextMenuProvider extends ContextMenuProvider menu.add(registry.getAction(ShowPropertiesViewAction.ID)); menu.add(new Separator()); - menu.add(new Separator("refactoring-slot-temp")); //$NON-NLS-1$ + IMenuManager subMenu = new MenuManager(Messages._UI_REFACTOR_CONTEXT_MENU, IWSDLRefactorConstants.REFACTOR_CONTEXT_MENU_ID); + menu.add(subMenu); menu.add(new Separator()); menu.add(new Separator("search_slot_temp")); //$NON-NLS-1$ menu.add(new Separator()); diff --git a/bundles/org.eclipse.wst.wsdl.ui/src-asd/org/eclipse/wst/wsdl/ui/internal/asd/messages.properties b/bundles/org.eclipse.wst.wsdl.ui/src-asd/org/eclipse/wst/wsdl/ui/internal/asd/messages.properties index ba31a08f1..3ba4775a8 100644 --- a/bundles/org.eclipse.wst.wsdl.ui/src-asd/org/eclipse/wst/wsdl/ui/internal/asd/messages.properties +++ b/bundles/org.eclipse.wst.wsdl.ui/src-asd/org/eclipse/wst/wsdl/ui/internal/asd/messages.properties @@ -50,4 +50,5 @@ _UI_TOOLTIP_RENAME_REFACTOR=Click here to invoke the Rename refactoring. _UI_LABEL_RIGHT_CLICK_TO_INSERT_CONTENT=Right mouse click here to insert content _UI_ACTION_SHOW_PROPERTIES=Sho&w properties -_ERROR_LABEL_PREFIX_EXISTS=Prefix already exists
\ No newline at end of file +_ERROR_LABEL_PREFIX_EXISTS=Prefix already exists +_UI_REFACTOR_CONTEXT_MENU=Refac&tor
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsdl.ui/src-asd/org/eclipse/wst/wsdl/ui/internal/asd/properties/sections/NameSection.java b/bundles/org.eclipse.wst.wsdl.ui/src-asd/org/eclipse/wst/wsdl/ui/internal/asd/properties/sections/NameSection.java index e2a843d16..bc13d8508 100644 --- a/bundles/org.eclipse.wst.wsdl.ui/src-asd/org/eclipse/wst/wsdl/ui/internal/asd/properties/sections/NameSection.java +++ b/bundles/org.eclipse.wst.wsdl.ui/src-asd/org/eclipse/wst/wsdl/ui/internal/asd/properties/sections/NameSection.java @@ -35,7 +35,7 @@ import org.eclipse.wst.wsdl.ui.internal.asd.facade.IBinding; import org.eclipse.wst.wsdl.ui.internal.asd.facade.IInterface; import org.eclipse.wst.wsdl.ui.internal.asd.facade.IMessage; import org.eclipse.wst.wsdl.ui.internal.asd.facade.INamedObject; -import org.eclipse.wst.wsdl.ui.internal.refactor.actions.RenameComponentAction; +import org.eclipse.wst.wsdl.ui.internal.refactor.handlers.RenameHandler; public class NameSection extends ASDAbstractSection implements IHyperlinkListener { protected static final String NEW_STRING = Messages._UI_BUTTON_NEW; //$NON-NLS-1$ @@ -187,9 +187,8 @@ public class NameSection extends ASDAbstractSection implements IHyperlinkListene ISelection selection = editor.getSite().getSelectionProvider().getSelection(); ISelectionMapper mapper = (ISelectionMapper) editor.getAdapter(ISelectionMapper.class); selection = mapper != null ? mapper.mapSelection(selection) : selection; - RenameComponentAction action = new RenameComponentAction(selection, definition); - action.update(selection); - action.run(); + RenameHandler renameHandler = new RenameHandler(); + renameHandler.execute(definition, selection); } private Object getRealModel() { diff --git a/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/IWSDLRefactorConstants.java b/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/IWSDLRefactorConstants.java new file mode 100644 index 000000000..c7533747c --- /dev/null +++ b/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/IWSDLRefactorConstants.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.wsdl.ui.internal.refactor; + +public interface IWSDLRefactorConstants { + String REFACTOR_CONTEXT_MENU_ID = "org.eclipse.wst.wsdl.ui.refactorMenuId"; //$NON-NLS-1$ +} diff --git a/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/RenameEnablementTester.java b/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/RenameEnablementTester.java new file mode 100644 index 000000000..829f01121 --- /dev/null +++ b/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/RenameEnablementTester.java @@ -0,0 +1,132 @@ +/******************************************************************************* + * 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.wsdl.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.wsdl.Binding; +import org.eclipse.wst.wsdl.Definition; +import org.eclipse.wst.wsdl.Message; +import org.eclipse.wst.wsdl.PortType; +import org.eclipse.wst.wsdl.WSDLElement; +import org.eclipse.wst.wsdl.internal.impl.WSDLElementImpl; +import org.eclipse.wst.wsdl.ui.internal.adapters.WSDLBaseAdapter; +import org.eclipse.wst.wsdl.ui.internal.util.NodeAssociationManager; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; +import org.eclipse.xsd.XSDAttributeDeclaration; +import org.eclipse.xsd.XSDConcreteComponent; +import org.eclipse.xsd.XSDElementDeclaration; +import org.eclipse.xsd.XSDNamedComponent; +import org.eclipse.xsd.XSDTypeDefinition; +import org.w3c.dom.Element; + +public class RenameEnablementTester extends PropertyTester { + public static final String RENAME_ENABLED = "renameEnabled"; //$NON-NLS-1$ + public boolean test(Object receiver, String property, Object[] args, + Object expectedValue) { + if (!RENAME_ENABLED.equals(property)) return false; + + 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; + + Definition definition = (Definition) editor.getAdapter(Definition.class); + if (definition == null) return false; + + return canEnable(definition, receiver); + } + + private boolean canEnable(Definition definition, Object selectedObject) { + if (selectedObject instanceof IStructuredSelection) { + IStructuredSelection fStructuredSelection = (IStructuredSelection) selectedObject; + selectedObject = fStructuredSelection.getFirstElement(); + + if (selectedObject instanceof WSDLBaseAdapter) { + WSDLBaseAdapter wsdlObject = (WSDLBaseAdapter) selectedObject; + + // do not enable for read-only objects + if (wsdlObject.isReadOnly()) { + return false; + } + + selectedObject = wsdlObject.getTarget(); + } + + if (selectedObject instanceof XSDNamedComponent) { + return doCanEnableXSDSelection((XSDNamedComponent) selectedObject); + } else if(selectedObject instanceof WSDLElementImpl){ + return doCanEnableWSDLSelection((WSDLElementImpl) selectedObject); + } + if (selectedObject instanceof Element) { + Element node = (Element) selectedObject; + if (definition != null) { + // issue (eb) dependency on utility class to get component from the model based on element + Object concreteComponent = (new NodeAssociationManager()).getModelObjectForNode(definition, node); + return canEnable(definition, concreteComponent); + } + } + } + return false; + } + + private boolean doCanEnableXSDSelection(XSDNamedComponent selectedObject) { + if ( !(selectedObject.getElement() instanceof IDOMElement)) { + return false; + } + + // if it's element reference, then this action is not appropriate + if (selectedObject instanceof XSDElementDeclaration) { + XSDElementDeclaration element = (XSDElementDeclaration) selectedObject; + if (element.isElementDeclarationReference()) { + return false; + } + } + + if(selectedObject instanceof XSDTypeDefinition){ + XSDTypeDefinition type = (XSDTypeDefinition) selectedObject; + 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; + } + + private boolean doCanEnableWSDLSelection(WSDLElement selectedObject) { + if (selectedObject instanceof Binding || + selectedObject instanceof PortType || + selectedObject instanceof Message) { + return true; + } else { + return false; + } + } + +} diff --git a/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/actions/RenameComponentAction.java b/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/actions/RenameComponentAction.java index 0939528e2..976db2981 100644 --- a/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/actions/RenameComponentAction.java +++ b/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/actions/RenameComponentAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2001, 2006 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 @@ -27,6 +27,7 @@ import org.eclipse.wst.wsdl.WSDLElement; import org.eclipse.wst.wsdl.internal.impl.DefinitionImpl; import org.eclipse.wst.wsdl.internal.impl.WSDLElementImpl; import org.eclipse.wst.wsdl.ui.internal.WSDLEditorPlugin; +import org.eclipse.wst.wsdl.ui.internal.refactor.handlers.RenameHandler; import org.eclipse.wst.wsdl.ui.internal.util.NodeAssociationManager; import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringComponent; @@ -41,6 +42,9 @@ import org.eclipse.xsd.XSDNamedComponent; import org.eclipse.xsd.XSDTypeDefinition; import org.w3c.dom.Element; +/** + * @deprecated This class is replaced by {@link RenameHandler}. + */ public class RenameComponentAction extends WSDLSelectionDispatchAction { private RefactoringComponent selectedComponent; diff --git a/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/actions/WSDLRefactorActionGroup.java b/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/actions/WSDLRefactorActionGroup.java index cd4a71692..f213a4569 100644 --- a/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/actions/WSDLRefactorActionGroup.java +++ b/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/actions/WSDLRefactorActionGroup.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2001, 2006 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 @@ -14,9 +14,13 @@ import java.util.ArrayList; import org.eclipse.jface.viewers.ISelection; import org.eclipse.wst.wsdl.Definition; +import org.eclipse.wst.wsdl.ui.internal.refactor.handlers.RenameHandler; import org.eclipse.wst.xsd.ui.internal.refactor.actions.RenameAction; import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactorActionGroup; +/** + * @deprecated This class is replaced by {@link RenameHandler}. + */ public class WSDLRefactorActionGroup extends RefactorActionGroup { diff --git a/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/actions/WSDLRefactorGroupActionDelegate.java b/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/actions/WSDLRefactorGroupActionDelegate.java index 3d580dcde..2a136b3da 100644 --- a/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/actions/WSDLRefactorGroupActionDelegate.java +++ b/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/actions/WSDLRefactorGroupActionDelegate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2001, 2007 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 @@ -19,10 +19,16 @@ import org.eclipse.ui.IWorkbenchPartSite; import org.eclipse.ui.ide.FileStoreEditorInput; import org.eclipse.wst.wsdl.Definition; import org.eclipse.wst.wsdl.ui.internal.ISelectionMapper; +import org.eclipse.wst.wsdl.ui.internal.refactor.handlers.RenameHandler; import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactorActionGroup; import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactorGroupActionDelegate; import org.eclipse.wst.xsd.ui.internal.refactor.wizard.RefactorGroupSubMenu; + +/** + * @deprecated This class is replaced by {@link RenameHandler}. + */ + public class WSDLRefactorGroupActionDelegate extends RefactorGroupActionDelegate { public WSDLRefactorGroupActionDelegate() diff --git a/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/handlers/RenameHandler.java b/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/handlers/RenameHandler.java new file mode 100644 index 000000000..7e4a0d9c7 --- /dev/null +++ b/bundles/org.eclipse.wst.wsdl.ui/src-refactor/org/eclipse/wst/wsdl/ui/internal/refactor/handlers/RenameHandler.java @@ -0,0 +1,234 @@ +/******************************************************************************* + * 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.wsdl.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.core.commands.IHandler; +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +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.swt.widgets.Display; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.actions.GlobalBuildAction; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.wst.common.ui.internal.dialogs.SaveDirtyFilesDialog; +import org.eclipse.wst.wsdl.Binding; +import org.eclipse.wst.wsdl.Definition; +import org.eclipse.wst.wsdl.Message; +import org.eclipse.wst.wsdl.PortType; +import org.eclipse.wst.wsdl.WSDLElement; +import org.eclipse.wst.wsdl.internal.impl.DefinitionImpl; +import org.eclipse.wst.wsdl.internal.impl.WSDLElementImpl; +import org.eclipse.wst.wsdl.ui.internal.WSDLEditorPlugin; +import org.eclipse.wst.wsdl.ui.internal.adapters.WSDLBaseAdapter; +import org.eclipse.wst.wsdl.ui.internal.util.NodeAssociationManager; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; +import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringMessages; +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.RenameRefactoringWizard; +import org.eclipse.xsd.XSDAttributeDeclaration; +import org.eclipse.xsd.XSDConcreteComponent; +import org.eclipse.xsd.XSDElementDeclaration; +import org.eclipse.xsd.XSDNamedComponent; +import org.eclipse.xsd.XSDTypeDefinition; +import org.w3c.dom.Element; + +public class RenameHandler extends AbstractHandler implements IHandler { + 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; + + Definition definition = (Definition) editor.getAdapter(Definition.class); + if (definition == null) return null; + + ISelection selection = activePage.getSelection(); + return execute(definition, selection); + } + + public Object execute(Definition definition, ISelection selection) { + if ( ! (selection instanceof IStructuredSelection)) return null; + + IStructuredSelection structuredSelection = (IStructuredSelection) selection; + Object element = structuredSelection.getFirstElement(); + if ( ! (element instanceof WSDLBaseAdapter || element instanceof WSDLElement)) return null; + + + + if (element instanceof WSDLBaseAdapter) { + // convert the WSDLBaseAdapter (EMF) to WSDLElement + element = ((WSDLBaseAdapter) element).getTarget(); + } + XMLRefactoringComponent selectedComponent = getRefactoringComponent(definition, element); + if (selectedComponent != null) { + run(definition, selectedComponent); + } + + return null; + } + + protected XMLRefactoringComponent getXSDRefactoringComponent(XSDNamedComponent selectedObject) { + + XMLRefactoringComponent selectedComponent = null; + if ( selectedObject.getElement() instanceof IDOMElement) { + selectedComponent = new XMLRefactoringComponent( + selectedObject, + (IDOMElement)selectedObject.getElement(), + selectedObject.getName(), + selectedObject.getTargetNamespace()); + + // if it's element reference, then this action is not appropriate + if (selectedObject instanceof XSDElementDeclaration) { + XSDElementDeclaration element = (XSDElementDeclaration) selectedObject; + if (element.isElementDeclarationReference()) { + selectedComponent = null; + } + } + if(selectedObject instanceof XSDTypeDefinition){ + XSDTypeDefinition type = (XSDTypeDefinition) selectedObject; + XSDConcreteComponent parent = type.getContainer(); + if (parent instanceof XSDElementDeclaration) { + XSDElementDeclaration element = (XSDElementDeclaration) parent; + if(element.getAnonymousTypeDefinition().equals(type)){ + selectedComponent = null; + } + } + else if(parent instanceof XSDAttributeDeclaration) { + XSDAttributeDeclaration element = (XSDAttributeDeclaration) parent; + if(element.getAnonymousTypeDefinition().equals(type)){ + selectedComponent = null; + } + } + } + } + + return selectedComponent; + } + + protected XMLRefactoringComponent getWSDLRefactoringComponent(WSDLElement selectedObject) { + + XMLRefactoringComponent selectedComponent = null; + String localName = null; + String namespace = null; + if (selectedObject instanceof Binding){ + localName = ((Binding)selectedObject).getQName().getLocalPart(); + namespace = ((Binding)selectedObject).getQName().getNamespaceURI(); + } + else if (selectedObject instanceof PortType){ + localName = ((PortType)selectedObject).getQName().getLocalPart(); + namespace = ((PortType)selectedObject).getQName().getNamespaceURI(); + } + else if (selectedObject instanceof Message){ + localName = ((Message)selectedObject).getQName().getLocalPart(); + namespace = ((Message)selectedObject).getQName().getNamespaceURI(); + } + if(localName != null){ + selectedComponent = new XMLRefactoringComponent( + selectedObject, + (IDOMElement)selectedObject.getElement(), + localName, + namespace); + } + + return selectedComponent; + } + + protected XMLRefactoringComponent getRefactoringComponent(Definition definition, Object selectedObject) { + + if (selectedObject instanceof XSDNamedComponent) { + return getXSDRefactoringComponent((XSDNamedComponent) selectedObject); + } else if(selectedObject instanceof WSDLElementImpl){ + return getWSDLRefactoringComponent((WSDLElementImpl) selectedObject); + } + if (selectedObject instanceof Element) { + Element node = (Element) selectedObject; + if (definition != null) { + // issue (eb) dependency on utility class to get component from the model based on element + Object concreteComponent = (new NodeAssociationManager()).getModelObjectForNode(definition, node); + return getRefactoringComponent(definition, concreteComponent); + } + } + + return null; + } + + + public void run(final Definition definition, XMLRefactoringComponent selectedComponent) { + + boolean rc = SaveDirtyFilesDialog.saveDirtyFiles(); + if (!rc) + { + return; + } + RenameComponentProcessor processor = new RenameComponentProcessor(selectedComponent, selectedComponent.getName()); + RenameRefactoring refactoring = new RenameRefactoring(processor); + try { + RefactoringWizard wizard = new RenameRefactoringWizard( + refactoring, + RefactoringMessages + .getString("RenameComponentWizard.defaultPageTitle"), //$NON-NLS-1$ TODO: provide correct strings + RefactoringMessages + .getString("RenameComponentWizard.inputPage.description"), //$NON-NLS-1$ + null) + { + public boolean performFinish() + { + boolean rc = super.performFinish(); + //((DefinitionImpl)getDefinition()).reconcileReferences(true); + return rc; + } + + }; + RefactoringWizardOpenOperation operation = new RefactoringWizardOpenOperation( + wizard); + operation.run(WSDLEditorPlugin.getShell(), wizard + .getDefaultPageTitle()); + triggerBuild(); + + Display.getCurrent().asyncExec(new Runnable() + { + public void run() + { + ((DefinitionImpl)definition).reconcileReferences(true); + } + }); + + } catch (InterruptedException e) { + // do nothing. User action got cancelled + } + + if (definition instanceof DefinitionImpl) { + ((DefinitionImpl) definition).reconcileReferences(true); + } + } + + public static void triggerBuild() { + if (ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding()) { + new GlobalBuildAction(WSDLEditorPlugin.getInstance().getWorkbench() + .getActiveWorkbenchWindow(), + IncrementalProjectBuilder.INCREMENTAL_BUILD).run(); + } + } +} |