Bug 570927: [Model2Doc] the architecture model of ieee sysml odt reference documentview.ui elementtype
https://bugs.eclipse.org/bugs/show_bug.cgi?id=570927

Change-Id: Iaed3b6484a86e05dc0ca08b2dd7aec6cfd67766e
Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
diff --git a/plugins/doc/org.eclipse.papyrus.model2doc.doc/src/site/mediawiki/images/papyrusDevDoc/architecture/Architecture_002_SetLanguage.png b/plugins/doc/org.eclipse.papyrus.model2doc.doc/src/site/mediawiki/images/papyrusDevDoc/architecture/Architecture_002_SetLanguage.png
index 9a33a30..3ba4ced 100755
--- a/plugins/doc/org.eclipse.papyrus.model2doc.doc/src/site/mediawiki/images/papyrusDevDoc/architecture/Architecture_002_SetLanguage.png
+++ b/plugins/doc/org.eclipse.papyrus.model2doc.doc/src/site/mediawiki/images/papyrusDevDoc/architecture/Architecture_002_SetLanguage.png
Binary files differ
diff --git a/plugins/doc/org.eclipse.papyrus.model2doc.doc/src/site/mediawiki/model2doc-papyrusDevDoc.mediawiki b/plugins/doc/org.eclipse.papyrus.model2doc.doc/src/site/mediawiki/model2doc-papyrusDevDoc.mediawiki
index 464b842..9b3f1c0 100755
--- a/plugins/doc/org.eclipse.papyrus.model2doc.doc/src/site/mediawiki/model2doc-papyrusDevDoc.mediawiki
+++ b/plugins/doc/org.eclipse.papyrus.model2doc.doc/src/site/mediawiki/model2doc-papyrusDevDoc.mediawiki
@@ -12,6 +12,8 @@
 
 ====2. Set language====
 Select the domain element, open the contextual menu and select '''New Child > Description Language'''.
+The field '''Element types''' must reference the '''ElementTypeSetConfiguration''' called '''DocumentTemplateContext'''. This element type allows that when the semantic object from your UML model is destroyed by the user, the associated DocumentTemplate are destroyed too. 
+This element type to reference is provided by the file '''documenttemplate-context.elementtypesconfigurations''' inside the plugin '''org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types'''.
 
 [[Image:images/papyrusDevDoc/architecture/Architecture_002_SetLanguage.png]]
 ====3. Set viewpoints====
diff --git a/plugins/integration/ieee/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml14.odt.architecture/META-INF/MANIFEST.MF b/plugins/integration/ieee/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml14.odt.architecture/META-INF/MANIFEST.MF
index 3a39303..a0282cd 100755
--- a/plugins/integration/ieee/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml14.odt.architecture/META-INF/MANIFEST.MF
+++ b/plugins/integration/ieee/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml14.odt.architecture/META-INF/MANIFEST.MF
@@ -26,7 +26,8 @@
  org.eclipse.papyrus.uml.architecture;bundle-version="[2.0.0,3.0.0)",
  org.eclipse.papyrus.infra.tools;bundle-version="[4.0.0,5.0.0)",
  org.eclipse.papyrus.sysml14.architecture;bundle-version="[2.0.0,3.0.0)",
- org.eclipse.papyrus.infra.core.log;bundle-version="[2.0.0,3.0.0)"
+ org.eclipse.papyrus.infra.core.log;bundle-version="[2.0.0,3.0.0)",
+ org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types;bundle-version="[0.8.0,1.0.0)"
 Bundle-RequiredExecutionEnvironment: JavaSE-11
 Automatic-Module-Name: org.eclipse.papyrus.model2doc.integration.ieee.sysml14.architecture
 Bundle-ActivationPolicy: lazy
diff --git a/plugins/integration/ieee/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml14.odt.architecture/resources/odt_sysml14_ieee_requirements.architecture b/plugins/integration/ieee/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml14.odt.architecture/resources/odt_sysml14_ieee_requirements.architecture
index 1b150c1..c884a00 100755
--- a/plugins/integration/ieee/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml14.odt.architecture/resources/odt_sysml14_ieee_requirements.architecture
+++ b/plugins/integration/ieee/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml14.odt.architecture/resources/odt_sysml14_ieee_requirements.architecture
@@ -2,7 +2,7 @@
 <architecture:ArchitectureDomain xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:architecture="http://www.eclipse.org/papyrus/infra/core/architecture" xmlns:documentstructuretemplate="http://www.eclipse.org/papyrus/model2doc/emf/1.0.0/documentstructuretemplate" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:elementtypesconfigurations="http://www.eclipse.org/papyrus/infra/elementtypesconfigurations/1.2" xmlns:representation="http://www.eclipse.org/papyrus/model2doc/integration/1.0.0/emf/documentstructuretemplate/representation" xmlns:representation_1="http://www.eclipse.org/papyrus/infra/core/architecture/representation" xmi:id="_pNW38LaHEeiKuPQLywy7Og" id="org.eclipse.papyrus.sysml14.systemsEngineering" name="Systems Engineering" description="" icon="platform:/plugin/org.eclipse.papyrus.uml.architecture/icons/domain.gif">
   <contexts xmi:type="architecture:ArchitectureDescriptionLanguage" xmi:id="_-tAb0Lp2EeiViqj5DY8SRQ" id="org.eclipse.papyrus.sysml.architecture.SysML14" name="SysML 1.4" creationCommandClass="org.eclipse.papyrus.sysml14.architecture.CreateSysML14ModelCommand">
     <viewpoints xmi:type="architecture:ArchitectureViewpoint" xmi:id="_dmWHgLp3EeiViqj5DY8SRQ" id="org.eclipse.papyrus.sysml14.standard.modeling" name="Standard SysML Modeling" description="" icon="platform:/plugin/org.eclipse.papyrus.uml.architecture/icons/viewpoint.gif" representationKinds="_ftR7wE6KEeuipsE7blzx2g"/>
-    <elementTypes xmi:type="elementtypesconfigurations:ElementTypeSetConfiguration" href="platform:/plugin/org.eclipse.papyrus.model2doc.documentview.ui/resources/model/documentviewadvices.elementtypesconfigurations#_rWI4YHPzEeSnGJwaJWHCSg"/>
+    <elementTypes xmi:type="elementtypesconfigurations:ElementTypeSetConfiguration" href="platform:/plugin/org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types/resources/documenttemplate-context.elementtypesconfigurations#_--FKQKJQEemnzshfQ11WZw"/>
     <representationKinds xmi:type="representation:PapyrusDocumentPrototype" xmi:id="_ftR7wE6KEeuipsE7blzx2g" id="IEEE_For_Sysml14_ODT_DocumentStructureTemplateKindId" name="ODT - IEEE SysML 1.4 Requirements documentation" description="Generate IEEE Requirements document (.odt) from IEEE Requirements model." icon="platform:/plugin/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml14.odt.architecture/resources/icons/srs_document.png" implementationID="IEEE_For_Sysml14_ODT_DocumentStructureTemplateType" creationCommandClass="org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml14.odt.architecture.internal.commands.CreateIEEEDocumentTemplateEditorCommand">
       <modelRules xmi:type="representation_1:ModelRule" xmi:id="_1o_lIE6KEeuipsE7blzx2g" permit="true" elementMultiplicity="1" multiplicity="1">
         <element xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
diff --git a/plugins/integration/ieee/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml14.odt.architecture/src/org/eclipse/papyrus/model2doc/integration/ieee/requirements/sysml14/odt/architecture/Activator.java b/plugins/integration/ieee/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml14.odt.architecture/src/org/eclipse/papyrus/model2doc/integration/ieee/requirements/sysml14/odt/architecture/Activator.java
index 9e60a75..48a18ce 100755
--- a/plugins/integration/ieee/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml14.odt.architecture/src/org/eclipse/papyrus/model2doc/integration/ieee/requirements/sysml14/odt/architecture/Activator.java
+++ b/plugins/integration/ieee/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml14.odt.architecture/src/org/eclipse/papyrus/model2doc/integration/ieee/requirements/sysml14/odt/architecture/Activator.java
@@ -33,6 +33,12 @@
 	public static LogHelper log;
 
 	/**
+	 * to be sure we don't lose this dependency (required by the architecture file)
+	 */
+	@SuppressWarnings("unused")
+	private AbstractUIPlugin activator = org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types.Activator.getDefault();
+
+	/**
 	 * The constructor
 	 */
 	public Activator() {
diff --git a/plugins/integration/org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.representation/src/org/eclipse/papyrus/model2doc/integration/emf/documentstructuretemplate/representation/internal/custom/CustomPapyrusDocumentPrototypeImpl.java b/plugins/integration/org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.representation/src/org/eclipse/papyrus/model2doc/integration/emf/documentstructuretemplate/representation/internal/custom/CustomPapyrusDocumentPrototypeImpl.java
index 368d440..120fef9 100755
--- a/plugins/integration/org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.representation/src/org/eclipse/papyrus/model2doc/integration/emf/documentstructuretemplate/representation/internal/custom/CustomPapyrusDocumentPrototypeImpl.java
+++ b/plugins/integration/org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.representation/src/org/eclipse/papyrus/model2doc/integration/emf/documentstructuretemplate/representation/internal/custom/CustomPapyrusDocumentPrototypeImpl.java
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Copyright (c) 2020 CEA LIST and others.
+ * Copyright (c) 2020, 2021 CEA LIST and others.
  *
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
  *
  * Contributors:
  *   Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *   Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Bug 570927
  *
  *****************************************************************************/
 
@@ -17,13 +18,16 @@
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
+import java.util.Iterator;
 import java.util.Map;
 
 import org.eclipse.emf.common.util.BasicDiagnostic;
 import org.eclipse.emf.common.util.Diagnostic;
 import org.eclipse.emf.common.util.DiagnosticChain;
 import org.eclipse.osgi.util.NLS;
+import org.eclipse.papyrus.infra.core.architecture.ArchitectureDescriptionLanguage;
 import org.eclipse.papyrus.infra.tools.util.ClassLoaderHelper;
+import org.eclipse.papyrus.infra.types.ElementTypeSetConfiguration;
 import org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.representation.RepresentationPackage;
 import org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.representation.command.ICreateDocumentTemplateEditorCommand;
 import org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.representation.impl.PapyrusDocumentPrototypeImpl;
@@ -34,6 +38,18 @@
  */
 public class CustomPapyrusDocumentPrototypeImpl extends PapyrusDocumentPrototypeImpl {
 
+	// the 2 next field could be in org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types, but we want to avoid a dependency between these plugins
+	// TODO : try to solve this point
+	/**
+	 * the name of the required element type
+	 */
+	private static final String REQUIRED_ELEMENT_TYPE_NAME = "DocumentTemplateContext"; //$NON-NLS-1$
+
+	/**
+	 * the ID of the required element type
+	 */
+	private static final String REQUIRED_ELEMENT_TYPE_IDENTIFIER = "org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types.elementTypeSet"; //$NON-NLS-1$
+
 	/**
 	 * @see org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.representation.impl.PapyrusDocumentPrototypeImpl#isValidClass(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map)
 	 *
@@ -73,6 +89,20 @@
 			}
 		}
 
+		final ArchitectureDescriptionLanguage language = getLanguage();
+
+		// this test allows to check that the element type used to delete the DocumentStructure is registered
+		boolean contains = false;
+		final Iterator<ElementTypeSetConfiguration> iter = language.getElementTypes().iterator();
+		while (iter.hasNext() && !contains) {
+			final ElementTypeSetConfiguration type = iter.next();
+			contains = REQUIRED_ELEMENT_TYPE_IDENTIFIER.equals(type.getIdentifier())
+					&& REQUIRED_ELEMENT_TYPE_NAME.equals(type.getName());
+
+		}
+		if (!contains) {
+			chain.add(createDiagnostic(NLS.bind("The element type {0} is not registered in your architecture file.", REQUIRED_ELEMENT_TYPE_IDENTIFIER))); //$NON-NLS-1$
+		}
 
 		return super.isValidClass(chain, context);
 	}
diff --git a/plugins/integration/org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types/META-INF/MANIFEST.MF b/plugins/integration/org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types/META-INF/MANIFEST.MF
index 4e5db4f..c13e7ef 100755
--- a/plugins/integration/org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types/META-INF/MANIFEST.MF
+++ b/plugins/integration/org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types/META-INF/MANIFEST.MF
@@ -11,6 +11,9 @@
  org.eclipse.gmf.runtime.emf.type.core;bundle-version="[1.9.0,2.0.0)",
  org.eclipse.papyrus.infra.services.edit;bundle-version="[4.0.0,5.0.0)",
  org.eclipse.papyrus.model2doc.emf.documentstructuretemplate;bundle-version="[0.7.0,1.0.0)",
- org.eclipse.papyrus.infra.types;bundle-version="[5.0.0,6.0.0)"
-Export-Package: org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types.internal.advices
+ org.eclipse.papyrus.infra.types;bundle-version="[5.0.0,6.0.0)",
+ org.eclipse.ui.workbench;bundle-version="[3.122.0,4.0.0)"
+Export-Package: org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types,
+ org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types.internal.advices
 Bundle-ActivationPolicy: lazy
+Bundle-Activator: org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types.Activator
diff --git a/plugins/integration/org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types/src/org/eclipse/papyrus/model2doc/integration/emf/documentstructuretemplate/types/Activator.java b/plugins/integration/org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types/src/org/eclipse/papyrus/model2doc/integration/emf/documentstructuretemplate/types/Activator.java
new file mode 100755
index 0000000..6648bd4
--- /dev/null
+++ b/plugins/integration/org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types/src/org/eclipse/papyrus/model2doc/integration/emf/documentstructuretemplate/types/Activator.java
@@ -0,0 +1,60 @@
+/*****************************************************************************
+ * Copyright (c) 2021 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ *  Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types;
+
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+	// The plug-in ID
+	public static final String PLUGIN_ID = "org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types"; //$NON-NLS-1$
+
+	// The shared instance
+	private static Activator plugin;
+
+	/**
+	 * The constructor
+	 */
+	public Activator() {
+	}
+
+	@Override
+	public void start(BundleContext context) throws Exception {
+		super.start(context);
+		plugin = this;
+	}
+
+	@Override
+	public void stop(BundleContext context) throws Exception {
+		plugin = null;
+		super.stop(context);
+	}
+
+	/**
+	 * Returns the shared instance
+	 *
+	 * @return the shared instance
+	 */
+	public static Activator getDefault() {
+		return plugin;
+	}
+
+}
diff --git a/plugins/integration/org.eclipse.papyrus.model2doc.integration.odt.uml.architecture/META-INF/MANIFEST.MF b/plugins/integration/org.eclipse.papyrus.model2doc.integration.odt.uml.architecture/META-INF/MANIFEST.MF
index ef00c8b..c3490a0 100755
--- a/plugins/integration/org.eclipse.papyrus.model2doc.integration.odt.uml.architecture/META-INF/MANIFEST.MF
+++ b/plugins/integration/org.eclipse.papyrus.model2doc.integration.odt.uml.architecture/META-INF/MANIFEST.MF
@@ -11,7 +11,8 @@
  org.eclipse.papyrus.infra.architecture;bundle-version="[3.0.0,4.0.0)",
  org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.representation.architecture;bundle-version="[0.8.0,1.0.0)",
  org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.representation;bundle-version="[0.8.0,1.0.0)",
- org.eclipse.papyrus.model2doc.odt;bundle-version="[0.8.0,1.0.0)"
+ org.eclipse.papyrus.model2doc.odt;bundle-version="[0.8.0,1.0.0)",
+ org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types;bundle-version="[0.8.0,1.0.0)"
 Export-Package: org.eclipse.papyrus.model2doc.integration.odt.uml.architecture.internal.utils
 Bundle-Activator: org.eclipse.papyrus.model2doc.integration.odt.uml.architecture.Activator
 Bundle-ActivationPolicy: lazy
diff --git a/plugins/integration/org.eclipse.papyrus.model2doc.integration.odt.uml.architecture/src/org/eclipse/papyrus/model2doc/integration/odt/uml/architecture/Activator.java b/plugins/integration/org.eclipse.papyrus.model2doc.integration.odt.uml.architecture/src/org/eclipse/papyrus/model2doc/integration/odt/uml/architecture/Activator.java
index 7e08bc9..d552f51 100755
--- a/plugins/integration/org.eclipse.papyrus.model2doc.integration.odt.uml.architecture/src/org/eclipse/papyrus/model2doc/integration/odt/uml/architecture/Activator.java
+++ b/plugins/integration/org.eclipse.papyrus.model2doc.integration.odt.uml.architecture/src/org/eclipse/papyrus/model2doc/integration/odt/uml/architecture/Activator.java
@@ -28,6 +28,12 @@
 	private static Activator plugin;
 
 	/**
+	 * to be sure we don't lose this dependency (required by the architecture file)
+	 */
+	@SuppressWarnings("unused")
+	private AbstractUIPlugin activator = org.eclipse.papyrus.model2doc.integration.emf.documentstructuretemplate.types.Activator.getDefault();
+
+	/**
 	 * The constructor
 	 */
 	public Activator() {