Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraelkouhen2011-07-07 09:24:12 +0000
committeraelkouhen2011-07-07 09:24:12 +0000
commit1f8fbd639aba88af70fa1d6409a6ad1126ceddd6 (patch)
tree02a8875eee28f404604e902ac7027b08e866fb36
parent63a2a19d95f325f3adcdf34cecc1914218fc6a5e (diff)
downloadorg.eclipse.papyrus-1f8fbd639aba88af70fa1d6409a6ad1126ceddd6.tar.gz
org.eclipse.papyrus-1f8fbd639aba88af70fa1d6409a6ad1126ceddd6.tar.xz
org.eclipse.papyrus-1f8fbd639aba88af70fa1d6409a6ad1126ceddd6.zip
Bug 325610 : File monitoring Service for decoration Service
-rw-r--r--incoming/org.eclipse.papyrus.markerlistener/.classpath7
-rw-r--r--incoming/org.eclipse.papyrus.markerlistener/.project28
-rw-r--r--incoming/org.eclipse.papyrus.markerlistener/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--incoming/org.eclipse.papyrus.markerlistener/META-INF/MANIFEST.MF15
-rw-r--r--incoming/org.eclipse.papyrus.markerlistener/about.html28
-rw-r--r--incoming/org.eclipse.papyrus.markerlistener/build.properties9
-rw-r--r--incoming/org.eclipse.papyrus.markerlistener/plugin.properties13
-rw-r--r--incoming/org.eclipse.papyrus.markerlistener/plugin.xml13
-rw-r--r--incoming/org.eclipse.papyrus.markerlistener/src/org/eclipse/papyrus/markerlistener/Activator.java89
-rw-r--r--incoming/org.eclipse.papyrus.markerlistener/src/org/eclipse/papyrus/markerlistener/MarkersMonitorService.java266
-rw-r--r--incoming/org.eclipse.papyrus.markerlistener/src/org/eclipse/papyrus/markerlistener/util/MarkerListenerUtils.java93
11 files changed, 569 insertions, 0 deletions
diff --git a/incoming/org.eclipse.papyrus.markerlistener/.classpath b/incoming/org.eclipse.papyrus.markerlistener/.classpath
new file mode 100644
index 00000000000..2d1a4302f04
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.markerlistener/.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/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/incoming/org.eclipse.papyrus.markerlistener/.project b/incoming/org.eclipse.papyrus.markerlistener/.project
new file mode 100644
index 00000000000..37dd4e044e1
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.markerlistener/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.markerlistener</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/incoming/org.eclipse.papyrus.markerlistener/.settings/org.eclipse.jdt.core.prefs b/incoming/org.eclipse.papyrus.markerlistener/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..c74da2f2a4f
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.markerlistener/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Wed Apr 13 16:10:03 CEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/incoming/org.eclipse.papyrus.markerlistener/META-INF/MANIFEST.MF b/incoming/org.eclipse.papyrus.markerlistener/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..416f5302699
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.markerlistener/META-INF/MANIFEST.MF
@@ -0,0 +1,15 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.papyrus.markerlistener;singleton:=true
+Bundle-Version: 0.8.0.qualifier
+Bundle-Activator: org.eclipse.papyrus.markerlistener.Activator
+Bundle-Vendor: %providerName
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.papyrus.core;bundle-version="0.8.0"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
+Export-Package: org.eclipse.papyrus.markerlistener
+Import-Package: org.eclipse.papyrus.decoration,
+ org.eclipse.papyrus.diagram.common.util
diff --git a/incoming/org.eclipse.papyrus.markerlistener/about.html b/incoming/org.eclipse.papyrus.markerlistener/about.html
new file mode 100644
index 00000000000..209103075a7
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.markerlistener/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 (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). 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, &quot;Program&quot; 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 (&quot;Redistributor&quot;) 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/incoming/org.eclipse.papyrus.markerlistener/build.properties b/incoming/org.eclipse.papyrus.markerlistener/build.properties
new file mode 100644
index 00000000000..1065c6693a5
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.markerlistener/build.properties
@@ -0,0 +1,9 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ icons/,\
+ plugin.properties,\
+ about.html
+src.includes = icons/,\
diff --git a/incoming/org.eclipse.papyrus.markerlistener/plugin.properties b/incoming/org.eclipse.papyrus.markerlistener/plugin.properties
new file mode 100644
index 00000000000..8ec77d6b94f
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.markerlistener/plugin.properties
@@ -0,0 +1,13 @@
+###############################################################################
+# Copyright (c) 2010 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
+# Amine EL KOUHEN (CEA LIST) Amine.elkouhen@cea.fr - Added the Menu Extension File Monitoring and Decoration Service
+###############################################################################
+pluginName=Papyrus Validation Listening Service (Incubation)
+pluginProvider=Eclipse Modeling Project
diff --git a/incoming/org.eclipse.papyrus.markerlistener/plugin.xml b/incoming/org.eclipse.papyrus.markerlistener/plugin.xml
new file mode 100644
index 00000000000..bed824127d1
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.markerlistener/plugin.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.papyrus.core.service">
+ <service
+ classname="org.eclipse.papyrus.markerlistener.MarkersMonitorService"
+ priority="1"
+ startKind="startup">
+ </service>
+ </extension>
+
+</plugin>
diff --git a/incoming/org.eclipse.papyrus.markerlistener/src/org/eclipse/papyrus/markerlistener/Activator.java b/incoming/org.eclipse.papyrus.markerlistener/src/org/eclipse/papyrus/markerlistener/Activator.java
new file mode 100644
index 00000000000..104c5c60940
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.markerlistener/src/org/eclipse/papyrus/markerlistener/Activator.java
@@ -0,0 +1,89 @@
+/*****************************************************************************
+ * Copyright (c) 2011 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:
+ * Amine EL KOUHEN (CEA LIST/LIFL) - Amine.Elkouhen@cea.fr
+ *****************************************************************************/
+package org.eclipse.papyrus.markerlistener;
+
+import org.eclipse.papyrus.log.LogHelper;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The activator class controls the plug-in life cycle.
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ /** The Constant PLUGIN_ID. */
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.markerlistener"; //$NON-NLS-1$
+
+ // The shared instance
+ /** The plugin. */
+ private static Activator plugin;
+
+ /** The log service. */
+ public static LogHelper log;
+
+ /**
+ * The constructor.
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ /**
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ *
+ * @param context
+ * @throws Exception
+ */
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ log = new LogHelper(plugin);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ /**
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ *
+ * @param context
+ * @throws Exception
+ */
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ log = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance.
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/incoming/org.eclipse.papyrus.markerlistener/src/org/eclipse/papyrus/markerlistener/MarkersMonitorService.java b/incoming/org.eclipse.papyrus.markerlistener/src/org/eclipse/papyrus/markerlistener/MarkersMonitorService.java
new file mode 100644
index 00000000000..758290eb80d
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.markerlistener/src/org/eclipse/papyrus/markerlistener/MarkersMonitorService.java
@@ -0,0 +1,266 @@
+/*****************************************************************************
+ * Copyright (c) 2011 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:
+ * Amine EL KOUHEN (CEA LIST/LIFL) - Amine.Elkouhen@cea.fr
+ *****************************************************************************/
+package org.eclipse.papyrus.markerlistener;
+
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.ui.resources.FileChangeManager;
+import org.eclipse.gmf.runtime.common.ui.resources.IFileObserver;
+import org.eclipse.papyrus.core.services.IService;
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.core.services.ServicesRegistry;
+import org.eclipse.papyrus.core.utils.ServiceUtils;
+import org.eclipse.papyrus.decoration.DecorationService;
+import org.eclipse.papyrus.markerlistener.util.MarkerListenerUtils;
+
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Class MarkersMonitorService.
+ */
+public class MarkersMonitorService implements IService {
+
+ /** The services registry. */
+ private ServicesRegistry servicesRegistry;
+
+ /** The decoration service. */
+ private DecorationService decorationService;
+
+ /**
+ * Gets the services registry.
+ *
+ * @return the services registry
+ */
+ public ServicesRegistry getServicesRegistry() {
+ return servicesRegistry;
+ }
+
+
+ /**
+ * Sets the services registry.
+ *
+ * @param servicesRegistry
+ * the new services registry
+ */
+ public void setServicesRegistry(ServicesRegistry servicesRegistry) {
+ this.servicesRegistry = servicesRegistry;
+ }
+
+ /** The file observer. */
+ protected MarkerObserver fileObserver;
+
+
+ /**
+ * Instantiates a new markers monitor service.
+ */
+ public MarkersMonitorService() {
+ System.out.println("MarkersMonitorService created");
+ }
+
+ /**
+ * @see org.eclipse.papyrus.core.services.IService#init(org.eclipse.papyrus.core.services.ServicesRegistry)
+ *
+ * @param servicesRegistry
+ * @throws ServiceException
+ */
+
+ public void init(ServicesRegistry servicesRegistry) throws ServiceException {
+ this.servicesRegistry = servicesRegistry;
+ this.fileObserver = new MarkerObserver(ServiceUtils.getInstance().getModelSet(servicesRegistry).getTransactionalEditingDomain());
+ try {
+ decorationService = servicesRegistry.getService(DecorationService.class);
+ checkMarkers();
+ } catch (ServiceException e) {
+ Activator.log.error(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * @see org.eclipse.papyrus.core.services.IService#startService()
+ *
+ * @throws ServiceException
+ */
+
+ public void startService() throws ServiceException {
+ //Start Listening
+ FileChangeManager.getInstance().addFileObserver(this.fileObserver);
+ System.out.println("MarkersMonitorService Started");
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.core.services.IService#disposeService()
+ *
+ * @throws ServiceException
+ */
+
+ public void disposeService() throws ServiceException {
+ //Stop Listening
+ FileChangeManager.getInstance().removeFileObserver(this.fileObserver);
+ System.out.println("MarkersMonitorService Stoped");
+ }
+
+ /**
+ * Initial Checking for existing markers in notation.uml.
+ */
+ void checkMarkers() {
+ IMarker[] markers = null;
+
+ try {
+ URI uri = ServiceUtils.getInstance().getModelSet(servicesRegistry).getResources().get(0).getURI();
+ String platformResourceString = uri.toPlatformString(true);
+ IFile file = (platformResourceString != null ? ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(platformResourceString)) : null);
+ if(file != null) {
+ try {
+ markers = file.findMarkers(IMarker.PROBLEM, true, 0);
+ } catch (CoreException e) {
+ Activator.log.error(e.getMessage(), e);
+ }
+ }
+
+ for(int i = 0; i < markers.length; i++) {
+ EObject eObjectFromMarker = MarkerListenerUtils.eObjectFromMarkerOrMap(markers[i], null, ServiceUtils.getInstance().getModelSet(servicesRegistry).getTransactionalEditingDomain());
+ int severity = markers[i].getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
+ if(eObjectFromMarker != null && severity > IMarker.SEVERITY_INFO)
+ try {
+ decorationService.addDecoration(markers[i].toString(), eObjectFromMarker, severity, (String)markers[i].getAttribute(IMarker.MESSAGE));
+ } catch (CoreException e) {
+ Activator.log.error(e.getMessage(), e);
+ }
+ }
+
+ } catch (ServiceException e1) {
+ // TODO Auto-generated catch block
+ Activator.log.error(e1.getMessage(), e1);
+ }
+ }
+
+
+
+ // File Listening Functions
+
+ /**
+ * An asynchronous update interface for receiving notifications
+ * about Marker information as the Marker is constructed.
+ */
+ class MarkerObserver implements IFileObserver {
+
+
+ /** The domain. */
+ private final TransactionalEditingDomain domain;
+
+ /**
+ * This method is called when information about an Marker
+ * which was previously requested using an asynchronous
+ * interface becomes available.
+ *
+ * @param domain
+ * the domain
+ */
+ public MarkerObserver(TransactionalEditingDomain domain) {
+ this.domain = domain;
+ }
+
+ /**
+ * handle changes of file name.
+ *
+ * @param oldFile
+ * the old file
+ * @param file
+ * the file
+ */
+ public void handleFileRenamed(IFile oldFile, IFile file) {
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.common.ui.resources.IFileObserver#handleFileMoved(org.eclipse.core.resources.IFile,
+ * org.eclipse.core.resources.IFile)
+ *
+ * @param oldFile
+ * @param file
+ */
+
+ public void handleFileMoved(IFile oldFile, IFile file) {
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.common.ui.resources.IFileObserver#handleFileDeleted(org.eclipse.core.resources.IFile)
+ *
+ * @param file
+ */
+
+ public void handleFileDeleted(IFile file) {
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.common.ui.resources.IFileObserver#handleFileChanged(org.eclipse.core.resources.IFile)
+ *
+ * @param file
+ */
+
+ public void handleFileChanged(IFile file) {
+ }
+
+ /**
+ * A marker has been added, treat as change.
+ *
+ * @param marker
+ * the marker
+ */
+ public void handleMarkerAdded(IMarker marker) {
+ handleMarkerChanged(marker);
+ }
+
+ /**
+ * A marker has been deleted. Need to treat separately from change, since old values are not stored in
+ * marker, but in attribute map
+ *
+ * @param marker
+ * the marker
+ * @param attributes
+ * the attributes
+ */
+ public void handleMarkerDeleted(IMarker marker, @SuppressWarnings("rawtypes") Map attributes) {
+ EObject eObjectFromMarker = MarkerListenerUtils.eObjectFromMarkerOrMap(null, attributes, domain);
+ int severity = marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
+ if(eObjectFromMarker != null && severity == IMarker.SEVERITY_INFO)
+ decorationService.removeDecoration(marker.toString());
+ }
+
+ /**
+ * A marker has changed.
+ *
+ * @param marker
+ * the marker
+ */
+ public void handleMarkerChanged(IMarker marker) {
+ EObject eObjectFromMarker = MarkerListenerUtils.eObjectFromMarkerOrMap(marker, null, domain);
+ int severity = marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
+ if(eObjectFromMarker != null && severity > IMarker.SEVERITY_INFO)
+ try {
+ decorationService.addDecoration(marker.toString(), eObjectFromMarker, severity, (String)marker.getAttribute(IMarker.MESSAGE));
+ } catch (CoreException e) {
+ Activator.log.error(e.getMessage(), e);
+ }
+ }
+ }
+
+}
diff --git a/incoming/org.eclipse.papyrus.markerlistener/src/org/eclipse/papyrus/markerlistener/util/MarkerListenerUtils.java b/incoming/org.eclipse.papyrus.markerlistener/src/org/eclipse/papyrus/markerlistener/util/MarkerListenerUtils.java
new file mode 100644
index 00000000000..4da25f59b67
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.markerlistener/src/org/eclipse/papyrus/markerlistener/util/MarkerListenerUtils.java
@@ -0,0 +1,93 @@
+/*****************************************************************************
+ * Copyright (c) 2011 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:
+ * Amine EL KOUHEN (CEA LIST/LIFL) - Amine.Elkouhen@cea.fr
+ *****************************************************************************/
+package org.eclipse.papyrus.markerlistener.util;
+
+import java.util.Map;
+import java.util.MissingResourceException;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.common.util.WrappedException;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EValidator;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.edit.domain.EditingDomain;
+
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Class MarkerListenerUtils.
+ */
+public class MarkerListenerUtils {
+
+ /**
+ * E object from marker or map.
+ *
+ * @param marker
+ * the marker
+ * @param attributes
+ * the attributes
+ * @param domain
+ * the domain
+ * @return the e object
+ */
+ public static EObject eObjectFromMarkerOrMap(IMarker marker, @SuppressWarnings("rawtypes") Map attributes, EditingDomain domain) {
+ String uriAttribute;
+ if(domain == null) {
+ return null;
+ }
+ if(marker != null) {
+ uriAttribute = marker.getAttribute(EValidator.URI_ATTRIBUTE, null);
+ } else {
+ uriAttribute = (String)attributes.get(EValidator.URI_ATTRIBUTE);
+ }
+ if(uriAttribute != null) {
+ URI uriOfMarker = URI.createURI(uriAttribute);
+ try {
+ return domain.getResourceSet().getEObject(uriOfMarker, true);
+ } catch (MissingResourceException e) {
+ // happens after renaming of the file containing the marker (or a parent folder)
+ // try to retrieve eObject via fragment only (assuming that no two elements within resource-set share
+ // the same fragment).
+ return eObjectOfFragment(uriOfMarker, domain);
+ } catch (WrappedException e) {
+ // same as above, seems to depend on context which exception is thrown.
+ return eObjectOfFragment(uriOfMarker, domain);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * E object of fragment.
+ *
+ * @param uri
+ * the uri
+ * @param domain
+ * the domain
+ * @return the e object
+ */
+ public static EObject eObjectOfFragment(URI uri, EditingDomain domain) {
+ try {
+ for(Resource resource : domain.getResourceSet().getResources()) {
+ EObject eObjectOfMarker = resource.getEObject(uri.fragment());
+ if(eObjectOfMarker != null) {
+ return eObjectOfMarker;
+ }
+ }
+ } catch (WrappedException e) {
+ }
+ return null;
+ }
+
+}

Back to the top