diff options
author | Christian W. Damus | 2016-09-28 15:40:12 +0000 |
---|---|---|
committer | Christian W. Damus | 2016-10-28 21:16:38 +0000 |
commit | 0d128b68b25bf9c06d7c474bd91445871c21486b (patch) | |
tree | bfb946d4fe6aa43024c1d1ce91e6d690dd805b21 /plugins/infra | |
parent | d074f58115cca11630b8534836fbef3fc9a8d972 (diff) | |
download | org.eclipse.papyrus-0d128b68b25bf9c06d7c474bd91445871c21486b.tar.gz org.eclipse.papyrus-0d128b68b25bf9c06d7c474bd91445871c21486b.tar.xz org.eclipse.papyrus-0d128b68b25bf9c06d7c474bd91445871c21486b.zip |
Bug 502461: [Copy/Paste] Pasting UML-RT protocol container corrupts the model
https://bugs.eclipse.org/bugs/show_bug.cgi?id=502461
Never copy the Dependency::client reference property of an
InterfaceRealization in copy/paste operations.
Use the Element Types Framework to set the name of a pasted element
when resolving name clashes, to allow for extensible editing
behaviour of DSMLs such as UML-RT (for protocol containers).
Change-Id: Iddfc4f7f4d5a9a412317f7fbe5db6a6ac7563be7
Diffstat (limited to 'plugins/infra')
11 files changed, 685 insertions, 6 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF b/plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF index c8635206ed3..be0b3be7e36 100644 --- a/plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF @@ -3,6 +3,7 @@ Export-Package: org.eclipse.papyrus.infra.core, org.eclipse.papyrus.infra.core.clipboard, org.eclipse.papyrus.infra.core.editor, org.eclipse.papyrus.infra.core.extension, + org.eclipse.papyrus.infra.core.internal.clipboard;x-internal:=true, org.eclipse.papyrus.infra.core.internal.expressions;x-internal:=true, org.eclipse.papyrus.infra.core.internal.language;x-friends:="org.eclipse.papyrus.infra.emf", org.eclipse.papyrus.infra.core.internal.sashmodel;x-internal:=true, diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/plugin.xml b/plugins/infra/core/org.eclipse.papyrus.infra.core/plugin.xml index 5002ac0231a..91659babdf6 100644 --- a/plugins/infra/core/org.eclipse.papyrus.infra.core/plugin.xml +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/plugin.xml @@ -7,6 +7,7 @@ <extension-point id="transactionalEditingDomainProvider" name="transactionalEditingDomainProvider" schema="schema/transactionalEditingDomainProvider.exsd"/> <extension-point id="sashModelProvider" name="Sash Model Providers" schema="schema/sashModelProvider.exsd"/> <extension-point id="language" name="Modeling Language" schema="schema/language.exsd"/> + <extension-point id="copier" name="Clipboard Copier Configuration" schema="schema/copier.exsd"/> <extension point="org.eclipse.papyrus.infra.core.model"> diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/schema/copier.exsd b/plugins/infra/core/org.eclipse.papyrus.infra.core/schema/copier.exsd new file mode 100644 index 00000000000..4077183f11e --- /dev/null +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/schema/copier.exsd @@ -0,0 +1,124 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- Schema file written by PDE --> +<schema targetNamespace="org.eclipse.papyrus.infra.core" xmlns="http://www.w3.org/2001/XMLSchema"> +<annotation> + <appInfo> + <meta.schema plugin="org.eclipse.papyrus.infra.core" id="copier" name="Clipboard Copier Configuration"/> + </appInfo> + <documentation> + Registers configuration parameters for the EMF copiers use by the clipboard +infrastructure in Papyrus for copy/paste operations. + </documentation> + </annotation> + + <element name="extension"> + <annotation> + <appInfo> + <meta.element /> + </appInfo> + </annotation> + <complexType> + <sequence> + <element ref="factoryConfiguration" minOccurs="1" maxOccurs="unbounded"/> + </sequence> + <attribute name="point" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="id" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="name" type="string"> + <annotation> + <documentation> + + </documentation> + <appInfo> + <meta.attribute translatable="true"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <element name="factoryConfiguration"> + <annotation> + <documentation> + Configuration parameters for the copier factory. + </documentation> + </annotation> + <complexType> + <choice minOccurs="0" maxOccurs="unbounded"> + <element ref="referenceFilter"/> + </choice> + <attribute name="configurator" type="string"> + <annotation> + <documentation> + Identifies a class implementing the <tt>ICopierFactory.Configurator</tt> protocol for copier factory configuration. If omitted, then a default configurator is used that reads configuration parameters from nested elements. In that case, at least some nested content is required. + </documentation> + <appInfo> + <meta.attribute kind="java" basedOn=":org.eclipse.papyrus.infra.core.clipboard.ICopierFactory$Configurator"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <element name="referenceFilter"> + <annotation> + <documentation> + Declares a reference filter configuration rule. Used with the implicit configurator. + </documentation> + </annotation> + <complexType> + <attribute name="referenceURI" type="string" use="required"> + <annotation> + <documentation> + Ecore URI of the reference to filter in copy operations. + </documentation> + </annotation> + </attribute> + <attribute name="ownerTypeURI" type="string"> + <annotation> + <documentation> + Ecore URI of the EClass of reference owner (object) to which to apply the reference filter. If omitted, then the reference is filtered for all instance of its defining EClass. + </documentation> + </annotation> + </attribute> + </complexType> + </element> + + <annotation> + <appInfo> + <meta.section type="since"/> + </appInfo> + <documentation> + Papyrus Oxygen + </documentation> + </annotation> + + + + + <annotation> + <appInfo> + <meta.section type="copyright"/> + </appInfo> + <documentation> + Copyright (c) 2016 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 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/epl-v10.html + </documentation> + </annotation> + +</schema> 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 new file mode 100644 index 00000000000..40b8a40e22f --- /dev/null +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/clipboard/ICopierFactory.java @@ -0,0 +1,122 @@ +/***************************************************************************** + * Copyright (c) 2016 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 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Christian W. Damus - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.infra.core.clipboard; + +import java.util.function.BiPredicate; +import java.util.function.Supplier; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.ecore.util.EcoreUtil.Copier; +import org.eclipse.papyrus.infra.core.internal.clipboard.CopierFactory; + +/** + * An extensible factory for EMF {@link Copier}s used for copy/paste + * operations in Papyrus. Extensions are registered on the + * {@code org.eclipse.papyrus.infra.core.copier} extension point. + * + * @since 2.2 + * + * @see EcoreUtil.Copier + */ +@FunctionalInterface +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. + * + * @return a copier factory + */ + static ICopierFactory getInstance() { + return CopierFactory.DEFAULT; + } + + /** + * Obtains a copier factory with the option of not using original references. + * The result is configured from the extension point. + * + * @param useOriginalReferences + * whether non-copied references should be used while copying + * + * @return a copier factory + */ + static ICopierFactory getInstance(boolean useOriginalReferences) { + return new CopierFactory(useOriginalReferences); + } + + // + // Nested types + // + + /** + * Configuration protocol for the {@linkplain ICopierFactory copier factory} + * that {@link Configurator} extensions use to tweak the behaviour of + * the copiers that it creates. + * + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + * + * @since 2.2 + */ + interface Configuration { + /** + * Queries whether the copier to be configured resolves references + * in its copying. {@link Configurator}s may need to know this to determine + * how to configure it. + * + * @return whether the copier resolves references + */ + boolean isResolveReferences(); + + /** + * Queries whether the copier to be configured uses original references + * in its copying. {@link Configurator}s may need to know this to determine + * how to configure it. + * + * @return whether the copier uses original references + */ + boolean isUseOriginalReferences(); + + /** + * Adds a filter matching references that should not be copied for + * select objects. + * + * @param filter + * a filter that matches some reference for some object + * that should not have that reference copied + */ + void filterReferences(BiPredicate<? super EReference, ? super EObject> filter); + } + + /** + * Extension protocol for the {@linkplain ICopierFactory copier factory} + * that allows plug-ins to customize the behaviour of the copiers that it creates. + * Instances are registered on the {@code org.eclipse.papyrus.infra.core.copier} + * extension point. + * + * @since 2.2 + */ + @FunctionalInterface + interface Configurator { + /** + * Installs configurations for the copier factory. + * + * @param copierConfiguration + * the configuration to update + */ + void configureCopier(Configuration copierConfiguration); + } +} diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/clipboard/CopierConfiguratorRegistry.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/clipboard/CopierConfiguratorRegistry.java new file mode 100644 index 00000000000..4c73988f4cd --- /dev/null +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/clipboard/CopierConfiguratorRegistry.java @@ -0,0 +1,155 @@ +/***************************************************************************** + * Copyright (c) 2016 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 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Christian W. Damus - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.infra.core.internal.clipboard; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Optional; +import java.util.function.Predicate; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; +import org.eclipse.emf.common.util.WrappedException; +import org.eclipse.emf.ecore.plugin.RegistryReader; +import org.eclipse.papyrus.infra.core.Activator; +import org.eclipse.papyrus.infra.core.clipboard.ICopierFactory; +import org.eclipse.papyrus.infra.core.clipboard.ICopierFactory.Configuration; + +/** + * Registry of configurator extensions on the + * {@code org.eclipse.papyrus.infra.core.copier} point. + */ +class CopierConfiguratorRegistry implements ICopierFactory.Configurator { + + private static final String EXT_PT = "copier"; //$NON-NLS-1$ + + static CopierConfiguratorRegistry INSTANCE = new CopierConfiguratorRegistry(); + + private final Collection<ICopierFactory.Configurator> configurators; + + private CopierConfiguratorRegistry() { + super(); + + configurators = new Reader(Platform.getExtensionRegistry(), Activator.PLUGIN_ID, EXT_PT).load(); + } + + @Override + public void configureCopier(ICopierFactory.Configuration copierConfiguration) { + configurators.forEach(c -> c.configureCopier(copierConfiguration)); + } + + // + // Nested types + // + + private static class Reader extends RegistryReader { + + private static final String FACTORY_CONFIGURATION = "factoryConfiguration"; //$NON-NLS-1$ + private static final String CONFIGURATOR = "configurator"; //$NON-NLS-1$ + + private Collection<ICopierFactory.Configurator> configurators; + private ICopierFactory.Configurator currentConfigurator; + + // Not really a predicate, but it is a boolean-valued function + private Predicate<IConfigurationElement> configurationReader; + + Reader(IExtensionRegistry pluginRegistry, String pluginID, String extensionPointID) { + super(pluginRegistry, pluginID, extensionPointID); + } + + Collection<ICopierFactory.Configurator> load() { + Collection<ICopierFactory.Configurator> result = new ArrayList<>(); + configurators = result; + + try { + readRegistry(); + } finally { + configurators = null; + } + + return result; + } + + @Override + protected boolean readElement(IConfigurationElement element) { + boolean result = false; + + if (FACTORY_CONFIGURATION.equals(element.getName())) { + result = true; + + if (element.getAttribute(CONFIGURATOR) != null) { + // Custom configurator + currentConfigurator = new ConfiguratorDescriptor(element); + configurationReader = null; + } else { + // Default configurator + DefaultConfigurator configurator = new DefaultConfigurator(); + currentConfigurator = configurator; + configurationReader = configurator::readElement; + } + + configurators.add(currentConfigurator); + } else if (currentConfigurator != null) { + if (configurationReader != null) { + result = configurationReader.test(element); + } else { + // Accept anything (who knows what a custom configurator may need?) + result = true; + } + } + + return result; + } + + // + // Nested types + // + + private class ConfiguratorDescriptor extends PluginClassDescriptor implements ICopierFactory.Configurator { + + private Optional<ICopierFactory.Configurator> resolved; + + ConfiguratorDescriptor(IConfigurationElement element) { + super(element, CONFIGURATOR); + } + + @Override + public void configureCopier(Configuration copierConfiguration) { + resolve().ifPresent(c -> c.configureCopier(copierConfiguration)); + } + + Optional<ICopierFactory.Configurator> resolve() { + if (resolved == null) { + ICopierFactory.Configurator delegate = null; + + try { + delegate = (ICopierFactory.Configurator) createInstance(); + } catch (ClassCastException e) { + Activator.log.warn("Not an ICopierFactory.Configurator extension in " + element.getContributor().getName()); //$NON-NLS-1$ + } catch (WrappedException e) { + Activator.log.log(((CoreException) e.exception()).getStatus()); + } catch (Exception e) { + Activator.log.error("Unhandled exception creating copier factory configurator extension in " + element.getContributor().getName(), e); //$NON-NLS-1$ + } + + resolved = Optional.ofNullable(delegate); + } + + return resolved; + } + } + } +} 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 new file mode 100644 index 00000000000..6921d99520e --- /dev/null +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/clipboard/CopierFactory.java @@ -0,0 +1,98 @@ +/***************************************************************************** + * Copyright (c) 2016 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 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Christian W. Damus - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.infra.core.internal.clipboard; + +import java.util.function.BiPredicate; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.util.EcoreUtil.Copier; +import org.eclipse.papyrus.infra.core.clipboard.ICopierFactory; + +/** + * A factory that creates copiers for the Papyrus Clipboard. + */ +public class CopierFactory implements ICopierFactory { + + 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}. + */ + public static CopierFactory DEFAULT = new CopierFactory(true); + + /** + * Initializes me. + * + * @param useOriginalReferences + * whether non-copied references should be used while copying + */ + public CopierFactory(boolean useOriginalReferences) { + super(); + + this.useOriginalReferences = useOriginalReferences; + } + + /** + * Queries whether non-copied references should be used while copying. + * + * @return whether to use non-copied references + */ + public boolean isUseOriginalReferences() { + return useOriginalReferences; + } + + @Override + public Copier get() { + DefaultConfiguration configuration = new DefaultConfiguration(true, isUseOriginalReferences()); + CopierConfiguratorRegistry.INSTANCE.configureCopier(configuration); + + return createCopier(configuration); + } + + private Copier createCopier(DefaultConfiguration configuration) { + return configuration.isEmpty() + ? createBasicCopier() + : new ConfiguredCopier(configuration); + } + + private Copier createBasicCopier() { + return new Copier(true, isUseOriginalReferences()); + } + + // + // Nested types + // + + private static class ConfiguredCopier extends Copier { + private static final long serialVersionUID = 1L; + + private final DefaultConfiguration configuration; + + ConfiguredCopier(DefaultConfiguration configuration) { + super(configuration.isResolveReferences(), configuration.isUseOriginalReferences()); + + this.configuration = configuration; + } + + @Override + protected void copyReference(EReference eReference, EObject eObject, EObject copyEObject) { + if (configuration.shouldCopyReference(eReference, eObject)) { + super.copyReference(eReference, eObject, copyEObject); + } + } + } +} diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/clipboard/DefaultConfiguration.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/clipboard/DefaultConfiguration.java new file mode 100644 index 00000000000..1a1e49b4d35 --- /dev/null +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/clipboard/DefaultConfiguration.java @@ -0,0 +1,73 @@ +/***************************************************************************** + * Copyright (c) 2016 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 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Christian W. Damus - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.infra.core.internal.clipboard; + +import java.util.function.BiPredicate; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.papyrus.infra.core.clipboard.ICopierFactory; + +/** + * Default implementation of the copier configuration protocol. + */ +class DefaultConfiguration implements ICopierFactory.Configuration { + + private final boolean resolveReferences; + private final boolean useOriginalReferences; + + private BiPredicate<EReference, EObject> referenceFilter; + + DefaultConfiguration(boolean resolveReferences, boolean useOriginalReferences) { + super(); + + this.resolveReferences = resolveReferences; + this.useOriginalReferences = useOriginalReferences; + } + + @Override + public boolean isResolveReferences() { + return resolveReferences; + } + + @Override + public boolean isUseOriginalReferences() { + return useOriginalReferences; + } + + /** + * Queries whether I am an empty configuration. + * + * @return whether I have no copier configuration rules + */ + boolean isEmpty() { + return referenceFilter == null; + } + + @Override + public void filterReferences(BiPredicate<? super EReference, ? super EObject> filter) { + if (referenceFilter == null) { + // We will only use it for these specific inputs + @SuppressWarnings("unchecked") + BiPredicate<EReference, EObject> filter_ = (BiPredicate<EReference, EObject>) filter; + referenceFilter = filter_; + } else { + referenceFilter = referenceFilter.or(filter); + } + } + + boolean shouldCopyReference(EReference reference, EObject owner) { + return (referenceFilter == null) || !referenceFilter.test(reference, owner); + } +} diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/clipboard/DefaultConfigurator.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/clipboard/DefaultConfigurator.java new file mode 100644 index 00000000000..4dae675ce24 --- /dev/null +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/clipboard/DefaultConfigurator.java @@ -0,0 +1,100 @@ +/***************************************************************************** + * Copyright (c) 2016 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 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Christian W. Damus - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.infra.core.internal.clipboard; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Optional; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EModelElement; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.papyrus.infra.core.Activator; +import org.eclipse.papyrus.infra.core.clipboard.ICopierFactory; +import org.eclipse.papyrus.infra.core.clipboard.ICopierFactory.Configuration; +import org.eclipse.papyrus.infra.core.clipboard.ICopierFactory.Configurator; + +import com.google.common.base.Strings; + +/** + * Default configurator that reads configuration rules from the extension point. + */ +class DefaultConfigurator implements Configurator { + + private static final String REFERENCE_FILTER = "referenceFilter"; //$NON-NLS-1$ + private static final String REFERENCE_URI = "referenceURI"; //$NON-NLS-1$ + private static final String OWNER_TYPE_URI = "ownerTypeURI"; //$NON-NLS-1$ + + private final Collection<ICopierFactory.Configurator> configurationRules = new ArrayList<>(); + + /** + * Initializes me. + */ + public DefaultConfigurator() { + super(); + } + + @Override + public void configureCopier(Configuration copierConfiguration) { + configurationRules.forEach(rule -> rule.configureCopier(copierConfiguration)); + } + + boolean readElement(IConfigurationElement element) { + boolean result = false; + + if (REFERENCE_FILTER.equals(element.getName())) { + String referenceURI = element.getAttribute(REFERENCE_URI); + if (!Strings.isNullOrEmpty(referenceURI)) { + result = true; + String ownerTypeURI = element.getAttribute(OWNER_TYPE_URI); + + try { + configurationRules.add(referenceFilter(referenceURI, ownerTypeURI)); + } catch (Exception e) { + Activator.log.warn(String.format("Invalid fopier reference filter extension in %s: %s", //$NON-NLS-1$ + element.getContributor().getName(), e.getMessage())); + } + } + } + + return result; + } + + private <T extends EModelElement> Optional<T> getEcoreElement(String uriString, Class<T> metaclass) { + EObject result = null; + URI uri = URI.createURI(uriString, true); + + EPackage epackage = EPackage.Registry.INSTANCE.getEPackage(uri.trimFragment().toString()); + if (epackage != null) { + result = epackage.eResource().getEObject(uri.fragment()); + } + + return Optional.ofNullable(result).map(metaclass::cast); + } + + private ICopierFactory.Configurator referenceFilter(String referenceURI, String ownerTypeURI) { + EReference reference = getEcoreElement(referenceURI, EReference.class).orElseThrow( + () -> new IllegalArgumentException("missing or invalid reference URI")); //$NON-NLS-1$ + + EClass ownerType = getEcoreElement(ownerTypeURI, EClass.class) + .orElse(reference.getEContainingClass()); + + return config -> config.filterReferences( + (ref, owner) -> (ref == reference) && ownerType.isInstance(owner)); + } +} diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF index 3d174ab26b1..ddf6a8377e7 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF @@ -67,7 +67,8 @@ Require-Bundle: org.eclipse.emf.ecore.edit;bundle-version="[2.9.0,3.0.0)", org.eclipse.papyrus.infra.sync;bundle-version="[1.2.0,2.0.0)";visibility:=reexport, org.eclipse.papyrus.infra.services.edit.ui;bundle-version="[3.0.0,4.0.0)";visibility:=reexport, org.eclipse.papyrus.infra.emf.gmf, - org.eclipse.papyrus.infra.ui;bundle-version="[2.0.0,3.0.0)" + org.eclipse.papyrus.infra.ui;bundle-version="[2.0.0,3.0.0)", + org.eclipse.papyrus.infra.core;bundle-version="[2.2.0,3.0.0)" Bundle-Vendor: %providerName Bundle-ActivationPolicy: lazy Bundle-ClassPath: . 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 6703095a1a1..bf233a978e0 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 @@ -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 502461 *****************************************************************************/ package org.eclipse.papyrus.infra.gmfdiag.common.commands; @@ -19,6 +20,7 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.edit.command.AbstractOverrideableCommand; import org.eclipse.emf.edit.domain.EditingDomain; +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; @@ -47,8 +49,8 @@ public class DefaultCopyCommand extends AbstractOverrideableCommand implements N public DefaultCopyCommand(EditingDomain domain, PapyrusClipboard papyrusClipboard, Collection<EObject> pObjectsToPutInClipboard) { 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); + boolean keepReferences = Activator.getInstance().getPreferenceStore().getBoolean(PastePreferencesPage.KEEP_EXTERNAL_REFERENCES); + EcoreUtil.Copier copier = ICopierFactory.getInstance(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/DefaultPasteCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultPasteCommand.java index d07f91911f3..81f10822c27 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 @@ -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 502461 *****************************************************************************/ package org.eclipse.papyrus.infra.gmfdiag.common.commands; @@ -27,6 +28,7 @@ import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; import org.eclipse.gmf.runtime.common.core.command.ICommand; import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest; +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.services.edit.service.ElementEditServiceUtils; @@ -69,7 +71,7 @@ public class DefaultPasteCommand extends AbstractCommand { List<EObject> rootElementToPaste = EcoreUtil.filterDescendants(eobjectsTopaste); // Copy all eObjects (inspired from PasteFromClipboardCommand) - EcoreUtil.Copier copier = new EcoreUtil.Copier(); + EcoreUtil.Copier copier = ICopierFactory.getInstance().get(); copier.copyAll(rootElementToPaste); copier.copyReferences(); Map<EObject, EObject> duplicatedObjects = new HashMap<EObject, EObject>(); |