Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThanh Liem PHAN2017-02-03 10:18:06 +0000
committerGerrit Code Review @ Eclipse.org2017-02-13 16:31:07 +0000
commitab72855fe5e4410565b1521fc6d9fc968d473a6b (patch)
treeeed040729abdcfb2df8ad5d56dd543b4ea7a21ac /plugins/views
parent6d837be05a8f6c176c25d0e3e0e452aecba1fb81 (diff)
downloadorg.eclipse.papyrus-ab72855fe5e4410565b1521fc6d9fc968d473a6b.tar.gz
org.eclipse.papyrus-ab72855fe5e4410565b1521fc6d9fc968d473a6b.tar.xz
org.eclipse.papyrus-ab72855fe5e4410565b1521fc6d9fc968d473a6b.zip
Bug 509357: [Model Explorer] Rename... Contextual menu doesn't exist
anymore for element https://bugs.eclipse.org/bugs/show_bug.cgi?id=509357 - Add commands to rename an element and its label - Refactor common methods into the ModelExplorerEditionUtil class - Refactor rename handlers - Correct an NPE in DirectEditorEditingSupport - Externalise the dialog's parameters Change-Id: I96dd078590139bde342fa6c0e633d04c4cd40b92 Signed-off-by: Thanh Liem PHAN <thanhliem.phan@all4tec.net>
Diffstat (limited to 'plugins/views')
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/META-INF/MANIFEST.MF3
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/DirectEditorEditingSupport.java30
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/commands/RenameElementCommand.java117
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/commands/RenameLabelCommand.java94
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/messages/Messages.java32
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/messages/messages.properties1
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/util/ModelExplorerEditionUtil.java85
7 files changed, 348 insertions, 14 deletions
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/META-INF/MANIFEST.MF b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/META-INF/MANIFEST.MF
index 303731cc0ea..bf007871e7e 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/META-INF/MANIFEST.MF
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/META-INF/MANIFEST.MF
@@ -10,7 +10,8 @@ Export-Package: org.eclipse.papyrus.views.modelexplorer,
org.eclipse.papyrus.views.modelexplorer.handler,
org.eclipse.papyrus.views.modelexplorer.matching,
org.eclipse.papyrus.views.modelexplorer.preferences,
- org.eclipse.papyrus.views.modelexplorer.queries
+ org.eclipse.papyrus.views.modelexplorer.queries,
+ org.eclipse.papyrus.views.modelexplorer.util
Require-Bundle: org.eclipse.ui.navigator;bundle-version="[3.6.0,4.0.0)";visibility:=reexport,
org.eclipse.emf.converter;bundle-version="[2.7.0,3.0.0)",
org.eclipse.emf.ecore.editor;bundle-version="[2.11.0,3.0.0)",
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/DirectEditorEditingSupport.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/DirectEditorEditingSupport.java
index 52109dc3526..dd6ef9f3af7 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/DirectEditorEditingSupport.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/DirectEditorEditingSupport.java
@@ -94,7 +94,7 @@ public class DirectEditorEditingSupport extends EditingSupport {
}
/**
- * Obtain direct editor configuration for a semantic element
+ * Obtain direct editor configuration for a semantic element.
*
* @param semanticElement
* a semantic element
@@ -102,22 +102,26 @@ public class DirectEditorEditingSupport extends EditingSupport {
*/
public static ICustomDirectEditorConfiguration getConfiguration(final EObject semanticElement) {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
- EClass eClass = semanticElement.eClass();
- String semanticClassName = eClass.getInstanceClassName();
- String key = IDirectEditorsIds.EDITOR_FOR_ELEMENT + semanticClassName;
- String languagePreferred = store.getString(key);
- IDirectEditorConfiguration configuration = null;
+ if (null != semanticElement) {
+ EClass eClass = semanticElement.eClass();
+ String semanticClassName = eClass.getInstanceClassName();
+ String key = IDirectEditorsIds.EDITOR_FOR_ELEMENT + semanticClassName;
+ String languagePreferred = store.getString(key);
- if (null != languagePreferred && !languagePreferred.isEmpty()) {
- configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, semanticElement, semanticElement);
- } else {
- configuration = getConfigurationSuperType(eClass, semanticElement);
- }
+ IDirectEditorConfiguration configuration = null;
+
+ if (null != languagePreferred && !languagePreferred.isEmpty()) {
+ configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, semanticElement, semanticElement);
+ } else {
+ configuration = getConfigurationSuperType(eClass, semanticElement);
+ }
- if (configuration instanceof ICustomDirectEditorConfiguration) {
- return (ICustomDirectEditorConfiguration) configuration;
+ if (configuration instanceof ICustomDirectEditorConfiguration) {
+ return (ICustomDirectEditorConfiguration) configuration;
+ }
}
+
return null;
}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/commands/RenameElementCommand.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/commands/RenameElementCommand.java
new file mode 100644
index 00000000000..64bcf11f63a
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/commands/RenameElementCommand.java
@@ -0,0 +1,117 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST.
+ *
+ * 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:
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.views.modelexplorer.commands;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+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.ICommandWrapper;
+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.InteractiveCommandWrapper;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Command to rename an element.
+ */
+public class RenameElementCommand extends InteractiveCommandWrapper {
+
+ /**
+ * The editing domain.
+ */
+ private TransactionalEditingDomain editingDomain = null;
+
+ /**
+ * The element to be renamed.
+ */
+ private EObject element = null;
+
+ /**
+ * The current name of element.
+ */
+ private String currentElementName = null;
+
+ /**
+ * The structural feature of name.
+ */
+ private EStructuralFeature nameStructuralFeature = null;
+
+ /**
+ * The input dialog title.
+ */
+ private String dialogTitle = null;
+
+ /**
+ * The input dialog message.
+ */
+ private String dialogMessage = null;
+
+ /**
+ * Default constructor.
+ *
+ * @param editingDomain
+ * The editing domain
+ * @param commandLabel
+ * The command label
+ * @param element
+ * The named element
+ * @param currentElementName
+ * The current element name
+ * @param nameStructuralFeature
+ * The name structural feature
+ * @param dialogTitle
+ * The dialog title
+ * @param dialogMessage
+ * The dialog message
+ */
+ public RenameElementCommand(final TransactionalEditingDomain editingDomain, final String commandLabel, final EObject element, final String currentElementName, final EStructuralFeature nameStructuralFeature, final String dialogTitle,
+ final String dialogMessage) {
+ super(commandLabel);
+ this.editingDomain = editingDomain;
+ this.element = element;
+ this.currentElementName = currentElementName;
+ this.nameStructuralFeature = nameStructuralFeature;
+ this.dialogTitle = dialogTitle;
+ this.dialogMessage = dialogMessage;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Command createCommand() {
+ Command result = UnexecutableCommand.INSTANCE;
+
+ InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), this.dialogTitle, this.dialogMessage, this.currentElementName, null);
+
+ // Check parameters before opening the input dialog
+ if (null != this.editingDomain && null != this.element && null != this.nameStructuralFeature && Window.OK == dialog.open()) {
+ String newName = dialog.getValue();
+
+ if (null != newName && !newName.isEmpty() && !newName.equals(this.currentElementName)) {
+ IElementEditService edit = ElementEditServiceUtils.getCommandProvider(this.element);
+
+ SetRequest request = new SetRequest(this.editingDomain, this.element, this.nameStructuralFeature, newName);
+ if (edit.canEdit(request)) {
+ result = ICommandWrapper.wrap(edit.getEditCommand(request), Command.class);
+ }
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/commands/RenameLabelCommand.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/commands/RenameLabelCommand.java
new file mode 100644
index 00000000000..ab8a36a63f7
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/commands/RenameLabelCommand.java
@@ -0,0 +1,94 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST.
+ *
+ * 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:
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.views.modelexplorer.commands;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+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.jface.dialogs.InputDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.views.modelexplorer.messages.Messages;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Command to rename a label of an element.
+ */
+public abstract class RenameLabelCommand extends AbstractTransactionalCommand {
+
+ /**
+ * The element whose label will be renamed.
+ */
+ private EObject element = null;
+
+ /**
+ * The current element label.
+ */
+ private String currentElementLabel = null;
+
+ /**
+ * The input dialog title.
+ */
+ private String dialogTitle = null;
+
+ /**
+ * Default constructor.
+ *
+ * @param editingDomain
+ * The editing domain
+ * @param commandLabel
+ * The command label
+ * @param element
+ * The element whose label is renamed
+ * @param currentElementLabel
+ * The current element label
+ * @param dialogTitle
+ * The dialog title
+ */
+ public RenameLabelCommand(final TransactionalEditingDomain editingDomain, final String commandLabel, final EObject element, final String currentElementLabel, final String dialogTitle) {
+ super(editingDomain, commandLabel, null);
+ this.element = element;
+ this.currentElementLabel = currentElementLabel;
+ this.dialogTitle = dialogTitle;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), this.dialogTitle, Messages.RenameLabelCommand_DialogMessage, this.currentElementLabel, null);
+
+ if (Window.OK == dialog.open()) {
+ final String newLabel = dialog.getValue();
+ if (null != newLabel && !newLabel.equals(this.currentElementLabel)) {
+ renameLabel(this.element, newLabel);
+ }
+ return CommandResult.newOKCommandResult();
+ } else {
+ return CommandResult.newCancelledCommandResult();
+ }
+ }
+
+ /**
+ * Rename the label of an element.
+ *
+ * @param element
+ * The element
+ * @param newLabel
+ * The new label
+ */
+ protected abstract void renameLabel(final EObject element, final String newLabel);
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/messages/Messages.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/messages/Messages.java
new file mode 100644
index 00000000000..b6b81990ad9
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/messages/Messages.java
@@ -0,0 +1,32 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST.
+ *
+ * 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:
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.views.modelexplorer.messages;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Messages class for the plugin org.eclipse.papyrus.views.modelexplorer.
+ */
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.views.modelexplorer.messages.messages"; //$NON-NLS-1$
+
+ public static String RenameLabelCommand_DialogMessage;
+
+ static {
+ // Initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/messages/messages.properties b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/messages/messages.properties
new file mode 100644
index 00000000000..6cd545bbd4d
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/messages/messages.properties
@@ -0,0 +1 @@
+RenameLabelCommand_DialogMessage=New label:
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/util/ModelExplorerEditionUtil.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/util/ModelExplorerEditionUtil.java
new file mode 100644
index 00000000000..1cfcd090b74
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/util/ModelExplorerEditionUtil.java
@@ -0,0 +1,85 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST.
+ *
+ * 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:
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.views.modelexplorer.util;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.infra.ui.util.WorkbenchPartHelper;
+import org.eclipse.papyrus.views.modelexplorer.DirectEditorEditingSupport;
+import org.eclipse.papyrus.views.modelexplorer.ModelExplorerPageBookView;
+import org.eclipse.papyrus.views.modelexplorer.ModelExplorerView;
+import org.eclipse.papyrus.views.modelexplorer.core.ui.pagebookview.MultiViewPageBookView;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPage;
+
+/**
+ * Class contains common methods to be used by different handlers in Model Explorer.
+ */
+public class ModelExplorerEditionUtil {
+
+ /**
+ * @return The Model Explorer active view part
+ */
+ public static IViewPart getModelExplorerActiveViewPart() {
+ IViewPart activeView = null;
+
+ final IWorkbenchPage activeWorkbenchPage = WorkbenchPartHelper.getCurrentActiveWorkbenchPage();
+
+ if (null != activeWorkbenchPage) {
+ // Get Model Explorer view part
+ final IViewPart modelExplorerView = activeWorkbenchPage.findView(ModelExplorerPageBookView.VIEW_ID);
+
+ if (modelExplorerView instanceof MultiViewPageBookView) {
+ final MultiViewPageBookView pageBook = (MultiViewPageBookView) modelExplorerView;
+ activeView = pageBook.getActiveView();
+ }
+ }
+
+ return activeView;
+ }
+
+ /**
+ * Check whether the editing of an element is handled by a direct editor. In this case, we do
+ * not want to open the rename pop-up.
+ *
+ * @param element
+ * The element that should be edited
+ * @return <code>true</code> if the element is handled by a direct editor, <code>false</code> otherwise
+ */
+ public static boolean isHandledByDirectEditor(final EObject element) {
+ return null != DirectEditorEditingSupport.getConfiguration(element);
+ }
+
+ /**
+ * Edit a selection element from the model explorer view.
+ *
+ * @param selectionObject
+ * The selection object to be edited
+ */
+ public static void editElement(final EObject selectionObject) {
+ Display.getCurrent().asyncExec(new Runnable() {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void run() {
+ IViewPart viewPart = getModelExplorerActiveViewPart();
+
+ if (viewPart instanceof ModelExplorerView) {
+ ((ModelExplorerView) viewPart).editElement(selectionObject, 0);
+ }
+ }
+ });
+ }
+}

Back to the top