Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2011-10-25 08:13:19 -0400
committercletavernie2011-10-25 08:13:19 -0400
commit565a800d0331ee6af75ef3333dd75a1bd56ddf62 (patch)
treebffef3dfc1605554a75b7d5912928330e1b57d7d /plugins/views/documentation
parentf2066fd5041aff68cdf316b4ab6e0f742ba99071 (diff)
downloadorg.eclipse.papyrus-565a800d0331ee6af75ef3333dd75a1bd56ddf62.tar.gz
org.eclipse.papyrus-565a800d0331ee6af75ef3333dd75a1bd56ddf62.tar.xz
org.eclipse.papyrus-565a800d0331ee6af75ef3333dd75a1bd56ddf62.zip
359057: [Architecture - SVN - Build] The Papyrus architecture should be refactored
https://bugs.eclipse.org/bugs/show_bug.cgi?id=359057
Diffstat (limited to 'plugins/views/documentation')
-rw-r--r--plugins/views/documentation/org.eclipse.papyrus.documentation/.classpath7
-rw-r--r--plugins/views/documentation/org.eclipse.papyrus.documentation/.project28
-rw-r--r--plugins/views/documentation/org.eclipse.papyrus.documentation/META-INF/MANIFEST.MF15
-rw-r--r--plugins/views/documentation/org.eclipse.papyrus.documentation/about.html28
-rw-r--r--plugins/views/documentation/org.eclipse.papyrus.documentation/build.properties7
-rw-r--r--plugins/views/documentation/org.eclipse.papyrus.documentation/plugin.properties12
-rw-r--r--plugins/views/documentation/org.eclipse.papyrus.documentation/plugin.xml6
-rw-r--r--plugins/views/documentation/org.eclipse.papyrus.documentation/schema/documentationManager.exsd100
-rw-r--r--plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/Activator.java43
-rw-r--r--plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/DocumentationManager.java132
-rw-r--r--plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/DocumentationManagerRegistry.java148
-rw-r--r--plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/DocumentationUnsupportedException.java27
-rw-r--r--plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/IDocumentationChangedListener.java32
-rw-r--r--plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/IDocumentationManager.java105
-rw-r--r--plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/Messages.java38
-rw-r--r--plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/eannotation/AddOrRemoveAssociatedResourceCommand.java152
-rw-r--r--plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/eannotation/ChangeEAnnotationCommand.java150
-rw-r--r--plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/eannotation/EAnnotationDocumentationManager.java161
-rw-r--r--plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/eannotation/IEAnnotationConstants.java28
-rw-r--r--plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/messages.properties5
20 files changed, 1224 insertions, 0 deletions
diff --git a/plugins/views/documentation/org.eclipse.papyrus.documentation/.classpath b/plugins/views/documentation/org.eclipse.papyrus.documentation/.classpath
new file mode 100644
index 00000000000..2d1a4302f04
--- /dev/null
+++ b/plugins/views/documentation/org.eclipse.papyrus.documentation/.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/plugins/views/documentation/org.eclipse.papyrus.documentation/.project b/plugins/views/documentation/org.eclipse.papyrus.documentation/.project
new file mode 100644
index 00000000000..d8dc4202fb1
--- /dev/null
+++ b/plugins/views/documentation/org.eclipse.papyrus.documentation/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.documentation</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/views/documentation/org.eclipse.papyrus.documentation/META-INF/MANIFEST.MF b/plugins/views/documentation/org.eclipse.papyrus.documentation/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..5b6a0125853
--- /dev/null
+++ b/plugins/views/documentation/org.eclipse.papyrus.documentation/META-INF/MANIFEST.MF
@@ -0,0 +1,15 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-Localization: plugin
+Bundle-SymbolicName: org.eclipse.papyrus.documentation;singleton:=true
+Bundle-Version: 0.9.0.qualifier
+Bundle-Activator: org.eclipse.papyrus.documentation.Activator
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-Vendor: %providerName
+Export-Package: org.eclipse.papyrus.documentation,
+ org.eclipse.papyrus.documentation.eannotation
+Require-Bundle: org.eclipse.emf.ecore;visibility:=reexport,
+ org.eclipse.core.runtime;visibility:=reexport,
+ org.eclipse.core.commands;visibility:=reexport
diff --git a/plugins/views/documentation/org.eclipse.papyrus.documentation/about.html b/plugins/views/documentation/org.eclipse.papyrus.documentation/about.html
new file mode 100644
index 00000000000..82d49bf5f81
--- /dev/null
+++ b/plugins/views/documentation/org.eclipse.papyrus.documentation/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>June 5, 2007</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>
diff --git a/plugins/views/documentation/org.eclipse.papyrus.documentation/build.properties b/plugins/views/documentation/org.eclipse.papyrus.documentation/build.properties
new file mode 100644
index 00000000000..463ee931969
--- /dev/null
+++ b/plugins/views/documentation/org.eclipse.papyrus.documentation/build.properties
@@ -0,0 +1,7 @@
+#
+#Mon Sep 12 09:29:50 CEST 2011
+bin.includes=META-INF/,.,plugin.xml,schema/,plugin.properties,about.html
+output..=bin/
+src.includes=about.html,schema/,META-INF/,.,plugin.xml,plugin.properties
+source..=src/
+bin..=bin/
diff --git a/plugins/views/documentation/org.eclipse.papyrus.documentation/plugin.properties b/plugins/views/documentation/org.eclipse.papyrus.documentation/plugin.properties
new file mode 100644
index 00000000000..9d6c640a44d
--- /dev/null
+++ b/plugins/views/documentation/org.eclipse.papyrus.documentation/plugin.properties
@@ -0,0 +1,12 @@
+#################################################################################
+# Copyright (c) 2010 Atos Origin.
+# 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:
+# Atos Origin - Initial API and Implementation
+##################################################################################
+pluginName=Papyrus documentation manager (Incubation)
+providerName=Eclipse Modeling Project
diff --git a/plugins/views/documentation/org.eclipse.papyrus.documentation/plugin.xml b/plugins/views/documentation/org.eclipse.papyrus.documentation/plugin.xml
new file mode 100644
index 00000000000..21020b34feb
--- /dev/null
+++ b/plugins/views/documentation/org.eclipse.papyrus.documentation/plugin.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension-point id="documentationManager" name="documentationManager" schema="schema/documentationManager.exsd"/>
+
+</plugin>
diff --git a/plugins/views/documentation/org.eclipse.papyrus.documentation/schema/documentationManager.exsd b/plugins/views/documentation/org.eclipse.papyrus.documentation/schema/documentationManager.exsd
new file mode 100644
index 00000000000..2e0a20b1ece
--- /dev/null
+++ b/plugins/views/documentation/org.eclipse.papyrus.documentation/schema/documentationManager.exsd
@@ -0,0 +1,100 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.papyrus.documentation" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.papyrus.documentation" id="modelDocumentationManager" name="modelDocumentationManager"/>
+ </appinfo>
+ <documentation>
+ This extension is used to provide a way to get and set a documentation for an element of a specific meta-model.
+A generic implementation using EAnnotation on EModelElement is used if no other implementation is found for the current meta-model.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="documentationManager" minOccurs="0" 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="documentationManager">
+ <complexType>
+ <attribute name="modelNsURI" type="string" use="required">
+ <annotation>
+ <documentation>
+ The nsURI of the meta-model for which this implementation applies.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="managerClass" type="string" use="required">
+ <annotation>
+ <documentation>
+ The implementation for the specified meta-model.
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.papyrus.documentation.registry.IDocumentationManager"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="priority">
+ <annotation>
+ <documentation>
+ This attribute is used to specify the priority of the contributed documentationManager.
+The documentationManager with the higher priority will be used. The behavior is unspecified if more than one documentationManager have the same modelNsURI and the same priority. Default value is Lowest.
+ </documentation>
+ </annotation>
+ <simpleType>
+ <restriction base="string">
+ <enumeration value="Lowest">
+ </enumeration>
+ <enumeration value="Low">
+ </enumeration>
+ <enumeration value="Medium">
+ </enumeration>
+ <enumeration value="High">
+ </enumeration>
+ <enumeration value="Highest">
+ </enumeration>
+ </restriction>
+ </simpleType>
+ </attribute>
+ </complexType>
+ </element>
+
+
+
+
+
+
+</schema>
diff --git a/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/Activator.java b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/Activator.java
new file mode 100644
index 00000000000..9a18b9f5e68
--- /dev/null
+++ b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/Activator.java
@@ -0,0 +1,43 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.documentation;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator {
+
+ private static BundleContext context;
+
+ static BundleContext getContext() {
+ return context;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext bundleContext) throws Exception {
+ Activator.context = bundleContext;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext bundleContext) throws Exception {
+ Activator.context = null;
+ }
+
+}
diff --git a/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/DocumentationManager.java b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/DocumentationManager.java
new file mode 100644
index 00000000000..1f61bdb8ab3
--- /dev/null
+++ b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/DocumentationManager.java
@@ -0,0 +1,132 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.documentation;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.documentation.eannotation.EAnnotationDocumentationManager;
+
+
+/**
+ * Helper class to access and modify documentation independently from the meta-model.
+ * It also provides an easy way to be notified of documentation change.
+ * The default implementation {@link EAnnotationDocumentationManager} uses an EAnnotation if it is available.
+ *
+ * @author mvelten
+ *
+ */
+public class DocumentationManager extends DocumentationManagerRegistry implements IDocumentationManager {
+
+ private static class DocumentationManagerHolder {
+
+ public static final DocumentationManager instance = new DocumentationManager();
+ }
+
+ public static DocumentationManager getInstance() {
+ return DocumentationManagerHolder.instance;
+ }
+
+ private static Set<IDocumentationChangedListener> documentationChangedListeners = new HashSet<IDocumentationChangedListener>();
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getDocumentation(EObject eObject) throws DocumentationUnsupportedException {
+ if (eObject != null) {
+ IDocumentationManager documentationManager = getDocumentationManager(eObject.eClass().getEPackage().getNsURI());
+ if(documentationManager != null) {
+ return documentationManager.getDocumentation(eObject);
+ }
+ }
+ throw new DocumentationUnsupportedException(Messages.DocumentationManager_UnsupportedModelType);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Command getChangeDocumentationCommand(EObject eObject, String newDocumentation) {
+ IDocumentationManager documentationManager = getDocumentationManager(eObject.eClass().getEPackage().getNsURI());
+ if(documentationManager != null) {
+ return documentationManager.getChangeDocumentationCommand(eObject, newDocumentation);
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Command getAddAssociatedResourceCommand(EObject eObject, URI resourceURI) {
+ IDocumentationManager documentationManager = getDocumentationManager(eObject.eClass().getEPackage().getNsURI());
+ if(documentationManager != null) {
+ return documentationManager.getAddAssociatedResourceCommand(eObject, resourceURI);
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Command getRemoveAssociatedResourceCommand(EObject eObject, URI resourceURI) {
+ IDocumentationManager documentationManager = getDocumentationManager(eObject.eClass().getEPackage().getNsURI());
+ if(documentationManager != null) {
+ return documentationManager.getRemoveAssociatedResourceCommand(eObject, resourceURI);
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<URI> getAssociatedResources(EObject eObject) throws DocumentationUnsupportedException {
+ IDocumentationManager documentationManager = getDocumentationManager(eObject.eClass().getEPackage().getNsURI());
+ if(documentationManager != null) {
+ return documentationManager.getAssociatedResources(eObject);
+ } else {
+ throw new DocumentationUnsupportedException(Messages.DocumentationManager_UnsupportedModelType);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void registerDocumentationChangedListener(IDocumentationChangedListener listener) {
+ documentationChangedListeners.add(listener);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void unregisterDocumentationChangedListener(IDocumentationChangedListener listener) {
+ documentationChangedListeners.remove(listener);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<IDocumentationChangedListener> getRegisteredDocumentationChangedListeners() {
+ return documentationChangedListeners;
+ }
+
+ public void documentationChanged(EObject eObject) {
+ for(IDocumentationChangedListener listener : documentationChangedListeners) {
+ listener.documentationChanged(eObject);
+ }
+ }
+
+}
diff --git a/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/DocumentationManagerRegistry.java b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/DocumentationManagerRegistry.java
new file mode 100644
index 00000000000..c6b8e8948ca
--- /dev/null
+++ b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/DocumentationManagerRegistry.java
@@ -0,0 +1,148 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.documentation;
+
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.PriorityQueue;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.papyrus.documentation.eannotation.EAnnotationDocumentationManager;
+
+public abstract class DocumentationManagerRegistry implements IDocumentationChangedListener {
+
+ // extension point ID
+ private static final String MODELDOCUMENTATION_EXTENSION_ID = "org.eclipse.papyrus.documentation.documentationManager"; //$NON-NLS-1$
+
+ private static final String MODELNSURI_ID = "modelNsURI"; //$NON-NLS-1$
+
+ private static final String PRIORITY_ID = "priority"; //$NON-NLS-1$
+
+ private static final String MODELDOCUMENTATIONCLASS_ID = "managerClass"; //$NON-NLS-1$
+
+ // Lowest is default
+ private static final Integer DEFAULT_PRIORITY = 0;
+
+
+ private Map<String, PriorityQueue<IDocumentationManager>> nsURIDocumentationManagerMap = new HashMap<String, PriorityQueue<IDocumentationManager>>();
+
+ private Map<IDocumentationManager, Integer> documentationManagerPriorityMap = new HashMap<IDocumentationManager, Integer>();
+
+ private IDocumentationManager eAnnotationDocumentationManager;
+
+ public DocumentationManagerRegistry() {
+ eAnnotationDocumentationManager = EAnnotationDocumentationManager.getInstance();
+ eAnnotationDocumentationManager.registerDocumentationChangedListener(this);
+ initializeMap();
+ }
+
+ protected IDocumentationManager getDocumentationManager(String nsURI) {
+ IDocumentationManager documentationManager = null;
+
+ PriorityQueue<IDocumentationManager> documentationManagers = nsURIDocumentationManagerMap.get(nsURI);
+ if(documentationManagers != null) {
+ documentationManager = documentationManagers.peek();
+ }
+
+ if(documentationManager == null) {
+ return eAnnotationDocumentationManager;
+ }
+
+ return documentationManager;
+ }
+
+ private void initializeMap() {
+ // Reading data from plugins
+ IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(MODELDOCUMENTATION_EXTENSION_ID);
+ for(int i = 0; i < configElements.length; i++) {
+ initializeOne(configElements[i]);
+ }
+ }
+
+ private void initializeOne(IConfigurationElement iConfigurationElement) {
+ try {
+ String modelNsURI = iConfigurationElement.getAttribute(MODELNSURI_ID);
+
+ IDocumentationManager documentationManager = (IDocumentationManager)createExtension(iConfigurationElement, MODELDOCUMENTATIONCLASS_ID);
+ documentationManager.registerDocumentationChangedListener(this);
+
+ String priority = iConfigurationElement.getAttribute(PRIORITY_ID);
+ documentationManagerPriorityMap.put(documentationManager, convertPriorityToInteger(priority));
+
+ PriorityQueue<IDocumentationManager> documentationManagers = nsURIDocumentationManagerMap.get(modelNsURI);
+ if(documentationManagers == null) {
+ documentationManagers = new PriorityQueue<IDocumentationManager>(10, new Comparator<IDocumentationManager>() {
+
+ public int compare(IDocumentationManager o1, IDocumentationManager o2) {
+ Integer p1 = documentationManagerPriorityMap.get(o1);
+ if(p1 == null) {
+ p1 = DEFAULT_PRIORITY;
+ }
+ Integer p2 = documentationManagerPriorityMap.get(o2);
+ if(p2 == null) {
+ p2 = DEFAULT_PRIORITY;
+ }
+ return p2 - p1;
+ }
+ });
+
+ nsURIDocumentationManagerMap.put(modelNsURI, documentationManagers);
+ }
+ documentationManagers.add(documentationManager);
+ } catch (Throwable e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ private static Integer convertPriorityToInteger(String priorityString) {
+ if(priorityString == null) {
+ return DEFAULT_PRIORITY;
+ }
+ if(priorityString.equalsIgnoreCase("Lowest")) { //$NON-NLS-1$
+ return 0;
+ }
+ if(priorityString.equalsIgnoreCase("Low")) { //$NON-NLS-1$
+ return 1;
+ }
+ if(priorityString.equalsIgnoreCase("Medium")) { //$NON-NLS-1$
+ return 2;
+ }
+ if(priorityString.equalsIgnoreCase("High")) { //$NON-NLS-1$
+ return 3;
+ }
+ if(priorityString.equalsIgnoreCase("Highest")) { //$NON-NLS-1$
+ return 4;
+ }
+ return DEFAULT_PRIORITY;
+ }
+
+ /**
+ * Load an instance of a class
+ *
+ * @param element
+ * the extension point
+ * @param classAttribute
+ * the name of the class to load
+ * @return the loaded Class
+ * @throws Exception
+ * if the class is not loaded
+ */
+ private static Object createExtension(final IConfigurationElement element, final String classAttribute) throws Exception {
+ return element.createExecutableExtension(classAttribute);
+ }
+
+}
diff --git a/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/DocumentationUnsupportedException.java b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/DocumentationUnsupportedException.java
new file mode 100644
index 00000000000..7ac4f432373
--- /dev/null
+++ b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/DocumentationUnsupportedException.java
@@ -0,0 +1,27 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.documentation;
+
+public class DocumentationUnsupportedException extends Exception {
+
+ private static final long serialVersionUID = -5469193051315476642L;
+
+ public DocumentationUnsupportedException() {
+ super();
+ }
+
+ public DocumentationUnsupportedException(String message) {
+ super(message);
+ }
+}
diff --git a/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/IDocumentationChangedListener.java b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/IDocumentationChangedListener.java
new file mode 100644
index 00000000000..f9acbcf21f8
--- /dev/null
+++ b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/IDocumentationChangedListener.java
@@ -0,0 +1,32 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.documentation;
+
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * Listener interface used to be notified of a change in the documentation.
+ *
+ * @author mvelten
+ *
+ */
+public interface IDocumentationChangedListener {
+
+ /**
+ * This method will be called when the documentation of eObject or its author is modified.
+ *
+ * @param eObject
+ */
+ void documentationChanged(EObject eObject);
+}
diff --git a/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/IDocumentationManager.java b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/IDocumentationManager.java
new file mode 100644
index 00000000000..8f302e486ea
--- /dev/null
+++ b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/IDocumentationManager.java
@@ -0,0 +1,105 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.documentation;
+
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+
+
+/**
+ * Interface used to provide a way to get or change the documentation of an element.
+ *
+ * @author mvelten
+ *
+ */
+public interface IDocumentationManager {
+
+ /**
+ * Returns an EMF Command to change the documentation.
+ *
+ * @param eObject
+ * The element where to change the documentation.
+ * @param newDocumentation
+ * The new value of the documentation or null to remove it.
+ * @return the command to execute or null if this element can not host a documentation.
+ */
+ public Command getChangeDocumentationCommand(EObject eObject, String newDocumentation);
+
+ /**
+ * Returns an EMF Command to add an associated resource to the element.
+ *
+ * @param eObject
+ * The element where to add the associated resource.
+ * @param resourceURI
+ * the URI of the resource.
+ * @return the command to execute or null if this element can not host a documentation.
+ */
+ public Command getAddAssociatedResourceCommand(EObject eObject, URI resourceURI);
+
+ /**
+ * Returns an EMF Command to remove an associated resource from the element.
+ *
+ * @param eObject
+ * The element where to remove the associated resource.
+ * @param resourceURI
+ * the URI of the resource.
+ * @return the command to execute or null if this element can not host a documentation.
+ */
+ public Command getRemoveAssociatedResourceCommand(EObject eObject, URI resourceURI);
+
+ /**
+ * Returns the documentation of an element.
+ *
+ * @param eObject
+ * The element where to look for the documentation.
+ * @return The documentation or null if there is no documentation.
+ * @throws DocumentationUnsupportedException
+ * if documentation is not supported on this element.
+ */
+ public String getDocumentation(EObject eObject) throws DocumentationUnsupportedException;
+
+ /**
+ * Returns the associated resources of the element.
+ *
+ * @param eObject
+ * The element where to look for the associated resources.
+ * @return a list of resource URIs.
+ * @throws DocumentationUnsupportedException
+ * if documentation is not supported on this element.
+ */
+ public List<URI> getAssociatedResources(EObject eObject) throws DocumentationUnsupportedException;
+
+ /**
+ * Register a IDocumentationChangedListener (see {@link IDocumentationChangedListener}).
+ *
+ * @param listener
+ */
+ public void registerDocumentationChangedListener(IDocumentationChangedListener listener);
+
+ /**
+ * Unregister a IDocumentationChangedListener (see {@link IDocumentationChangedListener}).
+ *
+ * @param listener
+ */
+ public void unregisterDocumentationChangedListener(IDocumentationChangedListener listener);
+
+ /**
+ * @return the registered IDocumentationChangedListeners.
+ */
+ public Set<IDocumentationChangedListener> getRegisteredDocumentationChangedListeners();
+}
diff --git a/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/Messages.java b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/Messages.java
new file mode 100644
index 00000000000..5f8e5c45ec7
--- /dev/null
+++ b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/Messages.java
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.documentation;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.documentation.messages"; //$NON-NLS-1$
+
+ public static String AddOrRemoveAssociatedResourceCommandLabel;
+
+ public static String ChangeDocCommandLabel;
+
+ public static String DocumentationManager_UnsupportedModelType;
+
+ public static String EAnnotationDocumentationManager_DocOnDocEAnnotationError;
+
+ public static String EAnnotationDocumentationManager_NonEModelElementError;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/eannotation/AddOrRemoveAssociatedResourceCommand.java b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/eannotation/AddOrRemoveAssociatedResourceCommand.java
new file mode 100644
index 00000000000..99f1aaf4212
--- /dev/null
+++ b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/eannotation/AddOrRemoveAssociatedResourceCommand.java
@@ -0,0 +1,152 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.documentation.eannotation;
+
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.emf.common.command.AbstractCommand;
+import org.eclipse.emf.common.util.EMap;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EModelElement;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.papyrus.documentation.IDocumentationChangedListener;
+import org.eclipse.papyrus.documentation.Messages;
+
+
+public class AddOrRemoveAssociatedResourceCommand extends AbstractCommand {
+
+ private boolean remove;
+
+ private EModelElement element;
+
+ private Set<IDocumentationChangedListener> documentationChangedListeners;
+
+ private String prefix;
+
+ private String value;
+
+ public AddOrRemoveAssociatedResourceCommand(boolean remove, EModelElement element, URI resourceURI, Set<IDocumentationChangedListener> documentationChangedListeners) {
+ super(Messages.AddOrRemoveAssociatedResourceCommandLabel);
+ this.remove = remove;
+ this.element = element;
+ this.documentationChangedListeners = documentationChangedListeners;
+
+ if(resourceURI.isPlatform()) {
+ prefix = IEAnnotationConstants.PREFIX_WORKSPACE_RESOURCE;
+ value = resourceURI.toPlatformString(true);
+ } else if(resourceURI.isFile()) {
+ prefix = IEAnnotationConstants.PREFIX_EXTERNAL_RESOURCE;
+ value = resourceURI.toFileString();
+ } else {
+ prefix = IEAnnotationConstants.PREFIX_REMOTE_RESOURCE;
+ value = resourceURI.toString();
+ }
+ }
+
+ private void notifyListeners() {
+ for(IDocumentationChangedListener listener : documentationChangedListeners) {
+ listener.documentationChanged(element);
+ }
+ }
+
+ @Override
+ public boolean canExecute() {
+ return true;
+ }
+
+ @Override
+ public boolean canUndo() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void execute() {
+ redo();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void redo() {
+ if(remove) {
+ removeAssociatedResource();
+ } else {
+ addAssociatedResource();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void undo() {
+ if(remove) {
+ addAssociatedResource();
+ } else {
+ removeAssociatedResource();
+ }
+ }
+
+ private void addAssociatedResource() {
+ EAnnotation annotation = element.getEAnnotation(IEAnnotationConstants.ASSOCIATED_RESOURCES_SOURCE);
+ if(annotation == null) {
+ annotation = EcoreFactory.eINSTANCE.createEAnnotation();
+ annotation.setSource(IEAnnotationConstants.ASSOCIATED_RESOURCES_SOURCE);
+ element.getEAnnotations().add(annotation);
+ }
+ if(prefix != null && value != null) {
+ annotation.getDetails().put(getNewResourceKey(annotation, prefix, 0), value);
+ notifyListeners();
+ }
+ }
+
+ private void removeAssociatedResource() {
+ EAnnotation annotation = element.getEAnnotation(IEAnnotationConstants.ASSOCIATED_RESOURCES_SOURCE);
+ if(annotation != null && prefix != null && value != null) {
+ EMap<String, String> details = annotation.getDetails();
+ for(Entry<String, String> detail : details) {
+ if(detail.getKey() != null && detail.getKey().startsWith(prefix) && value.equals(detail.getValue())) {
+ details.remove(detail);
+ break;
+ }
+ }
+ if (details.isEmpty()) {
+ element.getEAnnotations().remove(annotation);
+ }
+ notifyListeners();
+ }
+ }
+
+ /**
+ * Recursively compute a new resource key using its prefix, a starting index and a map of resources to create. It
+ * also look in the existing resources to find a free index.
+ *
+ * @param resourcePrefix
+ * the resource prefix to use
+ * @param startIndex
+ * the start index (ie : 0)
+ * @return a new resource key
+ */
+ private String getNewResourceKey(EAnnotation annotation, String resourcePrefix, int startIndex) {
+ String key = resourcePrefix + startIndex;
+ if(annotation != null && annotation.getDetails().get(key) == null) {
+ return key;
+ }
+
+ return getNewResourceKey(annotation, resourcePrefix, startIndex + 1);
+ }
+}
diff --git a/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/eannotation/ChangeEAnnotationCommand.java b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/eannotation/ChangeEAnnotationCommand.java
new file mode 100644
index 00000000000..685dac00e1a
--- /dev/null
+++ b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/eannotation/ChangeEAnnotationCommand.java
@@ -0,0 +1,150 @@
+/***********************************************************************
+ * Copyright (c) 2008 Anyware Technologies
+ *
+ * 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:
+ * Jacques Lescot (Anyware Technologies) - initial API and implementation
+ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com
+ **********************************************************************/
+package org.eclipse.papyrus.documentation.eannotation;
+
+import java.util.Set;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.command.AbstractCommand;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EModelElement;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.papyrus.documentation.IDocumentationChangedListener;
+import org.eclipse.papyrus.documentation.Messages;
+
+/**
+ * A GEF Command use to update documentation EAnnotation when an EModelElement is selected.
+ *
+ * @author <a href="mailto:jacques.lescot@anyware-tech.com">Jacques LESCOT</a>
+ * @author <a href="mailto:sebastien.gabel@c-s.fr">Sebastien GABEL</a>
+ * @author Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com
+ */
+public class ChangeEAnnotationCommand extends AbstractCommand {
+
+ private EModelElement element;
+
+ private String newValue;
+
+ private String oldValue;
+
+ private String source;
+
+ private String key;
+
+ private Set<IDocumentationChangedListener> documentationChangedListeners;
+
+ /**
+ * Constructor
+ *
+ * @param element
+ * the EModelElement
+ * @param newValue
+ * the new documentation as a String
+ */
+ public ChangeEAnnotationCommand(EModelElement element, String source, String key, String newValue, Set<IDocumentationChangedListener> documentationChangedListeners) {
+ super(Messages.ChangeDocCommandLabel);
+ this.element = element;
+ this.source = source;
+ this.key = key;
+ this.newValue = newValue;
+ this.documentationChangedListeners = documentationChangedListeners;
+ }
+
+
+
+ @Override
+ public boolean canExecute() {
+ return true;
+ }
+
+
+
+ @Override
+ public boolean canUndo() {
+ return true;
+ }
+
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void execute() {
+ // stores the previous doc
+ oldValue = null;
+ EAnnotation annotation = element.getEAnnotation(source);
+ if(annotation != null) {
+ oldValue = annotation.getDetails().get(key);
+ }
+
+ redo();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void redo() {
+ changeDocumentation(element, newValue);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void undo() {
+ changeDocumentation(element, oldValue);
+ }
+
+ private void notifyListeners(String currentDoc) {
+ for (IDocumentationChangedListener listener : documentationChangedListeners) {
+ listener.documentationChanged(element);
+ }
+ }
+
+ /**
+ * Set the documentation for the given Model Element
+ *
+ * @param elt
+ * the element to document
+ * @param newDoc
+ * the documentation text
+ */
+ protected IStatus changeDocumentation(EModelElement elt, String newDoc) {
+ EAnnotation annotation = elt.getEAnnotation(source);
+ if(newDoc != null && !"".equals(newDoc)) { //$NON-NLS-1$
+ // creates EAnnotation if needed
+ if(annotation == null) {
+ annotation = EcoreFactory.eINSTANCE.createEAnnotation();
+ annotation.setSource(source);
+ elt.getEAnnotations().add(annotation);
+ }
+
+ annotation.getDetails().put(key, newDoc);
+ } else {
+ // remove the documentation
+ if(annotation != null) {
+ annotation.getDetails().remove(key);
+
+ // remove the EAnnotation if empty
+ if(annotation.getDetails().isEmpty()) {
+ elt.getEAnnotations().remove(annotation);
+ }
+ }
+ }
+ notifyListeners(newDoc);
+
+ return Status.OK_STATUS;
+ }
+
+}
diff --git a/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/eannotation/EAnnotationDocumentationManager.java b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/eannotation/EAnnotationDocumentationManager.java
new file mode 100644
index 00000000000..6f82703a657
--- /dev/null
+++ b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/eannotation/EAnnotationDocumentationManager.java
@@ -0,0 +1,161 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.documentation.eannotation;
+
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.util.EMap;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EModelElement;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.documentation.DocumentationUnsupportedException;
+import org.eclipse.papyrus.documentation.IDocumentationChangedListener;
+import org.eclipse.papyrus.documentation.IDocumentationManager;
+import org.eclipse.papyrus.documentation.Messages;
+
+
+public class EAnnotationDocumentationManager implements IDocumentationManager {
+
+ private static class EAnnotationDocumentationManagerHolder {
+
+ public static final EAnnotationDocumentationManager instance = new EAnnotationDocumentationManager();
+ }
+
+ public static EAnnotationDocumentationManager getInstance() {
+ return EAnnotationDocumentationManagerHolder.instance;
+ }
+
+ private static Set<IDocumentationChangedListener> documentationChangedListeners = new HashSet<IDocumentationChangedListener>();
+
+ /**
+ * {@inheritDoc}
+ */
+ public Command getChangeDocumentationCommand(EObject eObject, String newDocumentation) {
+ if(getUnsupportedErrorMessage(eObject) == null) {
+ return new ChangeEAnnotationCommand((EModelElement)eObject, IEAnnotationConstants.DOCUMENTATION_SOURCE, IEAnnotationConstants.DOCUMENTATION_KEY, newDocumentation, documentationChangedListeners);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getDocumentation(EObject eObject) throws DocumentationUnsupportedException {
+ String errorMsg = getUnsupportedErrorMessage(eObject);
+ if(errorMsg == null) {
+ EAnnotation annotation = ((EModelElement)eObject).getEAnnotation(IEAnnotationConstants.DOCUMENTATION_SOURCE);
+ if(annotation != null) {
+ return annotation.getDetails().get(IEAnnotationConstants.DOCUMENTATION_KEY);
+ }
+ return null;
+ } else {
+ throw new DocumentationUnsupportedException(errorMsg);
+ }
+ }
+
+ public Command getAddAssociatedResourceCommand(EObject eObject, URI resourceURI) {
+ if(getUnsupportedErrorMessage(eObject) == null) {
+ return new AddOrRemoveAssociatedResourceCommand(false, (EModelElement)eObject, resourceURI, documentationChangedListeners);
+ } else {
+ return null;
+ }
+ }
+
+ public Command getRemoveAssociatedResourceCommand(EObject eObject, URI resourceURI) {
+ if(getUnsupportedErrorMessage(eObject) == null) {
+ return new AddOrRemoveAssociatedResourceCommand(true, (EModelElement)eObject, resourceURI, documentationChangedListeners);
+ } else {
+ return null;
+ }
+ }
+
+ public List<URI> getAssociatedResources(EObject eObject) throws DocumentationUnsupportedException {
+ String errorMsg = getUnsupportedErrorMessage(eObject);
+ if(errorMsg == null) {
+ EAnnotation annotation = ((EModelElement)eObject).getEAnnotation(IEAnnotationConstants.ASSOCIATED_RESOURCES_SOURCE);
+ if(annotation != null) {
+ return convertDetailsToURIs(annotation.getDetails());
+ }
+ return new LinkedList<URI>();
+ } else {
+ throw new DocumentationUnsupportedException(errorMsg);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void registerDocumentationChangedListener(IDocumentationChangedListener listener) {
+ documentationChangedListeners.add(listener);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void unregisterDocumentationChangedListener(IDocumentationChangedListener listener) {
+ documentationChangedListeners.remove(listener);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<IDocumentationChangedListener> getRegisteredDocumentationChangedListeners() {
+ return documentationChangedListeners;
+ }
+
+ private static List<URI> convertDetailsToURIs(EMap<String, String> details) {
+ List<URI> uris = new LinkedList<URI>();
+ for(Entry<String, String> detail : details) {
+ String value = detail.getValue();
+
+ String prefix = detail.getKey().substring(0, 2);
+ URI uri = null;
+ if(IEAnnotationConstants.PREFIX_REMOTE_RESOURCE.equals(prefix)) {
+ uri = URI.createURI(value, false);
+ } else if(IEAnnotationConstants.PREFIX_EXTERNAL_RESOURCE.equals(prefix)) {
+ uri = URI.createFileURI(value);
+ } else if(IEAnnotationConstants.PREFIX_WORKSPACE_RESOURCE.equals(prefix)) {
+ uri = URI.createPlatformResourceURI(value, true);
+ }
+ uris.add(uri);
+ }
+ return uris;
+ }
+
+ /**
+ * get an error message if eObject is unsupported by this implementation
+ *
+ * @param eObject
+ * @return null if it is ok or an error message if not
+ */
+ private static String getUnsupportedErrorMessage(EObject eObject) {
+ // forbid doc on doc eannotation
+ if(eObject instanceof EAnnotation && ((EAnnotation)eObject).getSource().equals(IEAnnotationConstants.DOCUMENTATION_SOURCE)) {
+ return Messages.EAnnotationDocumentationManager_DocOnDocEAnnotationError;
+ // Check whether the element is an EModelElement
+ } else if(eObject instanceof EModelElement) {
+ // OK, return null
+ return null;
+ } else {
+ return Messages.EAnnotationDocumentationManager_NonEModelElementError;
+ }
+ }
+}
diff --git a/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/eannotation/IEAnnotationConstants.java b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/eannotation/IEAnnotationConstants.java
new file mode 100644
index 00000000000..4b89c9d7e77
--- /dev/null
+++ b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/eannotation/IEAnnotationConstants.java
@@ -0,0 +1,28 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.documentation.eannotation;
+
+public abstract interface IEAnnotationConstants {
+ public static final String DOCUMENTATION_SOURCE = "http://www.topcased.org/documentation"; //$NON-NLS-1$
+
+ public static final String DOCUMENTATION_KEY = "documentation"; //$NON-NLS-1$
+
+ public static final String ASSOCIATED_RESOURCES_SOURCE = "http://www.topcased.org/resources"; //$NON-NLS-1$
+
+ public static final String PREFIX_WORKSPACE_RESOURCE = "WR"; //$NON-NLS-1$
+
+ public static final String PREFIX_EXTERNAL_RESOURCE = "ER"; //$NON-NLS-1$
+
+ public static final String PREFIX_REMOTE_RESOURCE = "RR"; //$NON-NLS-1$
+}
diff --git a/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/messages.properties b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/messages.properties
new file mode 100644
index 00000000000..71288ecb6cf
--- /dev/null
+++ b/plugins/views/documentation/org.eclipse.papyrus.documentation/src/org/eclipse/papyrus/documentation/messages.properties
@@ -0,0 +1,5 @@
+AddOrRemoveAssociatedResourceCommandLabel=Add or remove associated resource
+ChangeDocCommandLabel=Change documentation
+DocumentationManager_UnsupportedModelType=Unsupported type of model
+EAnnotationDocumentationManager_DocOnDocEAnnotationError=Documentation on documentation EAnnotation unsupported
+EAnnotationDocumentationManager_NonEModelElementError=Documentation on non EModelElement unsupported by this implementation

Back to the top