Bug 532105 - [Model Editor] undo/redo paste message could be better

Change-Id: I7a09c2d2100248d6a3c1ebd146560de095201af5
Signed-off-by: Olivier Prouvost <olivier.prouvost@opcoach.com>
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java
index 4e36e77..5a8ca3e 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java
@@ -113,6 +113,8 @@
 	public String ModelEditor_Move;
 	public String ModelEditor_Cut;
 	public String ModelEditor_CutObjects;
+	public String ModelEditor_Paste;
+	public String ModelEditor_PasteObjects;
 	public String ModelTooling_Common_RuntimeContributionInstance;
 	public String ModelTooling_Common_RuntimeWidgetTree;
 
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties
index 1e2c971..de985ce 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties
@@ -47,6 +47,8 @@
 ModelEditor_Move=Move
 ModelEditor_Cut=Cut
 ModelEditor_CutObjects=Cut Objects
+ModelEditor_Paste=Paste
+ModelEditor_PasteObjects=Paste Objects
 ModelTooling_Common_RuntimeContributionInstance=Contrib. Instance
 ModelTooling_Common_RuntimeWidgetTree=Widget Tree
 
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java
index 52d50f0..7b6191d 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java
@@ -155,6 +155,7 @@
 import org.eclipse.e4.ui.model.application.MApplication;
 import org.eclipse.e4.ui.model.application.MApplicationElement;
 import org.eclipse.e4.ui.model.application.commands.impl.CommandsPackageImpl;
+import org.eclipse.e4.ui.model.application.impl.ApplicationElementImpl;
 import org.eclipse.e4.ui.model.application.impl.ApplicationPackageImpl;
 import org.eclipse.e4.ui.model.application.ui.MContext;
 import org.eclipse.e4.ui.model.application.ui.MElementContainer;
@@ -1640,6 +1641,7 @@
 			}
 
 			CompoundCommand cc = new CompoundCommand();
+			Object pastedObject = null; // The single pasted object if single paste (for undo/redo message)
 			for (EObject eObject : toCopy) {
 				if (!ModelUtils.getTypeArgument(eObject.eClass(), feature.getEGenericType()).isInstance(eObject)) {
 					// the object to paste does not fit into the target feature
@@ -1657,6 +1659,7 @@
 					final Command cmd = AddCommand.create(getModelProvider().getEditingDomain(), container, feature,
 							el);
 					if (cmd.canExecute()) {
+						pastedObject = el;
 						cc.append(cmd);
 					}
 					return;
@@ -1664,6 +1667,7 @@
 
 				final Command cmd = AddCommand.create(getModelProvider().getEditingDomain(), container, feature,
 						eObject);
+				pastedObject = eObject;
 				if (cmd.canExecute()) {
 					cc.append(cmd);
 					if (isLiveModel()) {
@@ -1675,6 +1679,12 @@
 				}
 			}
 			if (!cc.isEmpty()) {
+				if (cc.getCommandList().size() == 1) {
+					cc.setLabel(messages.ModelEditor_Paste + " " + getObjectNameForCommand(pastedObject)); //$NON-NLS-1$
+				} else {
+					cc.setLabel(messages.ModelEditor_PasteObjects);
+				}
+
 				getModelProvider().getEditingDomain().getCommandStack().execute(cc);
 			}
 		}
@@ -1751,7 +1761,7 @@
 				EObject o = objectsToCut.iterator().next();
 				cmd = RemoveCommand.create(getModelProvider().getEditingDomain(), o.eContainer(),
 						o.eContainingFeature(), o);
-				((AbstractCommand) cmd).setLabel((messages.ModelEditor_Cut + " " + getObjectNameForCommand(o))); //$NON-NLS-1$
+				((AbstractCommand) cmd).setLabel(messages.ModelEditor_Cut + " " + getObjectNameForCommand(o)); //$NON-NLS-1$
 			} else {
 				// There are more than one object to remove -> Compound command.
 				CompoundCommand cc = new CompoundCommand();
@@ -2061,7 +2071,8 @@
 	 * @return a representative string for the object or 'Object' if nothing found
 	 */
 	private String getObjectNameForCommand(Object data) {
-		String clname = (data instanceof EObject) ? ((EObject) data).eClass().getName() : "Object"; //$NON-NLS-1$
+		String clname = (data instanceof ApplicationElementImpl) ? ((ApplicationElementImpl) data).eClass().getName()
+				: "Object"; //$NON-NLS-1$
 		String dname = (data instanceof MUILabel) ? ((MUILabel) data).getLabel() : ""; //$NON-NLS-1$
 		return clname + " " + dname; //$NON-NLS-1$
 	}