Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2016-11-29 18:00:37 +0000
committerChristian W. Damus2016-11-29 18:38:31 +0000
commit0208593251db9c02690c622ec99d9a40a50704a4 (patch)
tree914d925860f2197540a485962d05d8b757291d85 /plugins/infra
parent0761e723d50aae39fb0f131440e55304c8d48967 (diff)
downloadorg.eclipse.papyrus-0208593251db9c02690c622ec99d9a40a50704a4.tar.gz
org.eclipse.papyrus-0208593251db9c02690c622ec99d9a40a50704a4.tar.xz
org.eclipse.papyrus-0208593251db9c02690c622ec99d9a40a50704a4.zip
Bug 508404: [Copy/Paste] Copy and paste does not use registered EFactory
Update the ICopierFactory API to require a resource set context and get the registered factory from it when available. https://bugs.eclipse.org/bugs/show_bug.cgi?id=508404 Change-Id: Iccca171716df658f310b2a8c7b7a319f991b2002
Diffstat (limited to 'plugins/infra')
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/clipboard/ICopierFactory.java16
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/clipboard/CopierFactory.java69
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultCopyCommand.java4
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramCopyCommand.java8
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramPasteCommand.java6
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultPasteCommand.java4
6 files changed, 81 insertions, 26 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/clipboard/ICopierFactory.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/clipboard/ICopierFactory.java
index 40b8a40e22f..5847d09e0df 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/clipboard/ICopierFactory.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/clipboard/ICopierFactory.java
@@ -16,8 +16,10 @@ package org.eclipse.papyrus.infra.core.clipboard;
import java.util.function.BiPredicate;
import java.util.function.Supplier;
+import org.eclipse.emf.ecore.EFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.EcoreUtil.Copier;
import org.eclipse.papyrus.infra.core.internal.clipboard.CopierFactory;
@@ -38,23 +40,29 @@ public interface ICopierFactory extends Supplier<EcoreUtil.Copier> {
* Obtains a copier factory suitable for most copy/paste operations.
* The result is configured from the extension point.
*
+ * @param resourceSet
+ * a resource set context in which to look for registered
+ * {@link EFactory} instances for creation of new objects
* @return a copier factory
*/
- static ICopierFactory getInstance() {
- return CopierFactory.DEFAULT;
+ static ICopierFactory getInstance(ResourceSet resourceSet) {
+ return getInstance(resourceSet, true);
}
/**
* Obtains a copier factory with the option of not using original references.
* The result is configured from the extension point.
*
+ * @param resourceSet
+ * a resource set context in which to look for registered
+ * {@link EFactory} instances for creation of new objects
* @param useOriginalReferences
* whether non-copied references should be used while copying
*
* @return a copier factory
*/
- static ICopierFactory getInstance(boolean useOriginalReferences) {
- return new CopierFactory(useOriginalReferences);
+ static ICopierFactory getInstance(ResourceSet resourceSet, boolean useOriginalReferences) {
+ return new CopierFactory(resourceSet, useOriginalReferences);
}
//
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/clipboard/CopierFactory.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/clipboard/CopierFactory.java
index 6921d99520e..fb71b2fb500 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/clipboard/CopierFactory.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/clipboard/CopierFactory.java
@@ -13,10 +13,12 @@
package org.eclipse.papyrus.infra.core.internal.clipboard;
-import java.util.function.BiPredicate;
-
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EFactory;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil.Copier;
import org.eclipse.papyrus.infra.core.clipboard.ICopierFactory;
@@ -25,24 +27,32 @@ import org.eclipse.papyrus.infra.core.clipboard.ICopierFactory;
*/
public class CopierFactory implements ICopierFactory {
+ private final ResourceSet resourceSet;
private final boolean useOriginalReferences;
/**
- * The default copier factory that provides the usual EMF
- * copying semantics, except with filtering of references
- * as directed by {@linkplain #registerReferenceFilter(BiPredicate) registered filters}.
+ * Initializes me with the resource set in which context I copy model elements.
+ * Copiers that I create will use original references.
+ *
+ * @param resourceSet
+ * my resource set context
*/
- public static CopierFactory DEFAULT = new CopierFactory(true);
+ public CopierFactory(ResourceSet resourceSet) {
+ this(resourceSet, true);
+ }
/**
- * Initializes me.
+ * Initializes me with the resource set in which context I copy model elements.
*
+ * @param resourceSet
+ * my resource set context
* @param useOriginalReferences
* whether non-copied references should be used while copying
*/
- public CopierFactory(boolean useOriginalReferences) {
+ public CopierFactory(ResourceSet resourceSet, boolean useOriginalReferences) {
super();
+ this.resourceSet = resourceSet;
this.useOriginalReferences = useOriginalReferences;
}
@@ -66,24 +76,57 @@ public class CopierFactory implements ICopierFactory {
private Copier createCopier(DefaultConfiguration configuration) {
return configuration.isEmpty()
? createBasicCopier()
- : new ConfiguredCopier(configuration);
+ : new ConfiguredCopier(configuration, getPackageRegistry());
}
private Copier createBasicCopier() {
- return new Copier(true, isUseOriginalReferences());
+ return new BasicCopier(true, isUseOriginalReferences(), getPackageRegistry());
+ }
+
+ private EPackage.Registry getPackageRegistry() {
+ return (resourceSet == null) ? EPackage.Registry.INSTANCE : resourceSet.getPackageRegistry();
}
//
// Nested types
//
- private static class ConfiguredCopier extends Copier {
+ private static class BasicCopier extends Copier {
+ private static final long serialVersionUID = 1L;
+
+ private final EPackage.Registry packageRegistry;
+
+ BasicCopier(boolean resolveReferences, boolean useOriginalReferences, EPackage.Registry registry) {
+ super(resolveReferences, useOriginalReferences);
+
+ this.packageRegistry = registry;
+ }
+
+ @Override
+ protected EObject createCopy(EObject eObject) {
+ EClass eClass = getTarget(eObject);
+ EFactory eFactory = getEFactory(eClass);
+ return eFactory.create(eClass);
+ }
+
+ EFactory getEFactory(EClass eClass) {
+ EFactory result = packageRegistry.getEFactory(eClass.getEPackage().getNsURI());
+
+ if (result == null) {
+ result = eClass.getEPackage().getEFactoryInstance();
+ }
+
+ return result;
+ }
+ }
+
+ private static class ConfiguredCopier extends BasicCopier {
private static final long serialVersionUID = 1L;
private final DefaultConfiguration configuration;
- ConfiguredCopier(DefaultConfiguration configuration) {
- super(configuration.isResolveReferences(), configuration.isUseOriginalReferences());
+ ConfiguredCopier(DefaultConfiguration configuration, EPackage.Registry registry) {
+ super(configuration.isResolveReferences(), configuration.isUseOriginalReferences(), registry);
this.configuration = configuration;
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultCopyCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultCopyCommand.java
index bf233a978e0..9b5e7af0396 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultCopyCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultCopyCommand.java
@@ -8,7 +8,7 @@
*
* Contributors:
* Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
- * Christian W. Damus - bug 502461
+ * Christian W. Damus - bugs 502461, 508404
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.commands;
@@ -50,7 +50,7 @@ public class DefaultCopyCommand extends AbstractOverrideableCommand implements N
super(domain);
objectsToPutInClipboard = new ArrayList<Object>();
boolean keepReferences = Activator.getInstance().getPreferenceStore().getBoolean(PastePreferencesPage.KEEP_EXTERNAL_REFERENCES);
- EcoreUtil.Copier copier = ICopierFactory.getInstance(keepReferences).get();
+ EcoreUtil.Copier copier = ICopierFactory.getInstance(domain.getResourceSet(), keepReferences).get();
copier.copyAll(pObjectsToPutInClipboard);
copier.copyReferences();
papyrusClipboard.addAllInternalCopyInClipboard(copier);
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramCopyCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramCopyCommand.java
index 9b174215559..db34d4a200f 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramCopyCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramCopyCommand.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
+ * Copyright (c) 2014, 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
@@ -8,6 +8,7 @@
*
* Contributors:
* Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 508404
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.commands;
@@ -25,6 +26,7 @@ import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.core.clipboard.ICopierFactory;
import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
import org.eclipse.papyrus.infra.gmfdiag.common.preferences.PastePreferencesPage;
@@ -54,7 +56,7 @@ public class DefaultDiagramCopyCommand extends AbstractOverrideableCommand imple
super(domain);
objectsToPutInClipboard = new ArrayList<Object>();
Boolean keepReferences = Activator.getInstance().getPreferenceStore().getBoolean(PastePreferencesPage.KEEP_EXTERNAL_REFERENCES);
- EcoreUtil.Copier copier = new EcoreUtil.Copier(Boolean.TRUE, keepReferences);
+ EcoreUtil.Copier copier = ICopierFactory.getInstance(domain.getResourceSet(), keepReferences).get();
List<EObject> objectToCopy = new ArrayList<EObject>();
if (pObjectsToPutInClipboard != null) {
@@ -78,7 +80,7 @@ public class DefaultDiagramCopyCommand extends AbstractOverrideableCommand imple
if (pObjectsToPutInClipboard != null && !pObjectsToPutInClipboard.isEmpty()) {
IGraphicalEditPart next = pObjectsToPutInClipboard.iterator().next();
Diagram diagram = next.getNotationView().getDiagram();
- if(diagram != null){
+ if (diagram != null) {
papyrusClipboard.setContainerType(diagram.getType());
}
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramPasteCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramPasteCommand.java
index fc687254f35..8f003d1b8f1 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramPasteCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramPasteCommand.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
+ * Copyright (c) 2014, 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
@@ -8,6 +8,7 @@
*
* Contributors:
* Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 508404
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.commands;
@@ -45,6 +46,7 @@ import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.LayoutConstraint;
import org.eclipse.gmf.runtime.notation.Shape;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.core.clipboard.ICopierFactory;
import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
@@ -92,7 +94,7 @@ public class DefaultDiagramPasteCommand extends AbstractTransactionalCommand {
this.container = (View) targetEditPart.getModel();
this.targetEditPart = targetEditPart;
- EcoreUtil.Copier copier = new EcoreUtil.Copier();
+ EcoreUtil.Copier copier = ICopierFactory.getInstance(editingDomain.getResourceSet()).get();
List<EObject> rootElementInClipboard = EcoreUtil.filterDescendants(filterEObject(papyrusClipboard));
copier.copyAll(rootElementInClipboard);
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultPasteCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultPasteCommand.java
index 81f10822c27..e450eb2de3f 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultPasteCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultPasteCommand.java
@@ -8,7 +8,7 @@
*
* Contributors:
* Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
- * Christian W. Damus - bug 502461
+ * Christian W. Damus - bugs 502461, 508404
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.commands;
@@ -71,7 +71,7 @@ public class DefaultPasteCommand extends AbstractCommand {
List<EObject> rootElementToPaste = EcoreUtil.filterDescendants(eobjectsTopaste);
// Copy all eObjects (inspired from PasteFromClipboardCommand)
- EcoreUtil.Copier copier = ICopierFactory.getInstance().get();
+ EcoreUtil.Copier copier = ICopierFactory.getInstance(domain.getResourceSet()).get();
copier.copyAll(rootElementToPaste);
copier.copyReferences();
Map<EObject, EObject> duplicatedObjects = new HashMap<EObject, EObject>();

Back to the top