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/core
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/core')
-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
2 files changed, 68 insertions, 17 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;
}

Back to the top