Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2019-09-05 12:18:58 +0000
committerVincent Lorenzo2019-10-17 09:17:38 +0000
commit75864e3385cfd8db492b3674b5376e25475e9075 (patch)
treef6ac1f16e363fd5b0ee3a86c0b4129973f4f693f
parenta9757ba2f39dcf2ec7240312e1991c2e53a86581 (diff)
downloadorg.eclipse.papyrus-model2doc-75864e3385cfd8db492b3674b5376e25475e9075.tar.gz
org.eclipse.papyrus-model2doc-75864e3385cfd8db492b3674b5376e25475e9075.tar.xz
org.eclipse.papyrus-model2doc-75864e3385cfd8db492b3674b5376e25475e9075.zip
Bug 551916: [Model2Doc] add an API to create a TableOfFigures in the LibreOffice document
- create a Table Of Figures in the LibreOffice document - update documentation Change-Id: Ieb504142a8853d66371ac7117b0d455fbdc25af8 Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
-rwxr-xr-xplugins/core/org.eclipse.papyrus.model2doc.core/src/org/eclipse/papyrus/model2doc/core/internal/transcriber/UMLTranscriber.java2
-rwxr-xr-xplugins/core/org.eclipse.papyrus.model2doc.core/src/org/eclipse/papyrus/model2doc/core/transcription/Transcription.java13
-rwxr-xr-xplugins/doc/org.eclipse.papyrus.model2doc.doc/src/site/mediawiki/model2doc-userDoc.mediawiki4
-rwxr-xr-xplugins/odt/org.eclipse.papyrus.model2doc.odt.emf.structure2document/src/org/eclipse/papyrus/model2doc/odt/emf/structure2document/internal/transcriber/StructureToODTTranscriber.java26
-rwxr-xr-xplugins/odt/org.eclipse.papyrus.model2doc.odt/src/org/eclipse/papyrus/model2doc/odt/internal/editor/ODTEditor.java23
-rwxr-xr-xplugins/odt/org.eclipse.papyrus.model2doc.odt/src/org/eclipse/papyrus/model2doc/odt/internal/transcription/ODTTranscription.java96
6 files changed, 101 insertions, 63 deletions
diff --git a/plugins/core/org.eclipse.papyrus.model2doc.core/src/org/eclipse/papyrus/model2doc/core/internal/transcriber/UMLTranscriber.java b/plugins/core/org.eclipse.papyrus.model2doc.core/src/org/eclipse/papyrus/model2doc/core/internal/transcriber/UMLTranscriber.java
index dd9a05d6..11b6d70a 100755
--- a/plugins/core/org.eclipse.papyrus.model2doc.core/src/org/eclipse/papyrus/model2doc/core/internal/transcriber/UMLTranscriber.java
+++ b/plugins/core/org.eclipse.papyrus.model2doc.core/src/org/eclipse/papyrus/model2doc/core/internal/transcriber/UMLTranscriber.java
@@ -162,7 +162,7 @@ public class UMLTranscriber implements Transcriber {
}
- transcription.refreshTableOfContents();
+ transcription.refreshTablesOfIndexes();
// Save transcription
transcription.save(umlLabelInternationalization.getLabel(root));
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 d5cf9dd0..afff76f2 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
@@ -46,9 +46,18 @@ public interface Transcription {
public void writeTableOfContents(String tocTitle);
/**
- * Refresh the contents of the table Of Contents. Basically it must be called at the end of the transcription
+ * Write the Table of Figure
+ *
+ * @param tofTitle
+ * the title to use for the Table Of Figures
+ */
+ public void writeTableOfFigures(String tofTitle);
+
+ /**
+ * Refresh the contents of the table Of Contents, Table Of Index, ...
+ * Basically it must be called at the end of the transcription
*/
- public void refreshTableOfContents();
+ public void refreshTablesOfIndexes();
/**
* Write document main title.
diff --git a/plugins/doc/org.eclipse.papyrus.model2doc.doc/src/site/mediawiki/model2doc-userDoc.mediawiki b/plugins/doc/org.eclipse.papyrus.model2doc.doc/src/site/mediawiki/model2doc-userDoc.mediawiki
index a5575219..9e380172 100755
--- a/plugins/doc/org.eclipse.papyrus.model2doc.doc/src/site/mediawiki/model2doc-userDoc.mediawiki
+++ b/plugins/doc/org.eclipse.papyrus.model2doc.doc/src/site/mediawiki/model2doc-userDoc.mediawiki
@@ -65,8 +65,10 @@ Children of the '''TextDocumentTemplate''':
***''folder1/folder2/myTemplateFile'': interpreted as ''platform:/resource/currentPluginName/folder1/folder2/myTemplateFile'' : template owned by the current Eclipse project
***''platform:/plugin/aPluginName/aFolderName/myTemplatefile'' : the template is located in an installed Eclipse plugin
***''OS file system ''C:\aFolder\myTemplatefile'': the template is located somewhere in the file sytem
-*'''TableOfContents''': this element is used to declare that you want a TableOfContents
+*'''TableOfContents''': this element is used to declare that you want a Table Of Contents
**'''TocTitle''': the title to use for the TableOfContents. If nothing is defined, the table of contents will be name ''Table Of Contents'' in the generated file
+*'''TableOfFigures''': this element is used to declare that you want a Table Of Fiures
+**'''TofTitle''': the title to use for the TableOfFigures. If nothing is defined, the table of figures will be name ''Table Of Figures'' in the generated file
*'''Body''': The children of this element allows the definition of the document's content
*'''Author''': allows to define the authors of the document
diff --git a/plugins/odt/org.eclipse.papyrus.model2doc.odt.emf.structure2document/src/org/eclipse/papyrus/model2doc/odt/emf/structure2document/internal/transcriber/StructureToODTTranscriber.java b/plugins/odt/org.eclipse.papyrus.model2doc.odt.emf.structure2document/src/org/eclipse/papyrus/model2doc/odt/emf/structure2document/internal/transcriber/StructureToODTTranscriber.java
index 39753378..63b7303d 100755
--- a/plugins/odt/org.eclipse.papyrus.model2doc.odt.emf.structure2document/src/org/eclipse/papyrus/model2doc/odt/emf/structure2document/internal/transcriber/StructureToODTTranscriber.java
+++ b/plugins/odt/org.eclipse.papyrus.model2doc.odt.emf.structure2document/src/org/eclipse/papyrus/model2doc/odt/emf/structure2document/internal/transcriber/StructureToODTTranscriber.java
@@ -27,6 +27,7 @@ import org.eclipse.papyrus.model2doc.emf.documentstructure.Image;
import org.eclipse.papyrus.model2doc.emf.documentstructure.InsertedFile;
import org.eclipse.papyrus.model2doc.emf.documentstructure.Paragraph;
import org.eclipse.papyrus.model2doc.emf.documentstructure.TableOfContents;
+import org.eclipse.papyrus.model2doc.emf.documentstructure.TableOfFigures;
import org.eclipse.papyrus.model2doc.emf.documentstructure.TextDocument;
import org.eclipse.papyrus.model2doc.emf.documentstructure.TextDocumentPart;
import org.eclipse.papyrus.model2doc.emf.documentstructure.Title;
@@ -40,8 +41,6 @@ public class StructureToODTTranscriber implements Transcriber {
private TextDocument textDocument;
- private boolean refreshTableOfContents = false;
-
/**
*
* Constructor.
@@ -74,9 +73,7 @@ public class StructureToODTTranscriber implements Transcriber {
while (iter.hasNext()) {
transcribe(iter.next());
}
- if (this.refreshTableOfContents) {
- this.transcription.refreshTableOfContents();// TODO should be done directly by the transcriptor
- }
+ this.transcription.refreshTablesOfIndexes();// TODO should be done directly by the transcriptor
this.transcription.save(""); // TODO : remove this argument //$NON-NLS-1$
}
@@ -88,7 +85,9 @@ public class StructureToODTTranscriber implements Transcriber {
*/
private void transcribe(final TextDocumentPart part) {
if (part instanceof TableOfContents) {
- transcribeTableOfContent((TableOfContents) part);
+ transcribeTableOfContents((TableOfContents) part);
+ } else if (part instanceof TableOfFigures) {
+ transcribeTableOfFigures((TableOfFigures) part);
} else if (part instanceof Body) {
transcribeBody((Body) part);
}
@@ -118,8 +117,6 @@ public class StructureToODTTranscriber implements Transcriber {
private void transcribeBodyPart(final BodyPart bodyPart) {
if (bodyPart instanceof Title) {
transcribeTitle((Title) bodyPart);
- } else if (bodyPart instanceof TableOfContents) {
- transcribeTableOfContent((TableOfContents) bodyPart);
} else if (bodyPart instanceof Paragraph) {
transcribteParagraph((Paragraph) bodyPart);
} else if (bodyPart instanceof Image) {
@@ -167,9 +164,18 @@ public class StructureToODTTranscriber implements Transcriber {
* @param toc
* the table of contents
*/
- private void transcribeTableOfContent(final TableOfContents toc) {
+ private void transcribeTableOfContents(final TableOfContents toc) {
transcription.writeTableOfContents(toc.getTocTitle());
- this.refreshTableOfContents = true;
+ }
+
+ /**
+ * This method creates a table of figures in the output document
+ *
+ * @param toc
+ * the table of contents
+ */
+ private void transcribeTableOfFigures(final TableOfFigures tof) {
+ transcription.writeTableOfFigures(tof.getTofTitle());
}
/**
diff --git a/plugins/odt/org.eclipse.papyrus.model2doc.odt/src/org/eclipse/papyrus/model2doc/odt/internal/editor/ODTEditor.java b/plugins/odt/org.eclipse.papyrus.model2doc.odt/src/org/eclipse/papyrus/model2doc/odt/internal/editor/ODTEditor.java
index 5669afe0..e89cd217 100755
--- a/plugins/odt/org.eclipse.papyrus.model2doc.odt/src/org/eclipse/papyrus/model2doc/odt/internal/editor/ODTEditor.java
+++ b/plugins/odt/org.eclipse.papyrus.model2doc.odt/src/org/eclipse/papyrus/model2doc/odt/internal/editor/ODTEditor.java
@@ -31,6 +31,7 @@ import com.sun.star.beans.PropertyValue;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XController;
import com.sun.star.frame.XDesktop;
+import com.sun.star.frame.XDispatchHelper;
import com.sun.star.frame.XModel;
import com.sun.star.frame.XStorable;
import com.sun.star.io.IOException;
@@ -71,7 +72,13 @@ public class ODTEditor {
private XMultiComponentFactory xMultiComponentFactory = null;
private XMultiServiceFactory xMultiServiceFactory = null;
private XComponentContext xComponentContext = null;
- // private String projectFolder = null;
+
+ /**
+ * The dispatch helper (not yet used)
+ */
+ private XDispatchHelper dispatchHelper = null;
+
+
private ODTFileIOService fileIOService = null;
/**
@@ -102,6 +109,12 @@ public class ODTEditor {
final String templateURL = GeneratorConfigurationOperations.getTemplateFilePathInLocalPath(generatorConfig);
createTextDocument(templateURL);
xMultiServiceFactory = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
+ try {
+ Object dispatchHelperObject = this.xMultiComponentFactory.createInstanceWithContext("com.sun.star.frame.DispatchHelper", xComponentContext); //$NON-NLS-1$
+ this.dispatchHelper = UnoRuntime.queryInterface(XDispatchHelper.class, dispatchHelperObject);
+ } catch (com.sun.star.uno.Exception e) {
+ Activator.log.error(e);
+ }
}
}
@@ -560,5 +573,13 @@ public class ODTEditor {
return newFileURL;
}
+ /**
+ *
+ * @return
+ * the dispatch helper. This element can be called during the edition of the file to force a refresh
+ */
+ public final XDispatchHelper getDispatchHelper() {
+ return this.dispatchHelper;
+ }
}
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 beb91e60..e99ca98c 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
@@ -14,8 +14,10 @@
*****************************************************************************/
package org.eclipse.papyrus.model2doc.odt.internal.transcription;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
+import java.util.List;
import org.eclipse.emf.common.util.ECollections;
import org.eclipse.osgi.util.NLS;
@@ -53,6 +55,7 @@ import com.sun.star.document.XDocumentProperties;
import com.sun.star.document.XDocumentPropertiesSupplier;
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.XPageCursor;
@@ -71,6 +74,11 @@ import com.sun.star.uno.UnoRuntime;
*/
public class ODTTranscription implements Transcription {
+
+ private static final String TABLE_OF_FIGURE_TYPE = "com.sun.star.text.IllustrationsIndex"; //$NON-NLS-1$
+
+ private static final String TABLE_OF_CONTENTS_TYPE = "com.sun.star.text.ContentIndex"; //$NON-NLS-1$
+
/** The text interface contains all methods and properties to manipulate the content from a text document. */
private XText text = null;
@@ -87,7 +95,7 @@ public class ODTTranscription implements Transcription {
private StyleService styleService = null;
- private XDocumentIndex tableOfContents = null;
+ private List<XDocumentIndex> tablesOfIndexes = new ArrayList<>();
/**
* Constructor.
@@ -183,18 +191,39 @@ public class ODTTranscription implements Transcription {
* Refresh the table of contents
*/
@Override
- public void refreshTableOfContents() {
- if (null != this.tableOfContents) {
- this.tableOfContents.update();
+ public void refreshTablesOfIndexes() {
+ for (final XDocumentIndex current : this.tablesOfIndexes) {
+ current.update();
}
}
/**
+ * @see org.eclipse.papyrus.model2doc.core.transcription.Transcription#writeTableOfFigures(java.lang.String)
+ *
+ * @param tofTitle
+ */
+ @Override
+ public void writeTableOfFigures(String tofTitle) {
+ writePageOfContents(tofTitle, TABLE_OF_FIGURE_TYPE);
+ }
+
+ /**
* Create the table of contents
*/
@Override
public void writeTableOfContents(final String tocTitle) {
+ writePageOfContents(tocTitle, TABLE_OF_CONTENTS_TYPE);
+ }
+ /**
+ * Common method used to create a Table Of Contents or a Table of Figure
+ *
+ * @param pageTitle
+ * the title of the page
+ * @param libreOfficePagetype
+ * the type of the page to create
+ */
+ protected void writePageOfContents(final String pageTitle, final String libreOfficePagetype) {
// TODO improve me
// we should be able to start of not the table of contents on a new page
// we should be able to go to the next page at the end of the table of content
@@ -211,35 +240,18 @@ public class ODTTranscription implements Transcription {
XParagraphCursor xParaCursor = UnoRuntime.queryInterface(XParagraphCursor.class, mxDocCursor);
xParaCursor.gotoPreviousParagraph(false);// TODO : it was false before
- // Create a new ContentIndexMark and get its XPropertySet interface
- // XPropertySet xEntry;
-
- // xEntry = UnoRuntime.queryInterface(XPropertySet.class, mxDocFactory.createInstance("com.sun.star.text.ContentIndexMark"));
-
- //
- // // Set the text to be displayed in the index
- // xEntry.setPropertyValue("AlternativeText", "Big dogs! Falling on my head!");
-
- // The Level property _must_ be set
- // xEntry.setPropertyValue("Level", Short.valueOf((short) 1));
- // xEntry.setPropertyValue("Outline", true);
-
// Create a ContentIndex and access its XPropertySet interface
- XPropertySet xIndex = UnoRuntime.queryInterface(XPropertySet.class, mxDocFactory.createInstance("com.sun.star.text.ContentIndex")); //$NON-NLS-1$
-
- // Again, the Level property _must_ be set
- // xIndex.setPropertyValue("Level", Short.valueOf((short) 10));
+ XPropertySet xIndex = UnoRuntime.queryInterface(XPropertySet.class, mxDocFactory.createInstance(libreOfficePagetype)); // $NON-NLS-1$
// to fill the table of contents according to the existing title
- xIndex.setPropertyValue("CreateFromOutline", true); //$NON-NLS-1$
- // XPropertySetInfo set = xIndex.getPropertySetInfo();
- // for (Property tmp : set.getProperties()) {
- // System.out.println("prop Name " + tmp.Name);
- // System.out.println("prop attr " + tmp.Attributes);
- // System.out.println("prop type " + tmp.Type);
- // }
-
- xIndex.setPropertyValue("Title", tocTitle); //$NON-NLS-1$
+ if (TABLE_OF_CONTENTS_TYPE.equals(libreOfficePagetype)) {
+ xIndex.setPropertyValue("CreateFromOutline", true); //$NON-NLS-1$
+ } else if (TABLE_OF_FIGURE_TYPE.equals(libreOfficePagetype)) {
+ xIndex.setPropertyValue("CreateFromLabels", true); //$NON-NLS-1$
+ xIndex.setPropertyValue("LabelCategory", "Figure"); //$NON-NLS-1$
+ xIndex.setPropertyValue("LabelDisplayType", ChapterFormat.NAME_NUMBER); //$NON-NLS-1$
+ }
+ xIndex.setPropertyValue("Title", pageTitle); //$NON-NLS-1$
// Access the XTextContent interfaces of both the Index and the
// IndexMark
@@ -255,18 +267,7 @@ public class ODTTranscription implements Transcription {
// And call its update method
xDocIndex.update();
-
- tableOfContents = xDocIndex;
-
-
- // xParaCursor.gotoNextParagraph(true);
-
-
- // XText xText = mxDocCursor.getText();
- // xText.insertControlCharacter(mxDocCursor, (short)BreakType.PAGE_AFTER_value, false);
- // mxDocCursor.gotoEnd(false);
- // WriteUtil.addControlCharacter(xTextCursor, controlCharacter);addControlCharacter
-
+ tablesOfIndexes.add(xDocIndex);
writeService.endParagraph(xParaCursor);
@@ -275,17 +276,16 @@ public class ODTTranscription implements Transcription {
// TODO
cursorProperty.setPropertyValue("BreakType", BreakType.PAGE_BEFORE); //$NON-NLS-1$ //NONE AND BOTH gave me the same result... -> it is not good
// BEFORE Allow that the next content (an image) will be on the next page... it seems me stupid...
- } catch (Exception excp) {
- System.err.println("Failed to create page break. Exception: " + excp); //$NON-NLS-1$
- excp.printStackTrace(System.err);
+ } catch (Exception e) {
+ Activator.log.error("Failed to create page break. Exception: ", e); //$NON-NLS-1$
}
- //
} catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ Activator.log.error(e);
}
}
+
+
@Override
public void importImage(ImageDescription image, String caption) {
writeService.addImageLink(image, caption, cursor, odtEditor);

Back to the top