Bug 570898: [Model2doc][IEEE] Update the IEEE ott template
- fix authors and version
- use main title field (main title is still written twice)
- fix pre-existing Table Of Contents refresh
- remove duplicateed Table Of Contents (we keep the Toc provided by the ott file and remove the Tox provided by the pdst template)
Change-Id: Id113001517acd66995049e107a741c30795dab22
Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
diff --git a/plugins/core/org.eclipse.papyrus.model2doc.core/src/org/eclipse/papyrus/model2doc/core/transcription/Transcription.java b/plugins/core/org.eclipse.papyrus.model2doc.core/src/org/eclipse/papyrus/model2doc/core/transcription/Transcription.java
index e953cbf..b406756 100755
--- a/plugins/core/org.eclipse.papyrus.model2doc.core/src/org/eclipse/papyrus/model2doc/core/transcription/Transcription.java
+++ b/plugins/core/org.eclipse.papyrus.model2doc.core/src/org/eclipse/papyrus/model2doc/core/transcription/Transcription.java
@@ -11,8 +11,8 @@
* Contributors:
* Yupanqui Munoz (CEA LIST) yupanqui.munozjulho@cea.fr - Initial API and implementation
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Bug 569249
- *
+ * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Bug 569249
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Bug 570898
*****************************************************************************/
package org.eclipse.papyrus.model2doc.core.transcription;
@@ -62,26 +62,53 @@
public void refreshTablesOfIndexes();
/**
- * Write document main title.
+ * Write document main title in the document.
*
* @param documentTitle
*/
public void writeDocumentMainTitle(String documentTitle);
+ /**
+ * this method registers the version of the document in its properties (Metadata)
+ *
+ * @param documentVersion
+ * the version of the document
+ */
+ public void setDocumentVersionProperty(String documentVersion);
+
+ /**
+ * this method registers the title of the document in its properties (Metadata)
+ *
+ * @param documentTitle
+ * the title of the document
+ */
+ public void setDocumentMaintTitleProperty(String documentTitle);
+
+ /**
+ * this method registers the authors of the document in its properties (Metadata)
+ *
+ * @param authors
+ * the authors of the document
+ */
+ public void setDocumentAuthorsProperty(final Collection<IAuthor> authors);
/**
* this method allows to define the authors of the document
*
* @param authors
* the authors of the document
+ * @deprecated use the method setDocumentAuthorsProperty instead
*/
+ @Deprecated(since = "0.8", forRemoval = true)
public void writeAuthors(final Collection<IAuthor> authors);
/**
*
* @param version
* the version of the document
+ * @deprecated use the method setDocumentVersionProperty instead
*/
+ @Deprecated(since = "0.8", forRemoval = true)
public void writeVersion(final String version);
/**
diff --git a/plugins/docx/org.eclipse.papyrus.model2doc.docx/src/org/eclipse/papyrus/model2doc/docx/internal/transcription/DocxTranscription.java b/plugins/docx/org.eclipse.papyrus.model2doc.docx/src/org/eclipse/papyrus/model2doc/docx/internal/transcription/DocxTranscription.java
index 1927ced..8dd7f08 100755
--- a/plugins/docx/org.eclipse.papyrus.model2doc.docx/src/org/eclipse/papyrus/model2doc/docx/internal/transcription/DocxTranscription.java
+++ b/plugins/docx/org.eclipse.papyrus.model2doc.docx/src/org/eclipse/papyrus/model2doc/docx/internal/transcription/DocxTranscription.java
@@ -206,14 +206,12 @@
@Override
public void writeAuthors(Collection<IAuthor> authors) {
- // TODO Auto-generated method stub
-
+ setDocumentAuthorsProperty(authors);
}
@Override
public void writeVersion(String version) {
- // TODO Auto-generated method stub
-
+ setDocumentVersionProperty(version);
}
@Override
@@ -542,4 +540,37 @@
// FIXME This method should be removed
}
+ /**
+ * @see org.eclipse.papyrus.model2doc.core.transcription.Transcription#setDocumentVersionProperty(java.lang.String)
+ *
+ * @param documentVersion
+ */
+ @Override
+ public void setDocumentVersionProperty(String documentVersion) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.model2doc.core.transcription.Transcription#setDocumentMaintTitleProperty(java.lang.String)
+ *
+ * @param documentTitle
+ */
+ @Override
+ public void setDocumentMaintTitleProperty(String documentTitle) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.model2doc.core.transcription.Transcription#setDocumentAuthorsProperty(java.util.Collection)
+ *
+ * @param authors
+ */
+ @Override
+ public void setDocumentAuthorsProperty(Collection<IAuthor> authors) {
+ // TODO Auto-generated method stub
+
+ }
+
}
diff --git a/plugins/emf/org.eclipse.papyrus.model2doc.emf.structure2document/src-api/org/eclipse/papyrus/model2doc/emf/structure2document/generator/transcriber/StructureToTranscriber.java b/plugins/emf/org.eclipse.papyrus.model2doc.emf.structure2document/src-api/org/eclipse/papyrus/model2doc/emf/structure2document/generator/transcriber/StructureToTranscriber.java
index 5648549..e533f61 100755
--- a/plugins/emf/org.eclipse.papyrus.model2doc.emf.structure2document/src-api/org/eclipse/papyrus/model2doc/emf/structure2document/generator/transcriber/StructureToTranscriber.java
+++ b/plugins/emf/org.eclipse.papyrus.model2doc.emf.structure2document/src-api/org/eclipse/papyrus/model2doc/emf/structure2document/generator/transcriber/StructureToTranscriber.java
@@ -9,9 +9,10 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - bug 568341
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - bug 570803
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - bug 568341
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - bug 570803
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Bug 570898
*****************************************************************************/
package org.eclipse.papyrus.model2doc.emf.structure2document.generator.transcriber;
@@ -66,10 +67,11 @@
public String transcribe() {
final String mainTitle = this.textDocument.getMainTitle();
if (mainTitle != null && !mainTitle.isEmpty()) {
+ this.transcription.setDocumentMaintTitleProperty(mainTitle);
this.transcription.writeDocumentMainTitle(mainTitle);
- this.transcription.writeAuthors(this.textDocument.getAuthors());
+ this.transcription.setDocumentAuthorsProperty(this.textDocument.getAuthors());
if (null != this.textDocument.getVersion()) {
- this.transcription.writeVersion(this.textDocument.getVersion().getVersion());
+ this.transcription.setDocumentVersionProperty(this.textDocument.getVersion().getVersion());
}
}
diff --git a/plugins/integration/ieee/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml16.odt.architecture/resources/ODT_IEEE_For_SysML16.pdst b/plugins/integration/ieee/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml16.odt.architecture/resources/ODT_IEEE_For_SysML16.pdst
index 0b957d4..e2efa05 100755
--- a/plugins/integration/ieee/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml16.odt.architecture/resources/ODT_IEEE_For_SysML16.pdst
+++ b/plugins/integration/ieee/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml16.odt.architecture/resources/ODT_IEEE_For_SysML16.pdst
@@ -3,7 +3,6 @@
<documentTemplate xmi:type="documentstructuretemplate:TextDocumentTemplate" xmi:id="_UyXLAadBEeqvT9U277n1TQ" documentTemplatePrototype="IEEE_For_Sysml16_ODT_DocumentStructureTemplate_Prototype" name="NewIEEEDocument" description="This template allows to create a Document conforms to IEEE specifications with a SysML16 profile." kindId="IEEE_For_Sysml16_ODT_DocumentStructureTemplateKindId" mainTitle="Requirements">
<documentStructureGeneratorConfiguration xmi:type="generatorconfiguration:DefaultDocumentStructureGeneratorConfiguration" xmi:id="_UyXLAqdBEeqvT9U277n1TQ" saveDocumentStructure="true" saveImages="true" templateFile="platform:/plugin/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml16.odt.architecture/resources/srs_template_ieee.ott" documentName="IEEE Document" documentFolder="output" documentGeneratorId="org.eclipse.papyrus.model2doc.document.generator.odt" structureGeneratorId="TextDocumentStructureGenerator.default" imageFolder="output/images" structureFolder="output"/>
<author xmi:type="author:Author" xmi:id="_UyXLA6dBEeqvT9U277n1TQ" firstName="Papyrus-Model2Doc" lastName="Generator"/>
- <documentPart xmi:type="documentstructuretemplate:TableOfContents" xmi:id="_UyXLBKdBEeqvT9U277n1TQ" tocTitle="Table Of Contents"/>
<documentPart xmi:type="documentstructuretemplate:Body" xmi:id="_UyXLBadBEeqvT9U277n1TQ">
<bodyPartTemplate xmi:type="documentstructuretemplate:EReferencePartTemplate" xmi:id="_UyXLBqdBEeqvT9U277n1TQ" generate="true" generateTitle="true" customTitle="Specific Requirements" generateIfEmpty="false" defaultTextIfEmpty="N/A">
<eReference xmi:type="ecore:EReference" href="http://www.eclipse.org/uml2/5.0.0/UML#//Package/nestedPackage"/>
diff --git a/plugins/integration/ieee/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml16.odt.architecture/resources/srs_template_ieee.ott b/plugins/integration/ieee/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml16.odt.architecture/resources/srs_template_ieee.ott
index 2924d38..cfd3413 100755
--- a/plugins/integration/ieee/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml16.odt.architecture/resources/srs_template_ieee.ott
+++ b/plugins/integration/ieee/org.eclipse.papyrus.model2doc.integration.ieee.requirements.sysml16.odt.architecture/resources/srs_template_ieee.ott
Binary files differ
diff --git a/plugins/odt/org.eclipse.papyrus.model2doc.odt/src/org/eclipse/papyrus/model2doc/odt/internal/transcription/ODTTranscription.java b/plugins/odt/org.eclipse.papyrus.model2doc.odt/src/org/eclipse/papyrus/model2doc/odt/internal/transcription/ODTTranscription.java
index 5765163..d0abfb8 100755
--- a/plugins/odt/org.eclipse.papyrus.model2doc.odt/src/org/eclipse/papyrus/model2doc/odt/internal/transcription/ODTTranscription.java
+++ b/plugins/odt/org.eclipse.papyrus.model2doc.odt/src/org/eclipse/papyrus/model2doc/odt/internal/transcription/ODTTranscription.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2019, 2020 CEA LIST.
+ * Copyright (c) 2019-2021 CEA LIST.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -11,8 +11,8 @@
* Contributors:
* Yupanqui Munoz (CEA LIST) yupanqui.munozjulho@cea.fr - Initial API and implementation
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Bug 569249
- *
+ * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Bug 569249
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Bug 570898
*****************************************************************************/
package org.eclipse.papyrus.model2doc.odt.internal.transcription;
@@ -55,13 +55,17 @@
import com.sun.star.beans.UnknownPropertyException;
import com.sun.star.beans.XPropertyContainer;
import com.sun.star.beans.XPropertySet;
+import com.sun.star.container.XIndexAccess;
import com.sun.star.document.XDocumentProperties;
import com.sun.star.document.XDocumentPropertiesSupplier;
+import com.sun.star.lang.IndexOutOfBoundsException;
+import com.sun.star.lang.WrappedTargetException;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.style.BreakType;
import com.sun.star.text.ChapterFormat;
import com.sun.star.text.ControlCharacter;
import com.sun.star.text.XDocumentIndex;
+import com.sun.star.text.XDocumentIndexesSupplier;
import com.sun.star.text.XPageCursor;
import com.sun.star.text.XParagraphCursor;
import com.sun.star.text.XText;
@@ -124,9 +128,30 @@
this.writeService = new WriteServiceImpl();
this.styleService = new StyleServiceImpl();
+
+ // find pre-existing Table of Contents to update at the end of the process
+ final XDocumentIndexesSupplier indexSupplier = UnoRuntime.queryInterface(XDocumentIndexesSupplier.class, odtEditor.getXTextDocument());
+ final XIndexAccess indexes = indexSupplier.getDocumentIndexes();
+ for (int i = 0; i < indexes.getCount(); i++) {
+ try {
+ final Object tmp = indexes.getByIndex(i);
+ XDocumentIndex documentIndex = UnoRuntime.queryInterface(XDocumentIndex.class, tmp);
+ if (documentIndex != null) {
+ this.tablesOfIndexes.add(documentIndex);
+ }
+ } catch (IndexOutOfBoundsException | WrappedTargetException e) {
+ Activator.log.error(e);
+ }
+ }
}
}
+ /**
+ *
+ * @see org.eclipse.papyrus.model2doc.core.transcription.Transcription#writeDocumentMainTitle(java.lang.String)
+ *
+ * @param documentTitle
+ */
@Override
public void writeDocumentMainTitle(String documentTitle) {
writeService.addText(cursor, documentTitle);
@@ -134,6 +159,25 @@
writeService.endParagraph(cursor);
}
+ /**
+ * @see org.eclipse.papyrus.model2doc.core.transcription.Transcription#setDocumentMaintTitleProperty(java.lang.String)
+ *
+ * @param documentTitle
+ */
+ @Override
+ public void setDocumentMaintTitleProperty(String documentTitle) {
+ if (null == documentTitle || documentTitle.isEmpty()) {
+ return;
+ }
+ // fill the LibreOffice variable used for document title
+ final XTextDocument document = odtEditor.getXTextDocument();
+ final XDocumentPropertiesSupplier xsDocProp = UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, document);
+ final XDocumentProperties props = xsDocProp.getDocumentProperties();
+ props.setTitle(documentTitle);
+ }
+
+
+
@Override
public void writeSectionTitle(String sectionTitle, int sectionLevel) {
writeService.addParagraph(cursor, sectionTitle, false);
@@ -343,35 +387,7 @@
*/
@Override
public void writeAuthors(final Collection<IAuthor> authors) {
- if (authors.size() > 0) {
- final XTextDocument document = odtEditor.getXTextDocument();
- final XDocumentPropertiesSupplier xsDocProp = UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, document);
- XDocumentProperties props = xsDocProp.getDocumentProperties();
- final Iterator<IAuthor> iterator = authors.iterator();
- String allAuthorsLabel = ""; //$NON-NLS-1$
- if (iterator.hasNext()) {
- final IAuthor firstAuthor = iterator.next();
- allAuthorsLabel = firstAuthor.buildMultiAuthorLabel(ECollections.toEList(authors));
- props.setAuthor(firstAuthor.buildAuthorLabel());
- }
-
- XPropertyContainer userDefined = props.getUserDefinedProperties();
-
- // we need to remove the property if it already exist, in order to be able to change its value
- try {
- userDefined.removeProperty(CustomFields.AUTHORS);
- } catch (UnknownPropertyException e) {
- // nothing to do. If the property doesn't exist, we probably get an exception for nothing!
- } catch (NotRemoveableException e) {
- Activator.log.error(e);
- }
-
- try {
- userDefined.addProperty(CustomFields.AUTHORS, PropertyAttribute.REMOVABLE, allAuthorsLabel);
- } catch (IllegalArgumentException | PropertyExistException | IllegalTypeException e) {
- Activator.log.error(e);
- }
- }
+ setDocumentAuthorsProperty(authors);
}
/**
@@ -381,28 +397,7 @@
*/
@Override
public void writeVersion(final String version) {
- if (null == version || version.isEmpty()) {
- return;
- }
-
- final XTextDocument document = odtEditor.getXTextDocument();
- final XDocumentPropertiesSupplier xsDocProp = UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, document);
- final XDocumentProperties props = xsDocProp.getDocumentProperties();
-
- XPropertyContainer userDefined = props.getUserDefinedProperties();
-
- // we need to remove the property if it already exist, in order to be change its value
- try {
- userDefined.removeProperty(CustomFields.VERSION);
- } catch (UnknownPropertyException | NotRemoveableException e) {
- // nothing to do
- }
-
- try {
- userDefined.addProperty(CustomFields.VERSION, PropertyAttribute.REMOVABLE, version);
- } catch (IllegalArgumentException | PropertyExistException | IllegalTypeException e) {
- Activator.log.error(e);
- }
+ setDocumentVersionProperty(version);
}
/**
@@ -466,5 +461,75 @@
BEFORE, AFTER, BOTH
}
+ /**
+ * @see org.eclipse.papyrus.model2doc.core.transcription.Transcription#setDocumentVersionProperty(java.lang.String)
+ *
+ * @param version
+ */
+ @Override
+ public void setDocumentVersionProperty(final String version) {
+ if (null == version || version.isEmpty()) {
+ return;
+ }
+
+ final XTextDocument document = odtEditor.getXTextDocument();
+ final XDocumentPropertiesSupplier xsDocProp = UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, document);
+ final XDocumentProperties props = xsDocProp.getDocumentProperties();
+
+ XPropertyContainer userDefined = props.getUserDefinedProperties();
+
+ // we need to remove the property if it already exist, in order to be change its value
+ try {
+ userDefined.removeProperty(CustomFields.VERSION);
+ } catch (UnknownPropertyException | NotRemoveableException e) {
+ // nothing to do
+ }
+
+ try {
+ userDefined.addProperty(CustomFields.VERSION, PropertyAttribute.REMOVABLE, version);
+ } catch (IllegalArgumentException | PropertyExistException | IllegalTypeException e) {
+ Activator.log.error(e);
+ }
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.model2doc.core.transcription.Transcription#setDocumentAuthorsProperty(java.util.Collection)
+ *
+ * @param authors
+ */
+ @Override
+ public void setDocumentAuthorsProperty(Collection<IAuthor> authors) {
+ if (authors.size() > 0) {
+ final XTextDocument document = odtEditor.getXTextDocument();
+ final XDocumentPropertiesSupplier xsDocProp = UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, document);
+ XDocumentProperties props = xsDocProp.getDocumentProperties();
+ final Iterator<IAuthor> iterator = authors.iterator();
+ String allAuthorsLabel = ""; //$NON-NLS-1$
+ if (iterator.hasNext()) {
+ final IAuthor firstAuthor = iterator.next();
+ allAuthorsLabel = firstAuthor.buildMultiAuthorLabel(ECollections.toEList(authors));
+ props.setAuthor(firstAuthor.buildAuthorLabel());
+ }
+
+ XPropertyContainer userDefined = props.getUserDefinedProperties();
+
+ // we need to remove the property if it already exist, in order to be able to change its value
+ try {
+ userDefined.removeProperty(CustomFields.AUTHORS);
+ } catch (UnknownPropertyException e) {
+ // nothing to do. If the property doesn't exist, we probably get an exception for nothing!
+ } catch (NotRemoveableException e) {
+ Activator.log.error(e);
+ }
+
+ try {
+ userDefined.addProperty(CustomFields.AUTHORS, PropertyAttribute.REMOVABLE, allAuthorsLabel);
+ } catch (IllegalArgumentException | PropertyExistException | IllegalTypeException e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+
}