summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Maggi2014-03-10 09:05:55 (EDT)
committerVincent Lorenzo2014-03-18 10:03:30 (EDT)
commitcaa1146af753a46f2aadd6646a08bb2afc20af11 (patch)
tree84e27e4b0b25b181b191a398723b11f34d69f339
parentd61f621029aad0a5a196e5fe760ce98109d8dedb (diff)
downloadorg.eclipse.papyrus-caa1146af753a46f2aadd6646a08bb2afc20af11.zip
org.eclipse.papyrus-caa1146af753a46f2aadd6646a08bb2afc20af11.tar.gz
org.eclipse.papyrus-caa1146af753a46f2aadd6646a08bb2afc20af11.tar.bz2
Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
Conflicts: plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml8
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml5
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/RenamePasteStrategy.java207
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/StereotypePasteStrategy.java165
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/NamedElementUtil.java16
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/RenameElementCommand.java48
6 files changed, 371 insertions, 78 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml
index a47ef96..f034500 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml
@@ -62,13 +62,7 @@
class="org.eclipse.papyrus.infra.gmfdiag.common.preferences.PastePreferencesPage"
id="org.eclipse.papyrus.infra.gmfdiag.paste.preferences"
name="Paste">
- </page>
- <page
- category="org.eclipse.papyrus.infra.core.sasheditor.preferences.generalcategory"
- class="org.eclipse.papyrus.infra.gmfdiag.common.preferences.CopyPreferencesPage"
- id="org.eclipse.papyrus.infra.gmfdiag.paste.preferences"
- name="Copy">
- </page>
+ </page>
</extension>
<extension
point="org.eclipse.core.runtime.preferences">
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml
index ade614c..dd1c21e 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml
@@ -598,7 +598,10 @@
strategy="org.eclipse.papyrus.uml.diagram.common.strategy.paste.StereotypePasteStrategy">
</strategy>
<strategy
- strategy="org.eclipse.papyrus.uml.diagram.common.strategy.paste.ImportResourcePasteStrategy">
+ strategy="org.eclipse.papyrus.uml.diagram.common.strategy.paste.DefaultPasteStrategy">
+ </strategy>
+ <strategy
+ strategy="org.eclipse.papyrus.uml.diagram.common.strategy.paste.RenamePasteStrategy">
</strategy>
</extension>
<extension
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/RenamePasteStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/RenamePasteStrategy.java
new file mode 100644
index 0000000..74f77e8
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/RenamePasteStrategy.java
@@ -0,0 +1,207 @@
+/*****************************************************************************
+ * 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:
+ * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.strategy.paste;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.commands.wrappers.EMFtoGEFCommandWrapper;
+import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
+import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.papyrus.uml.tools.commands.RenameElementCommand;
+import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.uml2.uml.NamedElement;
+
+/**
+ * Offer a strategy for copying stereotypes.
+ */
+public class RenamePasteStrategy implements IPasteStrategy {
+
+ /** The instance. */
+ private static IPasteStrategy instance = new RenamePasteStrategy();
+
+ /**
+ * Gets the single instance of StereotypePasteStrategy.
+ *
+ * @return single instance of StereotypePasteStrategy
+ */
+ public static IPasteStrategy getInstance() {
+ return instance;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getLabel()
+ */
+ public String getLabel() {
+ return "Rename Strategy"; //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getID()
+ */
+ public String getID() {
+ return Activator.ID + ".RenameStrategy"; //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getDescription()
+ */
+ public String getDescription() {
+ return "Rename elements"; //$NON-NLS-1$
+ }
+
+ /**
+ * Gets the category id.
+ *
+ * @return the category id
+ */
+ public String getCategoryID() {
+ return "org.eclipse.papyrus.strategy.paste"; //$NON-NLS-1$
+ }
+
+ /**
+ * Gets the category label.
+ *
+ * @return the category label
+ */
+ public String getCategoryLabel() {
+ return "Paste all copied elements"; //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getImage()
+ */
+ @Deprecated
+ public Image getImage() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getPriority()
+ */
+ @Deprecated
+ public int getPriority() {
+ return 1;
+ }
+
+ /**
+ * Sets the options.
+ *
+ * @param options
+ * the options
+ */
+ public void setOptions(Map<String, Object> options) {
+ //Nothing
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getSemanticCommand(org.eclipse.emf.edit.domain.EditingDomain,
+ * org.eclipse.emf.ecore.EObject, org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard)
+ */
+ @Override
+ public org.eclipse.emf.common.command.Command getSemanticCommand(EditingDomain domain, EObject targetOwner, PapyrusClipboard<Object> papyrusClipboard) {
+ CompoundCommand compoundCommand = new CompoundCommand("Rename root paste elements"); //$NON-NLS-1$
+ for(Iterator<Object> iterator = papyrusClipboard.iterator(); iterator.hasNext();) {
+ Object object = (Object)iterator.next();
+ // get target Element
+ EObject target = papyrusClipboard.getTragetCopyFromInternalClipboardCopy(object);
+ if(target != null && target instanceof NamedElement) {
+ NamedElement namedElement = (NamedElement)target;
+ if(namedElement.getName() != null) {
+ String defaultCopyNameWithIncrement = NamedElementUtil.getDefaultCopyNameWithIncrement(namedElement, targetOwner.eContents());
+ RenameElementCommand renameElementCommand = new RenameElementCommand((TransactionalEditingDomain)domain, namedElement, defaultCopyNameWithIncrement);
+ compoundCommand.append(renameElementCommand);
+ }
+ }
+ }
+ // An empty can't be executed
+ if(compoundCommand.getCommandList().isEmpty()) {
+ return null;
+ }
+ return compoundCommand;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getGraphicalCommand(org.eclipse.emf.edit.domain.EditingDomain,
+ * org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart, org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard)
+ */
+ @Override
+ public Command getGraphicalCommand(EditingDomain domain, org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart targetEditPart, PapyrusClipboard<Object> papyrusClipboard) {
+ org.eclipse.gef.commands.CompoundCommand compoundCommand = new org.eclipse.gef.commands.CompoundCommand("Stereotype Semantic And Graphical paste"); //$NON-NLS-1$
+ View view = (View)targetEditPart.getModel();
+ EObject modelTargetOwner = (EObject)view.getElement();
+ for(Iterator<Object> iterator = papyrusClipboard.iterator(); iterator.hasNext();) {
+ Object object = (Object)iterator.next();
+ // get target Element
+ EObject target = papyrusClipboard.getTragetCopyFromInternalClipboardCopy(object);
+ if(target != null && target instanceof NamedElement) {
+ NamedElement namedElement = (NamedElement)target;
+ if(namedElement.getName() != null) {
+ String defaultCopyNameWithIncrement = NamedElementUtil.getDefaultCopyNameWithIncrement(namedElement, modelTargetOwner.eContents());
+ RenameElementCommand renameElementCommand = new RenameElementCommand((TransactionalEditingDomain)domain, (NamedElement)target, defaultCopyNameWithIncrement);
+ EMFtoGEFCommandWrapper emFtoGEFCommandWrapper = new EMFtoGEFCommandWrapper(renameElementCommand);
+ compoundCommand.add(emFtoGEFCommandWrapper);
+ }
+ }
+ }
+
+ if(compoundCommand.size() == 0) {// TODO : use unwrap if no use of UnexecutableCommand.INSTANCE
+ return null;
+ }
+ return compoundCommand;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#dependsOn()
+ */
+ @Override
+ public IPasteStrategy dependsOn() {
+ return DefaultPasteStrategy.getInstance();
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#prepare(org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard)
+ */
+ @Override
+ public void prepare(PapyrusClipboard<Object> papyrusClipboard) {
+ // Nothing to prepare since the renaming depends of the pasting context
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/StereotypePasteStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/StereotypePasteStrategy.java
index 814a661..e47dd57 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/StereotypePasteStrategy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/StereotypePasteStrategy.java
@@ -23,8 +23,6 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.commands.wrappers.EMFtoGEFCommandWrapper;
@@ -144,6 +142,12 @@ public class StereotypePasteStrategy implements IPasteStrategy {
@Override
public org.eclipse.emf.common.command.Command getSemanticCommand(EditingDomain domain, EObject targetOwner, PapyrusClipboard<Object> papyrusClipboard) {
CompoundCommand compoundCommand = new CompoundCommand("Copy all stereotypes"); //$NON-NLS-1$
+
+ Map<Profile,List<ApplyStereotypeCommand>> missingProfiles = new HashMap<Profile,List<ApplyStereotypeCommand>>();
+
+ Package targetPackage = ((Element)targetOwner).getNearestPackage();
+
+ // 1. init all ApplyStereotypeCommand
for(Iterator<Object> iterator = papyrusClipboard.iterator(); iterator.hasNext();) {
Object object = (Object)iterator.next();
// get target Element
@@ -155,19 +159,47 @@ public class StereotypePasteStrategy implements IPasteStrategy {
if(additionnalData instanceof StereotypeClipboard) {
StereotypeClipboard stereotypeClipboard = (StereotypeClipboard)additionnalData;
Collection<Stereotype> stereotypes = stereotypeClipboard.getStereotypes();
- Collection<Stereotype> stereotypeListInTargetContext = new ArrayList<Stereotype>();
+// Collection<Stereotype> stereotypeListInTargetContext = new ArrayList<Stereotype>();
for(Stereotype stereotype : stereotypes) {
// reload the stereotype in the new Contex-ResourceSet (Required because in org.eclipse.uml2.uml.internal.operations.PackageOperations
// L960 in getProfileApplication the test is using == instead of equals)
Stereotype stereotypeInTargetContext = EMFHelper.reloadIntoContext(stereotype, targetOwner);
- stereotypeListInTargetContext.add(stereotypeInTargetContext);
+
+ Profile profile = stereotypeInTargetContext.getProfile();
+ ApplyStereotypeCommand applyStereotypeCommand = new ApplyStereotypeCommand((Element)target, stereotypeInTargetContext, (TransactionalEditingDomain)domain);
+ if (isProfileAppliedRecursive(targetPackage, profile)){
+ compoundCommand.append(applyStereotypeCommand);
+ } else { // Profile is missing
+ Activator.getDefault().logWarning(profile.getName()+" is missing", null);
+ List<ApplyStereotypeCommand> list = missingProfiles.get(profile);
+ if (list!= null && !list.isEmpty()){
+ list.add(applyStereotypeCommand);
+ } else {
+ list = new ArrayList<ApplyStereotypeCommand>();
+ missingProfiles.put(profile, list);
+ }
+ }
+
+// stereotypeListInTargetContext.add(stereotypeInTargetContext);
}
// append command to apply stereotype
- ApplyStereotypeCommand applyStereotypeCommand = new ApplyStereotypeCommand((Element)target, stereotypeListInTargetContext, (TransactionalEditingDomain)domain);
- compoundCommand.append(applyStereotypeCommand);// TODO : command should be append only after verification of profiles
+// ApplyStereotypeCommand applyStereotypeCommand = new ApplyStereotypeCommand((Element)target, stereotypeListInTargetContext, (TransactionalEditingDomain)domain);
+// applyStereotypeCommandList.add(applyStereotypeCommand);
}
}
}
+
+ // TODO: 2. user choices (Apply profiles, data...)
+
+ // first draft remove all unapplicable commd
+
+
+
+
+ //3. construct compoundCommand
+
+
+
// An empty can't be executed
if(compoundCommand.getCommandList().isEmpty()) {
return null;
@@ -186,6 +218,7 @@ public class StereotypePasteStrategy implements IPasteStrategy {
org.eclipse.gef.commands.CompoundCommand compoundCommand = new org.eclipse.gef.commands.CompoundCommand("Stereotype Semantic And Graphical paste"); //$NON-NLS-1$
View view = (View)targetEditPart.getModel();
EObject modelTargetOwner = (EObject)view.getElement();
+ Package targetPackage = ((Element)modelTargetOwner).getNearestPackage();
// apply stereotypes
List<ApplyStereotypeCommand> applyStereotypeCommandList = new ArrayList<ApplyStereotypeCommand>();
for(Iterator<Object> iterator = papyrusClipboard.iterator(); iterator.hasNext();) {
@@ -204,9 +237,15 @@ public class StereotypePasteStrategy implements IPasteStrategy {
// L960 in getProfileApplication the test is using == instead of equals)
Stereotype stereotypeInTargetContext = EMFHelper.reloadIntoContext(stereotype, modelTargetOwner);
ApplyStereotypeCommand applyStereotypeCommand = new ApplyStereotypeCommand((Element)target, stereotypeInTargetContext, (TransactionalEditingDomain)domain);
- EMFtoGEFCommandWrapper emFtoGEFCommandWrapper = new EMFtoGEFCommandWrapper(applyStereotypeCommand);
- compoundCommand.add(emFtoGEFCommandWrapper);
-// applyStereotypeCommandList.add(applyStereotypeCommand);
+
+ Profile profile = stereotypeInTargetContext.getProfile();
+ if (isProfileAppliedRecursive(targetPackage, profile)){
+ EMFtoGEFCommandWrapper emFtoGEFCommandWrapper = new EMFtoGEFCommandWrapper(applyStereotypeCommand);
+ compoundCommand.add(emFtoGEFCommandWrapper);
+ } else { // Profile is missing
+ Activator.getDefault().logWarning(profile.getName()+" is missing", null);
+ }
+ // applyStereotypeCommandList.add(applyStereotypeCommand);
}
}
@@ -214,38 +253,38 @@ public class StereotypePasteStrategy implements IPasteStrategy {
}
// TODO : test profile application
-// List<Profile> missingProfiles = new ArrayList<Profile>();
-// if(modelTargetOwner != null && modelTargetOwner instanceof Element) {
-// Package nearestPackage = ((Element)modelTargetOwner).getNearestPackage();
-//
-// for(ApplyStereotypeCommand applyStereotypeCommand : applyStereotypeCommandList) {
-//
-// Collection<Stereotype> stereotypes = applyStereotypeCommand.getStereotypes();
-// for(Stereotype stereotype : stereotypes) {
-// Profile profile = stereotype.getProfile();
-// boolean profileApplied = isProfileAppliedRecursive(nearestPackage, profile);
-// if(!profileApplied) {
-// missingProfiles.add(profile);
-// Map<EditPart, Set<EObject>> availableLinks = new HashMap<EditPart, Set<EObject>>();
-// Collection<EObject> initialSelection = new ArrayList<EObject>();
-// Map<EObject, LinkEndsMapper> linkMapping = new HashMap<EObject, LinkEndsMapper>();
-// Collection<EditPart> selectedEditPart = new ArrayList<EditPart>();
-// // ICommand openDialogCommand = getOpenDialogCommand((TransactionalEditingDomain)domain, selectedEditPart, availableLinks, initialSelection, linkMapping);
-// //
-// // try {
-// // openDialogCommand.execute(new NullProgressMonitor(), null);
-// // } catch (ExecutionException e) {
-// // // TODO Auto-generated catch block
-// // e.printStackTrace();
-// // }
-// // domain.getCommandStack().execute(openDialogCommand);
-// } else {
-// EMFtoGEFCommandWrapper emFtoGEFCommandWrapper = new EMFtoGEFCommandWrapper(applyStereotypeCommand);
-//// compoundCommand.add(emFtoGEFCommandWrapper);
-// }
-// }
-// }
-// }
+ // List<Profile> missingProfiles = new ArrayList<Profile>();
+ // if(modelTargetOwner != null && modelTargetOwner instanceof Element) {
+ // Package nearestPackage = ((Element)modelTargetOwner).getNearestPackage();
+ //
+ // for(ApplyStereotypeCommand applyStereotypeCommand : applyStereotypeCommandList) {
+ //
+ // Collection<Stereotype> stereotypes = applyStereotypeCommand.getStereotypes();
+ // for(Stereotype stereotype : stereotypes) {
+ // Profile profile = stereotype.getProfile();
+ // boolean profileApplied = isProfileAppliedRecursive(nearestPackage, profile);
+ // if(!profileApplied) {
+ // missingProfiles.add(profile);
+ // Map<EditPart, Set<EObject>> availableLinks = new HashMap<EditPart, Set<EObject>>();
+ // Collection<EObject> initialSelection = new ArrayList<EObject>();
+ // Map<EObject, LinkEndsMapper> linkMapping = new HashMap<EObject, LinkEndsMapper>();
+ // Collection<EditPart> selectedEditPart = new ArrayList<EditPart>();
+ // // ICommand openDialogCommand = getOpenDialogCommand((TransactionalEditingDomain)domain, selectedEditPart, availableLinks, initialSelection, linkMapping);
+ // //
+ // // try {
+ // // openDialogCommand.execute(new NullProgressMonitor(), null);
+ // // } catch (ExecutionException e) {
+ // // // TODO Auto-generated catch block
+ // // e.printStackTrace();
+ // // }
+ // // domain.getCommandStack().execute(openDialogCommand);
+ // } else {
+ // EMFtoGEFCommandWrapper emFtoGEFCommandWrapper = new EMFtoGEFCommandWrapper(applyStereotypeCommand);
+ //// compoundCommand.add(emFtoGEFCommandWrapper);
+ // }
+ // }
+ // }
+ // }
if(compoundCommand.size() == 0) {// TODO : use unwrap if no use of UnexecutableCommand.INSTANCE
return null;
}
@@ -321,28 +360,28 @@ public class StereotypePasteStrategy implements IPasteStrategy {
}
-// protected ICommand getOpenDialogCommand(final TransactionalEditingDomain domain, final Collection<EditPart> selectedEditPart, final Map<EditPart, Set<EObject>> availableLinks, final Collection<EObject> initialSelection, final Map<EObject, LinkEndsMapper> linkMapping) {
-// final ICommand cmd = new AbstractTransactionalCommand(domain, "Open Show/HideDialogCommand", null) {//$NON-NLS-1$
-//
-// @Override
-// protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
-// final ShowHideRelatedLinkSelectionDialog dialog = new ShowHideRelatedLinkSelectionDialog(Display.getDefault().getActiveShell(), new UMLLabelProvider(), new AbstractShowHideRelatedLinkEditPolicy.LinkContentProvider(availableLinks), availableLinks, linkMapping);
-// dialog.setTitle("Show/Hide Links");//$NON-NLS-1$
-// dialog.setMessage("Choose the links to show.");//$NON-NLS-1$
-// dialog.setInput(selectedEditPart);
-// dialog.setInitialSelection(initialSelection);
-// dialog.setExpandedElements(selectedEditPart.toArray());
-// dialog.setContainerMode(true);
-// int status = dialog.open();
-// if(status == Window.CANCEL) {
-// return CommandResult.newCancelledCommandResult();
-// }
-// return CommandResult.newOKCommandResult(Arrays.asList(dialog.getResult()));
-// }
-// };
-//
-// return cmd;
-// }
+ // protected ICommand getOpenDialogCommand(final TransactionalEditingDomain domain, final Collection<EditPart> selectedEditPart, final Map<EditPart, Set<EObject>> availableLinks, final Collection<EObject> initialSelection, final Map<EObject, LinkEndsMapper> linkMapping) {
+ // final ICommand cmd = new AbstractTransactionalCommand(domain, "Open Show/HideDialogCommand", null) {//$NON-NLS-1$
+ //
+ // @Override
+ // protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ // final ShowHideRelatedLinkSelectionDialog dialog = new ShowHideRelatedLinkSelectionDialog(Display.getDefault().getActiveShell(), new UMLLabelProvider(), new AbstractShowHideRelatedLinkEditPolicy.LinkContentProvider(availableLinks), availableLinks, linkMapping);
+ // dialog.setTitle("Show/Hide Links");//$NON-NLS-1$
+ // dialog.setMessage("Choose the links to show.");//$NON-NLS-1$
+ // dialog.setInput(selectedEditPart);
+ // dialog.setInitialSelection(initialSelection);
+ // dialog.setExpandedElements(selectedEditPart.toArray());
+ // dialog.setContainerMode(true);
+ // int status = dialog.open();
+ // if(status == Window.CANCEL) {
+ // return CommandResult.newCancelledCommandResult();
+ // }
+ // return CommandResult.newOKCommandResult(Arrays.asList(dialog.getResult()));
+ // }
+ // };
+ //
+ // return cmd;
+ // }
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/NamedElementUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/NamedElementUtil.java
index b7f45fa..1befb89 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/NamedElementUtil.java
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/NamedElementUtil.java
@@ -87,14 +87,16 @@ public class NamedElementUtil {
@SuppressWarnings("rawtypes")
public static String getDefaultCopyNameWithIncrement(NamedElement namedElement, Collection contents) {
String rootName = namedElement.getName();
- for(Object o : contents) {
- if(o instanceof EObject) {
- String name = EMFCoreUtil.getName((EObject)o);
- if (rootName.equals(name)){
- String newName = NLS.bind(COPY_OF + "_{0}_", rootName);
- return NamedElementUtil.getDefaultNameWithIncrementFromBase(newName, contents);
+ if (rootName != null){
+ for(Object o : contents) {
+ if(o instanceof EObject) {
+ String name = EMFCoreUtil.getName((EObject)o);
+ if (rootName.equals(name)){
+ String newName = NLS.bind(COPY_OF + "_{0}_", rootName);
+ return NamedElementUtil.getDefaultNameWithIncrementFromBase(newName, contents);
+ }
}
- }
+ }
}
return rootName;
}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/RenameElementCommand.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/RenameElementCommand.java
new file mode 100644
index 0000000..d02c8df
--- /dev/null
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/RenameElementCommand.java
@@ -0,0 +1,48 @@
+/*****************************************************************************
+ * 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:
+ * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.tools.commands;
+
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.uml2.uml.NamedElement;
+
+/**
+ * A Command to apply a rename on a UML Element
+ */
+public class RenameElementCommand extends RecordingCommand {
+
+ private NamedElement element;
+
+ private String name;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param namedElement
+ * The UML Element w
+ * @param stereotypes
+ * The stereotypes to apply
+ */
+ public RenameElementCommand(TransactionalEditingDomain domain, NamedElement namedElement, String name) {
+ super(domain);
+ this.element = namedElement;
+ this.name = name;
+ }
+
+
+ @Override
+ protected void doExecute() {
+ element.setName(name);
+ }
+
+}