Skip to main content
aboutsummaryrefslogtreecommitdiffstats
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/infra
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/infra')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/commands/RenameDiagramLabelCommand.java51
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/handlers/RenameDiagramHandler.java99
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/messages/Messages.java68
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/messages/messages.properties7
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/commands/RenameTableLabelCommand.java51
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/handlers/RenameTableHandler.java90
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/messages/Messages.java68
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/messages/messages.properties7
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.ui/src/org/eclipse/papyrus/infra/ui/command/AbstractCommandHandler.java1
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.ui/src/org/eclipse/papyrus/infra/ui/util/WorkbenchPartHelper.java59
10 files changed, 280 insertions, 221 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/commands/RenameDiagramLabelCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/commands/RenameDiagramLabelCommand.java
new file mode 100644
index 00000000000..85f71ca420c
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/commands/RenameDiagramLabelCommand.java
@@ -0,0 +1,51 @@
+/*****************************************************************************
+ * 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.infra.gmfdiag.modelexplorer.commands;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.infra.internationalization.utils.utils.LabelInternationalization;
+import org.eclipse.papyrus.views.modelexplorer.commands.RenameLabelCommand;
+
+/**
+ * Command to rename a label of a {@link Diagram}.
+ */
+public class RenameDiagramLabelCommand extends RenameLabelCommand {
+
+ /**
+ * Default constructor.
+ *
+ * @param editingDomain
+ * The editing domain
+ * @param commandLabel
+ * The command label
+ * @param element
+ * The element whose label is renamed
+ * @param elementLabel
+ * The element label
+ * @param dialogTitle
+ * The dialog title
+ */
+ public RenameDiagramLabelCommand(final TransactionalEditingDomain editingDomain, final String commandLabel, final EObject element, final String elementLabel, final String dialogTitle) {
+ super(editingDomain, commandLabel, element, elementLabel, dialogTitle);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void renameLabel(final EObject element, final String newLabel) {
+ if (element instanceof Diagram) {
+ LabelInternationalization.getInstance().setDiagramLabel((Diagram) element, newLabel, null);
+ }
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/handlers/RenameDiagramHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/handlers/RenameDiagramHandler.java
index a318f4d1a89..98c0cb7dd2a 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/handlers/RenameDiagramHandler.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/handlers/RenameDiagramHandler.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2011, 2016 CEA LIST, Christian W. Damus, and others.
+ * Copyright (c) 2011, 2016, 2017 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
@@ -11,35 +11,33 @@
* Christian W. Damus - bug 485220
* Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Bug 497289
* Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905
- *
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 509357
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.modelexplorer.handlers;
import java.util.List;
+import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.expressions.IEvaluationContext;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
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.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
import org.eclipse.gmf.runtime.notation.Diagram;
-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.utils.EMFHelper;
+import org.eclipse.papyrus.infra.gmfdiag.modelexplorer.commands.RenameDiagramLabelCommand;
import org.eclipse.papyrus.infra.gmfdiag.modelexplorer.messages.Messages;
import org.eclipse.papyrus.infra.internationalization.utils.utils.LabelInternationalization;
import org.eclipse.papyrus.infra.internationalization.utils.utils.LabelInternationalizationPreferencesUtils;
-import org.eclipse.papyrus.views.modelexplorer.DirectEditorEditingSupport;
-import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper;
-import org.eclipse.swt.widgets.Display;
+import org.eclipse.papyrus.views.modelexplorer.commands.RenameElementCommand;
+import org.eclipse.papyrus.views.modelexplorer.util.ModelExplorerEditionUtil;
/**
- * This handler provides the method to rename a Diagram
+ * This handler provides the method to rename a Diagram.
*/
public class RenameDiagramHandler extends AbstractDiagramCommandHandler {
@@ -54,56 +52,16 @@ public class RenameDiagramHandler extends AbstractDiagramCommandHandler {
if (editingDomain != null && diagrams.size() == 1) {
final Diagram diag = diagrams.get(0);
-
+
final String diagramLabel = LabelInternationalization.getInstance().getDiagramLabelWithoutName(diag);
- if(null != diagramLabel && LabelInternationalizationPreferencesUtils.getInternationalizationPreference(diag)){
- AbstractTransactionalCommand cmd = new AbstractTransactionalCommand(editingDomain, "ChangeDiagramLabelCommand", 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(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
- InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), "Rename diagram label...", "New label:", diagramLabel, null); //$NON-NLS-1$ //$NON-NLS-2$
- if (Window.OK == dialog.open()) {
- final String label = dialog.getValue();
- if (label != null && label.length() > 0) {
- LabelInternationalization.getInstance().setDiagramLabel(diag, label, null);
- }
- return CommandResult.newOKCommandResult();
- } else {
- return CommandResult.newCancelledCommandResult();
- }
- }
- };
+ if (null != diagramLabel && LabelInternationalizationPreferencesUtils.getInternationalizationPreference(diag)) {
+ AbstractTransactionalCommand cmd = new RenameDiagramLabelCommand(editingDomain, "ChangeDiagramLabelCommand", diag, diagramLabel, Messages.RenameDiagramHandler_Label_DialogTitle); //$NON-NLS-1$
return new GMFtoEMFCommandWrapper(cmd);
- }else{
+ } else {
final String currentName = diag.getName();
if (currentName != null) {
-
- AbstractTransactionalCommand cmd = new AbstractTransactionalCommand(editingDomain, "RenameDiagramCommand", null) { //$NON-NLS-1$
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), Messages.RenameDiagramHandler_RenameAnExistingDiagram, Messages.RenameDiagramHandler_NewName, currentName, null);
- if (dialog.open() == Window.OK) {
- final String name = dialog.getValue();
- if (name != null && name.length() > 0) {
- diag.setName(name);
- }
- return CommandResult.newOKCommandResult();
- } else {
- return CommandResult.newCancelledCommandResult();
- }
- }
- };
- return new GMFtoEMFCommandWrapper(cmd);
+ EStructuralFeature nameFeature = diag.eClass().getEStructuralFeature("name"); //$NON-NLS-1$
+ return new RenameElementCommand(editingDomain, "RenameDiagramCommand", diag, currentName, nameFeature, Messages.RenameDiagramHandler_RenameAnExistingDiagram, Messages.RenameDiagramHandler_NewName); //$NON-NLS-1$
}
}
}
@@ -119,21 +77,30 @@ public class RenameDiagramHandler extends AbstractDiagramCommandHandler {
if (computeEnabled) {
List<EObject> selectedElements = getSelectedElements();
EObject selection = selectedElements.get(0);
- computeEnabled = !EMFHelper.isReadOnly(selection) && !isHandledByDirectEditor(selection);
+ computeEnabled = !EMFHelper.isReadOnly(selection);
}
return computeEnabled;
}
/**
- * 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
- * an element that should be edited.
- * @return true, if handled by a direct editor
+ * {@inheritDoc}
+ *
+ * Overridden to inline edit a diagram if it is handled by direct editor.
*/
- protected boolean isHandledByDirectEditor(final EObject element) {
- return null != DirectEditorEditingSupport.getConfiguration(element);
+ @Override
+ public Object execute(final ExecutionEvent event) throws ExecutionException {
+ EObject selectedDiagram = getSelectedElement();
+
+ // If the diagram could be handled by direct editor
+ if (ModelExplorerEditionUtil.isHandledByDirectEditor(selectedDiagram)) {
+ // Call the edit element method from the model explorer to trigger DirectEditor
+ ModelExplorerEditionUtil.editElement(selectedDiagram);
+ } else {
+ // Otherwise, show the model dialog to get user input
+ super.execute(event);
+ }
+
+ return null;
}
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/messages/Messages.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/messages/Messages.java
index 80beb8c4d98..154e3311a9a 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/messages/Messages.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/messages/Messages.java
@@ -1,33 +1,35 @@
-/*****************************************************************************
- * Copyright (c) 2014 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:
- * Patrick Tessier (CEA LIST) - Initial API and implementation
- /*****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.modelexplorer.messages;
-
-import org.eclipse.osgi.util.NLS;
-
-public class Messages extends NLS {
-
- private static final String BUNDLE_NAME = "org.eclipse.papyrus.infra.gmfdiag.modelexplorer.messages.messages"; //$NON-NLS-1$
-
- public static String DuplicateDiagramHandler_CopyOf;
-
- public static String RenameDiagramHandler_NewName;
-
- public static String RenameDiagramHandler_RenameAnExistingDiagram;
- static {
- // initialize resource bundle
- NLS.initializeMessages(BUNDLE_NAME, Messages.class);
- }
-
- private Messages() {
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2014, 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:
+ * Patrick Tessier (CEA LIST) - Initial API and implementation
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 509357
+ /*****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.modelexplorer.messages;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.infra.gmfdiag.modelexplorer.messages.messages"; //$NON-NLS-1$
+
+ public static String DuplicateDiagramHandler_CopyOf;
+
+ public static String RenameDiagramHandler_NewName;
+
+ public static String RenameDiagramHandler_RenameAnExistingDiagram;
+
+ public static String RenameDiagramHandler_Label_DialogTitle;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/messages/messages.properties b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/messages/messages.properties
index 696090c9cea..799ff43fbf6 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/messages/messages.properties
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/messages/messages.properties
@@ -1,3 +1,4 @@
-DuplicateDiagramHandler_CopyOf=Copy Of {0}
-RenameDiagramHandler_NewName=New name:
-RenameDiagramHandler_RenameAnExistingDiagram=Rename an existing diagram
+DuplicateDiagramHandler_CopyOf=Copy Of {0}
+RenameDiagramHandler_NewName=New name:
+RenameDiagramHandler_RenameAnExistingDiagram=Rename an existing diagram
+RenameDiagramHandler_Label_DialogTitle=Rename diagram label... \ No newline at end of file
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/commands/RenameTableLabelCommand.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/commands/RenameTableLabelCommand.java
new file mode 100644
index 00000000000..f1f2886ac81
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/commands/RenameTableLabelCommand.java
@@ -0,0 +1,51 @@
+/*****************************************************************************
+ * 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.infra.nattable.modelexplorer.commands;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.internationalization.utils.utils.LabelInternationalization;
+import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
+import org.eclipse.papyrus.views.modelexplorer.commands.RenameLabelCommand;
+
+/**
+ * Command to rename a label of a {@link Table}.
+ */
+public class RenameTableLabelCommand extends RenameLabelCommand {
+
+ /**
+ * Default constructor.
+ *
+ * @param editingDomain
+ * The editing domain
+ * @param commandLabel
+ * The command label
+ * @param element
+ * The element whose label is renamed
+ * @param elementLabel
+ * The element label
+ * @param dialogTitle
+ * The dialog title
+ */
+ public RenameTableLabelCommand(final TransactionalEditingDomain editingDomain, final String commandLabel, final EObject element, final String elementLabel, final String dialogTitle) {
+ super(editingDomain, commandLabel, element, elementLabel, dialogTitle);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void renameLabel(final EObject element, final String newLabel) {
+ if (element instanceof Table) {
+ LabelInternationalization.getInstance().setTableLabel((Table) element, newLabel, null);
+ }
+ }
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/handlers/RenameTableHandler.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/handlers/RenameTableHandler.java
index 097ef1f69fa..fe5e827234f 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/handlers/RenameTableHandler.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/handlers/RenameTableHandler.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
+ * Copyright (c) 2013, 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
@@ -10,35 +10,33 @@
* Juan Cadavid (CEA LIST) juan.cadavid@cea.fr - Initial API and implementation
* Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Bug 497289
* Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905
- *
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 509357
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.modelexplorer.handlers;
import java.util.List;
+import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.expressions.IEvaluationContext;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
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.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.infra.emf.gmf.command.GMFtoEMFCommandWrapper;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.internationalization.utils.utils.LabelInternationalization;
import org.eclipse.papyrus.infra.internationalization.utils.utils.LabelInternationalizationPreferencesUtils;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
+import org.eclipse.papyrus.infra.nattable.modelexplorer.commands.RenameTableLabelCommand;
import org.eclipse.papyrus.infra.nattable.modelexplorer.messages.Messages;
-import org.eclipse.papyrus.views.modelexplorer.DirectEditorEditingSupport;
-import org.eclipse.swt.widgets.Display;
+import org.eclipse.papyrus.views.modelexplorer.commands.RenameElementCommand;
+import org.eclipse.papyrus.views.modelexplorer.util.ModelExplorerEditionUtil;
/**
- * This handler provides the method to rename a Table
+ * This handler provides the method to rename a Table.
*/
public class RenameTableHandler extends AbstractTableCommandHandler {
@@ -52,47 +50,16 @@ public class RenameTableHandler extends AbstractTableCommandHandler {
if (editingDomain != null && tables.size() == 1) {
final Table table = tables.get(0);
-
+
final String tableLabel = LabelInternationalization.getInstance().getTableLabelWithoutName(table);
- if(null != tableLabel && LabelInternationalizationPreferencesUtils.getInternationalizationPreference(table)){
- AbstractTransactionalCommand cmd = new AbstractTransactionalCommand(editingDomain, "ChangeTableLabelCommand", null) { //$NON-NLS-1$
-
- @Override
- protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
- InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), "Rename table label...", "New label:", tableLabel, null); //$NON-NLS-1$ //$NON-NLS-2$
- if (Window.OK == dialog.open()) {
- final String label = dialog.getValue();
- if (label != null && label.length() > 0) {
- LabelInternationalization.getInstance().setTableLabel(table, label, null);
- }
- return CommandResult.newOKCommandResult();
- } else {
- return CommandResult.newCancelledCommandResult();
- }
- }
- };
+ if (null != tableLabel && LabelInternationalizationPreferencesUtils.getInternationalizationPreference(table)) {
+ AbstractTransactionalCommand cmd = new RenameTableLabelCommand(editingDomain, "ChangeTableLabelCommand", table, tableLabel, Messages.RenameTableHandler_Label_DialogTitle); //$NON-NLS-1$
return new GMFtoEMFCommandWrapper(cmd);
- }else{
+ } else {
final String currentName = table.getName();
- if (currentName != null) {
-
- AbstractTransactionalCommand cmd = new AbstractTransactionalCommand(editingDomain, "RenameTableCommand", null) { //$NON-NLS-1$
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) {
- InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), Messages.RenameTableHandler_RenameAnExistingTable, Messages.RenameTableHandler_NewName, currentName, null);
- if (dialog.open() == Window.OK) {
- final String name = dialog.getValue();
- if (name != null && name.length() > 0) {
- table.setName(name);
- }
- return CommandResult.newOKCommandResult();
- } else {
- return CommandResult.newCancelledCommandResult();
- }
- }
- };
- return new GMFtoEMFCommandWrapper(cmd);
+ if (null != currentName) {
+ EStructuralFeature nameFeature = table.eClass().getEStructuralFeature("name"); //$NON-NLS-1$
+ return new RenameElementCommand(editingDomain, "RenameTableCommand", table, currentName, nameFeature, Messages.RenameTableHandler_RenameAnExistingTable, Messages.RenameTableHandler_NewName); // $NON-NLS-1$
}
}
}
@@ -108,21 +75,30 @@ public class RenameTableHandler extends AbstractTableCommandHandler {
if (computeEnabled) {
List<EObject> selectedElements = getSelectedElements();
EObject selection = selectedElements.get(0);
- computeEnabled = !EMFHelper.isReadOnly(selection) && !isHandledByDirectEditor(selection);
+ computeEnabled = !EMFHelper.isReadOnly(selection);
}
return computeEnabled;
}
/**
- * 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
- * an element that should be edited.
- * @return true, if handled by a direct editor
+ * {@inheritDoc}
+ *
+ * Overridden to inline edit a table if it is handled by direct editor.
*/
- protected boolean isHandledByDirectEditor(final EObject element) {
- return null != DirectEditorEditingSupport.getConfiguration(element);
+ @Override
+ public Object execute(final ExecutionEvent event) throws ExecutionException {
+ EObject selectedTable = getSelectedElement();
+
+ // If the selected table could be handled by direct editor
+ if (ModelExplorerEditionUtil.isHandledByDirectEditor(selectedTable)) {
+ // Call the edit element method from the model explorer to trigger DirectEditor
+ ModelExplorerEditionUtil.editElement(selectedTable);
+ } else {
+ // Otherwise, show the model dialog to get user input
+ super.execute(event);
+ }
+
+ return null;
}
}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/messages/Messages.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/messages/Messages.java
index d0fe7a9f2b2..9e0ed57180e 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/messages/Messages.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/messages/Messages.java
@@ -1,32 +1,36 @@
-/*****************************************************************************
- * Copyright (c) 2013 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:
- * Juan Cadavid (CEA LIST) juan.cadavid@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.nattable.modelexplorer.messages;
-
-import org.eclipse.osgi.util.NLS;
-
-public class Messages extends NLS {
-
- private static final String BUNDLE_NAME = "org.eclipse.papyrus.infra.nattable.modelexplorer.messages.messages"; //$NON-NLS-1$
-
- public static String DuplicateTableHandler_CopyOf;
-
- public static String RenameTableHandler_NewName;
-
- public static String RenameTableHandler_RenameAnExistingTable;
- static {
- // initialize resource bundle
- NLS.initializeMessages(BUNDLE_NAME, Messages.class);
- }
-
- private Messages() {
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * Juan Cadavid (CEA LIST) juan.cadavid@cea.fr - Initial API and implementation
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 509357
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.modelexplorer.messages;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.infra.nattable.modelexplorer.messages.messages"; //$NON-NLS-1$
+
+ public static String DuplicateTableHandler_CopyOf;
+
+ public static String RenameTableHandler_NewName;
+
+ public static String RenameTableHandler_RenameAnExistingTable;
+
+ public static String RenameTableHandler_Label_DialogTitle;
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/messages/messages.properties b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/messages/messages.properties
index 4cd13849a21..1f426b55e17 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/messages/messages.properties
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/messages/messages.properties
@@ -1,3 +1,4 @@
-DuplicateTableHandler_CopyOf=Copy Of {0}
-RenameTableHandler_NewName=New name:
-RenameTableHandler_RenameAnExistingTable=Rename an existing table
+DuplicateTableHandler_CopyOf=Copy Of {0}
+RenameTableHandler_NewName=New name:
+RenameTableHandler_RenameAnExistingTable=Rename an existing table
+RenameTableHandler_Label_DialogTitle=Rename table label...
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.ui/src/org/eclipse/papyrus/infra/ui/command/AbstractCommandHandler.java b/plugins/infra/ui/org.eclipse.papyrus.infra.ui/src/org/eclipse/papyrus/infra/ui/command/AbstractCommandHandler.java
index c80791a8047..46088acc19a 100644
--- a/plugins/infra/ui/org.eclipse.papyrus.infra.ui/src/org/eclipse/papyrus/infra/ui/command/AbstractCommandHandler.java
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.ui/src/org/eclipse/papyrus/infra/ui/command/AbstractCommandHandler.java
@@ -183,7 +183,6 @@ public abstract class AbstractCommandHandler extends AbstractPapyrusHandler {
if (selection instanceof Collection<?>) {
this.selection = (selection instanceof List<?>) ? (List<?>) selection : new java.util.ArrayList<Object>((Collection<?>) selection);
setBaseEnabled(computeEnabled(context));
- this.selection = Collections.EMPTY_LIST;
}
}
super.setEnabled(evaluationContext);
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.ui/src/org/eclipse/papyrus/infra/ui/util/WorkbenchPartHelper.java b/plugins/infra/ui/org.eclipse.papyrus.infra.ui/src/org/eclipse/papyrus/infra/ui/util/WorkbenchPartHelper.java
index 440fd597ff0..240874d8f23 100644
--- a/plugins/infra/ui/org.eclipse.papyrus.infra.ui/src/org/eclipse/papyrus/infra/ui/util/WorkbenchPartHelper.java
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.ui/src/org/eclipse/papyrus/infra/ui/util/WorkbenchPartHelper.java
@@ -1,6 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
+ * Copyright (c) 2012, 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
@@ -9,7 +8,7 @@
*
* Contributors:
* Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
- *
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 509357
*****************************************************************************/
package org.eclipse.papyrus.infra.ui.util;
@@ -21,11 +20,14 @@ import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
/**
- *
- * a helper for the Eclipse workbench part
+ * A helper for retrieving from Eclipse Platform UI:
+ * <ul>
+ * <li>the active editor part</li>
+ * <li>the active workbench part</li>
+ * <li>and the active workbench</li>
+ * </ul>
*
* @since 1.2
- *
*/
public class WorkbenchPartHelper {
@@ -34,40 +36,45 @@ public class WorkbenchPartHelper {
}
/**
- *
* @return
- * the current IWorkbenchPart or <code>null</code> if not found
+ * The current {@link IWorkbenchPage} or <code>null</code> if not found
*/
- public static final IWorkbenchPart getCurrentActiveWorkbenchPart() {
+ public static final IWorkbenchPage getCurrentActiveWorkbenchPage() {
final IWorkbench workbench = PlatformUI.getWorkbench();
- if (workbench != null) {
+ if (null != workbench) {
final IWorkbenchWindow activeWorkbench = workbench.getActiveWorkbenchWindow();
- if (activeWorkbench != null) {
- final IWorkbenchPage activePage = activeWorkbench.getActivePage();
- if (activePage != null) {
- return activePage.getActivePart();
- }
+ if (null != activeWorkbench) {
+ return activeWorkbench.getActivePage();
}
}
+
+ return null;
+ }
+
+
+ /**
+ * @return
+ * The current {@link IWorkbenchPart} or <code>null</code> if not found
+ */
+ public static final IWorkbenchPart getCurrentActiveWorkbenchPart() {
+ final IWorkbenchPage activePage = getCurrentActiveWorkbenchPage();
+ if (null != activePage) {
+ return activePage.getActivePart();
+ }
+
return null;
}
/**
- *
* @return
- * the current IEditorPart or <code>null</code> if not found
+ * The current {@link IEditorPart} or <code>null</code> if not found
*/
public static final IEditorPart getCurrentActiveEditorPart() {
- final IWorkbench workbench = PlatformUI.getWorkbench();
- if (workbench != null) {
- final IWorkbenchWindow activeWorkbench = workbench.getActiveWorkbenchWindow();
- if (activeWorkbench != null) {
- final IWorkbenchPage activePage = activeWorkbench.getActivePage();
- if (activePage != null) {
- return activePage.getActiveEditor();
- }
- }
+ final IWorkbenchPage activePage = getCurrentActiveWorkbenchPage();
+ if (null != activePage) {
+ return activePage.getActiveEditor();
}
+
return null;
}
}

Back to the top