diff options
author | Christian W. Damus | 2016-11-02 14:14:40 +0000 |
---|---|---|
committer | Christian W. Damus | 2016-11-02 15:57:24 +0000 |
commit | 4a1cb9f9a8f065c323065bad3fbdc0027f2543b2 (patch) | |
tree | 0a98300ac278713ab5b39aed7482f9bb8a2ed0ff | |
parent | 4a48cdce7f043c5eb617ed0917d1dcbd785425de (diff) | |
download | org.eclipse.papyrus-4a1cb9f9a8f065c323065bad3fbdc0027f2543b2.tar.gz org.eclipse.papyrus-4a1cb9f9a8f065c323065bad3fbdc0027f2543b2.tar.xz org.eclipse.papyrus-4a1cb9f9a8f065c323065bad3fbdc0027f2543b2.zip |
Bug 506896: F2 rename action does not use edit helpers
Delegate to the edit-helper command for setting the name of a named
element. Also clean up a bit as long as there is no API impact (the
handlers package is not exported).
https://bugs.eclipse.org/bugs/show_bug.cgi?id=506896
Change-Id: I03dc4a92622a64ad8870df43cdf67c8144847ba9
5 files changed, 72 insertions, 63 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.uml.commands/.classpath b/plugins/uml/org.eclipse.papyrus.uml.commands/.classpath index 2d1a4302f04..eca7bdba8f0 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.commands/.classpath +++ b/plugins/uml/org.eclipse.papyrus.uml.commands/.classpath @@ -1,7 +1,7 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/uml/org.eclipse.papyrus.uml.commands/.settings/org.eclipse.jdt.core.prefs b/plugins/uml/org.eclipse.papyrus.uml.commands/.settings/org.eclipse.jdt.core.prefs index 4759947300a..62a08f4494d 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.commands/.settings/org.eclipse.jdt.core.prefs +++ b/plugins/uml/org.eclipse.papyrus.uml.commands/.settings/org.eclipse.jdt.core.prefs @@ -1,10 +1,10 @@ eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
diff --git a/plugins/uml/org.eclipse.papyrus.uml.commands/META-INF/MANIFEST.MF b/plugins/uml/org.eclipse.papyrus.uml.commands/META-INF/MANIFEST.MF index 6051fd69b08..03584e7f124 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.commands/META-INF/MANIFEST.MF +++ b/plugins/uml/org.eclipse.papyrus.uml.commands/META-INF/MANIFEST.MF @@ -7,10 +7,10 @@ Require-Bundle: org.eclipse.emf;bundle-version="[2.6.0,3.0.0)", Export-Package: org.eclipse.papyrus.uml.commands.command Bundle-Vendor: %providerName Bundle-ActivationPolicy: lazy -Bundle-Version: 1.2.0.qualifier +Bundle-Version: 1.2.1.qualifier Bundle-Localization: plugin Bundle-Name: %pluginName Bundle-Activator: org.eclipse.papyrus.uml.commands.Activator Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.eclipse.papyrus.uml.commands;singleton:=true -Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 diff --git a/plugins/uml/org.eclipse.papyrus.uml.commands/pom.xml b/plugins/uml/org.eclipse.papyrus.uml.commands/pom.xml index dc0f9e0635a..373ec09df8b 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.commands/pom.xml +++ b/plugins/uml/org.eclipse.papyrus.uml.commands/pom.xml @@ -7,6 +7,6 @@ <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>org.eclipse.papyrus.uml.commands</artifactId> - <version>1.2.0-SNAPSHOT</version> + <version>1.2.1-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project> diff --git a/plugins/uml/org.eclipse.papyrus.uml.commands/src/org/eclipse/papyrus/uml/commands/handler/RenameNamedElementHandler.java b/plugins/uml/org.eclipse.papyrus.uml.commands/src/org/eclipse/papyrus/uml/commands/handler/RenameNamedElementHandler.java index 37c35ed687e..d2978037afe 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.commands/src/org/eclipse/papyrus/uml/commands/handler/RenameNamedElementHandler.java +++ b/plugins/uml/org.eclipse.papyrus.uml.commands/src/org/eclipse/papyrus/uml/commands/handler/RenameNamedElementHandler.java @@ -1,6 +1,5 @@ /***************************************************************************** - * Copyright (c) 2011 CEA LIST. - * + * Copyright (c) 2011, 2016 CEA LIST, Christian W. Damus, and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -9,91 +8,101 @@ * * Contributors: * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation + * Christian W. Damus - bug 506896 * *****************************************************************************/ package org.eclipse.papyrus.uml.commands.handler; import java.util.List; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.expressions.IEvaluationContext; +import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CommandWrapper; +import org.eclipse.emf.common.command.UnexecutableCommand; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gmf.runtime.common.core.command.CommandResult; -import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand; +import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper; +import org.eclipse.papyrus.infra.emf.gmf.command.ICommandWrapper; import org.eclipse.papyrus.infra.emf.utils.EMFHelper; +import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; +import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; +import org.eclipse.papyrus.infra.ui.command.AbstractCommandHandler; import org.eclipse.papyrus.views.modelexplorer.DirectEditorEditingSupport; -import org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler; import org.eclipse.swt.widgets.Display; import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.UMLPackage; + +import com.google.common.base.Strings; /** - * This handler allows to rename {@link NamedElement} - * - * - * + * This handler implements renaming of {@link NamedElement}s. */ public class RenameNamedElementHandler extends AbstractCommandHandler { - /** - * - * @see org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler#getCommand() - * - * @return - */ @Override - protected Command getCommand() { - TransactionalEditingDomain editingDomain = getEditingDomain(getCurrentContext()); - List<EObject> selectedElements = getSelectedElements(); - if (selectedElements.size() == 1 && selectedElements.get(0) instanceof NamedElement) { - final NamedElement namedElement = (NamedElement) selectedElements.get(0); + protected Command getCommand(IEvaluationContext context) { + Command result = UnexecutableCommand.INSTANCE; + + TransactionalEditingDomain editingDomain = getEditingDomain(context); + EObject selectedElement = getSelectedElement(); + if (selectedElement instanceof NamedElement) { + final NamedElement namedElement = (NamedElement) selectedElement; final String currentName = namedElement.getName(); + if (currentName != null) { + result = new CommandWrapper("Rename", "Change the name of an element", null) { + @Override + public boolean canExecute() { + // Don't show the input dialog for canExecute() + return !isPrepared || basicCanExecute(); + } + + protected final boolean basicCanExecute() { + return super.canExecute(); + } - AbstractTransactionalCommand cmd = new AbstractTransactionalCommand(editingDomain, "RenameCommand", null) { //$NON-NLS-1$ - - /** - * - * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) - * - * @param monitor - * @param info - * @return - * @throws ExecutionException - */ @Override - protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { + public void execute() { + if (basicCanExecute()) { + super.execute(); + } else { + // Balk: we shouldn't have been executable + throw new OperationCanceledException(); + } + } + + @Override + protected Command createCommand() { + Command result = UnexecutableCommand.INSTANCE; + InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), "Rename...", "New name:", currentName, null); if (dialog.open() == Window.OK) { - final String name = dialog.getValue(); - if (name != null && name.length() > 0) { - namedElement.setName(name); + String name = dialog.getValue(); + + if (!Strings.isNullOrEmpty(name) && !name.equals(currentName)) { + IElementEditService edit = ElementEditServiceUtils.getCommandProvider(namedElement); + SetRequest request = new SetRequest(editingDomain, namedElement, UMLPackage.Literals.NAMED_ELEMENT__NAME, name); + if (edit.canEdit(request)) { + result = ICommandWrapper.wrap(edit.getEditCommand(request), Command.class); + } } - return CommandResult.newOKCommandResult(); - } else { - return CommandResult.newCancelledCommandResult(); } + + return result; } }; - return new GMFtoEMFCommandWrapper(cmd); } } - return null; + return result; } - /** - * - * {@inheritDoc} - */ @Override - protected boolean computeEnabled() { - boolean enabled = super.computeEnabled(); + protected boolean computeEnabled(IEvaluationContext context) { + boolean enabled = super.computeEnabled(context); if (enabled) { List<EObject> selectedElements = getSelectedElements(); EObject selection = selectedElements.get(0); |