diff options
17 files changed, 547 insertions, 7 deletions
diff --git a/features/papyrus-main-features/org.eclipse.papyrus.infra.services.feature/feature.xml b/features/papyrus-main-features/org.eclipse.papyrus.infra.services.feature/feature.xml index 69d2f52ae65..d0084cfb784 100644 --- a/features/papyrus-main-features/org.eclipse.papyrus.infra.services.feature/feature.xml +++ b/features/papyrus-main-features/org.eclipse.papyrus.infra.services.feature/feature.xml @@ -41,4 +41,6 @@ http://www.eclipse.org/legal/epl-v10.html <plugin download-size="0" id="org.eclipse.papyrus.infra.services.navigation" install-size="0" unpack="false" version="0.0.0"/>
+ <plugin download-size="0" id="org.eclipse.papyrus.infra.services.localizer" install-size="0" unpack="false" version="0.0.0"/>
+
</feature>
\ No newline at end of file diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/.classpath b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/.classpath new file mode 100644 index 00000000000..ad32c83a788 --- /dev/null +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/.project b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/.project new file mode 100644 index 00000000000..11fb2387944 --- /dev/null +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.papyrus.infra.services.localizer</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/.settings/org.eclipse.jdt.core.prefs b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..c537b63063c --- /dev/null +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/META-INF/MANIFEST.MF b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..eddadaae489 --- /dev/null +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.papyrus.infra.services.localizer;singleton:=true +Bundle-Version: 0.10.1.qualifier +Bundle-Activator: org.eclipse.papyrus.infra.services.localizer.internal.Activator +Bundle-Vendor: %providerName +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.papyrus.infra.core;bundle-version="0.10.1", + org.eclipse.papyrus.infra.core.log;bundle-version="0.10.1", + org.eclipse.emf.ecore;bundle-version="[2.9.0,3.0.0)", + org.eclipse.papyrus.infra.emf;bundle-version="0.10.1" +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ActivationPolicy: lazy +Bundle-Localization: plugin +Import-Package: com.google.common.base;version="10.0.0", + com.google.common.collect;version="10.0.0" +Export-Package: org.eclipse.papyrus.infra.services.localizer, + org.eclipse.papyrus.infra.services.localizer.internal;x-internal:=true, + org.eclipse.papyrus.infra.services.localizer.util diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/about.html b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/about.html new file mode 100644 index 00000000000..dd3c089a94c --- /dev/null +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/about.html @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>November 14, 2008</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p> + +</body> +</html>
\ No newline at end of file diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/build.properties b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/build.properties new file mode 100644 index 00000000000..ae22b3b40a0 --- /dev/null +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + about.html,\ + plugin.properties,\ + plugin.xml diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/plugin.properties b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/plugin.properties new file mode 100644 index 00000000000..dc5321d68c1 --- /dev/null +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/plugin.properties @@ -0,0 +1,13 @@ +# Copyright (c) 2013 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: +# CEA LIST - Initial API and implementation +# + +pluginName = Papyrus EMF Object Localizer Service (Incubation) +providerName = Eclipse Modeling Project diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/plugin.xml b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/plugin.xml new file mode 100644 index 00000000000..1765dec8616 --- /dev/null +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/plugin.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + <extension + point="org.eclipse.papyrus.infra.core.service"> + <serviceFactory + classname="org.eclipse.papyrus.infra.services.localizer.util.DefaultObjectLocalizerFactory" + description="A service that determines the correspondents of objects and resources from other resource sets in the local ModelSet." + id="org.eclipse.papyrus.infra.services.localizer.IObjectLocalizer" + priority="1" + startKind="lazy"> + </serviceFactory> + </extension> + +</plugin> diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/src/org/eclipse/papyrus/infra/services/localizer/AbstractObjectLocalizer.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/src/org/eclipse/papyrus/infra/services/localizer/AbstractObjectLocalizer.java new file mode 100644 index 00000000000..9a82a1b2c70 --- /dev/null +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/src/org/eclipse/papyrus/infra/services/localizer/AbstractObjectLocalizer.java @@ -0,0 +1,66 @@ +/***************************************************************************** + * Copyright (c) 2013 CEA LIST 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: + * CEA LIST - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.infra.services.localizer; + +import java.util.Map; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; + +import com.google.common.collect.ImmutableMap; + + +/** + * A partial implementation of the object localizer. + */ +public abstract class AbstractObjectLocalizer implements IObjectLocalizer { + + public AbstractObjectLocalizer() { + super(); + } + + @Override + public Map<EObject, EObject> getLocalEObjects(ResourceSet localSet, Iterable<? extends EObject> remoteObjects) { + ImmutableMap.Builder<EObject, EObject> result = ImmutableMap.builder(); + + for(EObject next : remoteObjects) { + result.put(next, getLocalEObject(localSet, next)); + } + + return result.build(); + } + + @Override + public Map<Resource, Resource> getLocalResources(ResourceSet localSet, Iterable<? extends Resource> remoteResources) { + ImmutableMap.Builder<Resource, Resource> result = ImmutableMap.builder(); + + for(Resource next : remoteResources) { + result.put(next, getLocalResource(localSet, next)); + } + + return result.build(); + } + + protected ResourceSet getResourceSet(EObject object) { + Resource resource = null; + + // in CDO, resources are EObjects + if(object instanceof Resource) { + resource = (Resource)object; + } else if(object != null) { + resource = object.eResource(); + } + + return (resource == null) ? null : resource.getResourceSet(); + } +} diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/src/org/eclipse/papyrus/infra/services/localizer/DefaultObjectLocalizer.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/src/org/eclipse/papyrus/infra/services/localizer/DefaultObjectLocalizer.java new file mode 100644 index 00000000000..ceac2214bd2 --- /dev/null +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/src/org/eclipse/papyrus/infra/services/localizer/DefaultObjectLocalizer.java @@ -0,0 +1,68 @@ +/***************************************************************************** + * Copyright (c) 2013 CEA LIST 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: + * CEA LIST - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.infra.services.localizer; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.ContentHandler; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.util.EcoreUtil; + + +/** + * The default object localizer simply assumes that resources and objects can be loaded in the local resource set in the usual way. + */ +public class DefaultObjectLocalizer extends AbstractObjectLocalizer { + + public static final DefaultObjectLocalizer INSTANCE = new DefaultObjectLocalizer(); + + public DefaultObjectLocalizer() { + super(); + } + + @Override + public EObject getLocalEObject(ResourceSet localSet, EObject remoteObject) { + EObject result = null; + + if(getResourceSet(remoteObject) == localSet) { + result = remoteObject; + } else { + URI uri = EcoreUtil.getURI(remoteObject); + if(uri != null) { + result = localSet.getEObject(uri, true); + } + } + + return result; + } + + @Override + public Resource getLocalResource(ResourceSet localSet, Resource remoteResource) { + Resource result = null; + + if(remoteResource != null) { + if(remoteResource.getResourceSet() == localSet) { + result = remoteResource; + } else { + result = localSet.getResource(remoteResource.getURI(), false); + if(result == null) { + // create but don't load + result = localSet.createResource(remoteResource.getURI(), ContentHandler.UNSPECIFIED_CONTENT_TYPE); + } + } + } + + return result; + } + +} diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/src/org/eclipse/papyrus/infra/services/localizer/IObjectLocalizer.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/src/org/eclipse/papyrus/infra/services/localizer/IObjectLocalizer.java new file mode 100644 index 00000000000..bba7ff63f9a --- /dev/null +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/src/org/eclipse/papyrus/infra/services/localizer/IObjectLocalizer.java @@ -0,0 +1,88 @@ +/***************************************************************************** + * Copyright (c) 2013 CEA LIST 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: + * CEA LIST - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.infra.services.localizer; + +import java.util.Map; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; + + +/** + * <p> + * An object localizer provides the instances of {@link EObject}s and {@link Resource}s in a {@link ResourceSet} (the "local" set) corresponding to + * instances residing in another resource set (the "remote" set). + * </p> + * <p> + * This accounts for systems such as the CDO model repository in which there are peculiar considerations like: + * </p> + * <ul> + * <li>resources are {@code EObject}s, but treating them as such is not necessarily appropriate to the situation</li> + * <li>some {@code EObject}s represent text or binary documents (CLOB/BLOB resources) that should not be retrieved by attempting to load their + * {@link EObject#eResource() eResource} and asking it for the object</li> + * </ul> + */ +public interface IObjectLocalizer { + + /** + * Finds and returns (loading it, if necessary) the local correspondent of the specified remote {@link EObject}. + * + * @param localSet + * the local resource set in which to find the object + * @param remoteObject + * the remote object to localize + * @return the local instance of the {@code remoteObject}, or {@code null} if it is not available locally. This could + * just be the original {@code remoteObject} if the remote resource set is the local set + */ + EObject getLocalEObject(ResourceSet localSet, EObject remoteObject); + + /** + * Finds and returns (without loading it, though it may have been loaded previously) the local correspondent of the specified remote + * {@link Resource}. + * + * @param localSet + * the local resource set in which to find the resource + * @param remoteResource + * the remote resource to localize + * @return the local instance of the {@code remoteResource}, or {@code null} if it is not available locally. This could + * just be the original {@code remoteResource} if the remote resource set is the local set + */ + Resource getLocalResource(ResourceSet localSet, Resource remoteResource); + + /** + * Finds and returns (loading them, if necessary) the local correspondents of the specified remote {@link EObject}s. + * + * @param localSet + * the local resource set in which to find the objects + * @param remoteObjects + * the remote objects to localize + * @return a mapping of the local instances of the {@code remoteObjects}, keyed by the remotes. For any object, its mapping may be {@code null} if + * it is not available locally or could + * just be the original remote if the remote resource set is the local set. The map must be assumed by callers to be immutable + */ + Map<EObject, EObject> getLocalEObjects(ResourceSet localSet, Iterable<? extends EObject> remoteObjects); + + /** + * Finds and returns (without loading them, though they may have been loaded previously) the local correspondents of the specified remote + * {@link Resource}s. + * + * @param localSet + * the local resource set in which to find the resources + * @param remoteResources + * the remote resources to localize + * @return a mapping of the local instances of the {@code remoteResources}, keyed by the remotes. For any resource, its mapping may be + * {@code null} if it is not available locally or could + * just be the original remote if the remote resource set is the local set. The map must be assumed by callers to be immutable + */ + Map<Resource, Resource> getLocalResources(ResourceSet localSet, Iterable<? extends Resource> remoteResources); +} diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/src/org/eclipse/papyrus/infra/services/localizer/internal/Activator.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/src/org/eclipse/papyrus/infra/services/localizer/internal/Activator.java new file mode 100644 index 00000000000..ce8cc005420 --- /dev/null +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/src/org/eclipse/papyrus/infra/services/localizer/internal/Activator.java @@ -0,0 +1,50 @@ +package org.eclipse.papyrus.infra.services.localizer.internal; + +import org.eclipse.core.runtime.Plugin; +import org.eclipse.papyrus.infra.core.log.LogHelper; +import org.osgi.framework.BundleContext; + +public class Activator extends Plugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.papyrus.infra.services.localizer"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** Logging helper */ + public static LogHelper log = new LogHelper(); + + /** + * The constructor + */ + public Activator() { + super(); + } + + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + + // register the log helper + log.setPlugin(plugin); + } + + @Override + public void stop(BundleContext context) throws Exception { + log = null; + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/src/org/eclipse/papyrus/infra/services/localizer/util/DefaultObjectLocalizerFactory.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/src/org/eclipse/papyrus/infra/services/localizer/util/DefaultObjectLocalizerFactory.java new file mode 100644 index 00000000000..9b0216f3cf4 --- /dev/null +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/src/org/eclipse/papyrus/infra/services/localizer/util/DefaultObjectLocalizerFactory.java @@ -0,0 +1,49 @@ +/***************************************************************************** + * Copyright (c) 2013 CEA LIST 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: + * CEA LIST - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.infra.services.localizer.util; + +import org.eclipse.papyrus.infra.core.services.IServiceFactory; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.core.services.ServicesRegistry; +import org.eclipse.papyrus.infra.services.localizer.DefaultObjectLocalizer; + + +/** + * Service factory for the default object localizer. + */ +public class DefaultObjectLocalizerFactory implements IServiceFactory { + + public DefaultObjectLocalizerFactory() { + super(); + } + + @Override + public void init(ServicesRegistry servicesRegistry) throws ServiceException { + // pass. The localizer is stateless and requires no initialization + } + + @Override + public void startService() throws ServiceException { + // pass. The localizer is stateless and requires no starting + } + + @Override + public void disposeService() throws ServiceException { + // pass. The localizer is stateless and requires no disposal + } + + @Override + public Object createServiceInstance() throws ServiceException { + return DefaultObjectLocalizer.INSTANCE; + } + +} diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/src/org/eclipse/papyrus/infra/services/localizer/util/LocalizerUtil.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/src/org/eclipse/papyrus/infra/services/localizer/util/LocalizerUtil.java new file mode 100644 index 00000000000..2fef02a2b2c --- /dev/null +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.localizer/src/org/eclipse/papyrus/infra/services/localizer/util/LocalizerUtil.java @@ -0,0 +1,83 @@ +/***************************************************************************** + * Copyright (c) 2013 CEA LIST 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: + * CEA LIST - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.infra.services.localizer.util; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.core.services.ServicesRegistry; +import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject; +import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource; +import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResourceSet; +import org.eclipse.papyrus.infra.services.localizer.DefaultObjectLocalizer; +import org.eclipse.papyrus.infra.services.localizer.IObjectLocalizer; +import org.eclipse.papyrus.infra.services.localizer.internal.Activator; + + +/** + * Utilities for getting/working with localizers. + */ +public class LocalizerUtil { + + /** + * Not instantiable by clients. + */ + private LocalizerUtil() { + super(); + } + + public static IObjectLocalizer getDefault() { + return DefaultObjectLocalizer.INSTANCE; + } + + public static IObjectLocalizer getInstance(ResourceSet rset) { + try { + return getInstance(ServiceUtilsForResourceSet.getInstance().getServiceRegistry(rset)); + } catch (ServiceException e) { + Activator.log.error("Failed to get localizer service.", e); //$NON-NLS-1$ + } + + return getDefault(); + } + + public static IObjectLocalizer getInstance(Resource resource) { + try { + return getInstance(ServiceUtilsForResource.getInstance().getServiceRegistry(resource)); + } catch (ServiceException e) { + Activator.log.error("Failed to get localizer service.", e); //$NON-NLS-1$ + } + + return getDefault(); + } + + public static IObjectLocalizer getInstance(EObject object) { + try { + return getInstance(ServiceUtilsForEObject.getInstance().getServiceRegistry(object)); + } catch (ServiceException e) { + Activator.log.error("Failed to get localizer service.", e); //$NON-NLS-1$ + } + + return getDefault(); + } + + public static IObjectLocalizer getInstance(ServicesRegistry services) { + try { + return services.getService(IObjectLocalizer.class); + } catch (ServiceException e) { + Activator.log.error("Failed to get localizer service.", e); //$NON-NLS-1$ + } + + return getDefault(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF index 9fd4b169075..e2e5e0fc766 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF @@ -86,7 +86,8 @@ Require-Bundle: org.eclipse.papyrus.infra.core;bundle-version="0.10.1", org.eclipse.papyrus.infra.services.labelprovider;bundle-version="0.10.1", org.eclipse.jface, org.eclipse.papyrus.infra.emf.readonly;bundle-version="0.10.1", - org.eclipse.emf.facet.infra.browser.uicore;bundle-version="0.4.0" + org.eclipse.emf.facet.infra.browser.uicore;bundle-version="0.4.0", + org.eclipse.papyrus.infra.services.localizer;bundle-version="0.10.1" Bundle-Vendor: %providerName Ant-Version: Apache Ant 1.7.0 Bundle-Version: 0.10.1.qualifier diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/listeners/DropTargetListener.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/listeners/DropTargetListener.java index 50c795a36fb..eea5043e77d 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/listeners/DropTargetListener.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/listeners/DropTargetListener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Obeo. + * Copyright (c) 2008, 2013 Obeo, CEA LIST, 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 @@ -8,6 +8,7 @@ * Contributors: * Obeo - initial API and implementation * modified by CEA-LIST + * Christian W. Damus (CEA LIST) - delegate object localization to a new service *******************************************************************************/ package org.eclipse.papyrus.uml.diagram.common.listeners; @@ -18,12 +19,14 @@ import java.util.List; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.gef.EditPartViewer; import org.eclipse.gef.Request; import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramDropTargetListener; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.papyrus.infra.services.localizer.IObjectLocalizer; +import org.eclipse.papyrus.infra.services.localizer.util.LocalizerUtil; import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.dnd.TransferData; @@ -60,8 +63,13 @@ public abstract class DropTargetListener extends DiagramDropTargetListener { // order of the selection Object transferedObject = getJavaObject(data); + ArrayList<EObject> result = new ArrayList<EObject>(); + if(transferedObject instanceof IStructuredSelection) { IStructuredSelection selection = (IStructuredSelection)transferedObject; + ResourceSet localSet = getTransactionalEditingDomain().getResourceSet(); + IObjectLocalizer localizer = LocalizerUtil.getInstance(localSet); + for(Iterator<?> it = selection.iterator(); it.hasNext();) { Object nextSelectedObject = it.next(); // if (nextSelectedObject instanceof UMLNavigatorItem) { @@ -74,14 +82,14 @@ public abstract class DropTargetListener extends DiagramDropTargetListener { nextSelectedObject = adaptable.getAdapter(EObject.class); } if(nextSelectedObject instanceof EObject) { - EObject modelElement = (EObject)nextSelectedObject; - Resource modelElementResource = modelElement.eResource(); - uris.add(modelElementResource.getURI().appendFragment(modelElementResource.getURIFragment(modelElement))); + EObject local = localizer.getLocalEObject(localSet, (EObject)nextSelectedObject); + if(local != null) { + result.add(local); + } } } } - ArrayList<EObject> result = new ArrayList<EObject>(); for(URI uri : uris) { EObject modelObject = getTransactionalEditingDomain().getResourceSet().getEObject(uri, true); result.add(modelObject); |