Bug 569064 - [Model2Doc][Docx] When the table column or row header is
not generated the style should be different
Create 4 different styles :
* row and column header
* row header only
* column header only
* no header
Signed-off-by: Pauline DEVILLE <pauline.deville@cea.fr>
Change-Id: Iedb5772d6fb44d1a04091a7503fd06a251676b66
diff --git a/plugins/docx/org.eclipse.papyrus.model2doc.docx/src/org/eclipse/papyrus/model2doc/docx/services/StyleServiceImpl.java b/plugins/docx/org.eclipse.papyrus.model2doc.docx/src/org/eclipse/papyrus/model2doc/docx/internal/services/StyleServiceImpl.java
similarity index 71%
rename from plugins/docx/org.eclipse.papyrus.model2doc.docx/src/org/eclipse/papyrus/model2doc/docx/services/StyleServiceImpl.java
rename to plugins/docx/org.eclipse.papyrus.model2doc.docx/src/org/eclipse/papyrus/model2doc/docx/internal/services/StyleServiceImpl.java
index 1307a61..cfaf24e 100755
--- a/plugins/docx/org.eclipse.papyrus.model2doc.docx/src/org/eclipse/papyrus/model2doc/docx/services/StyleServiceImpl.java
+++ b/plugins/docx/org.eclipse.papyrus.model2doc.docx/src/org/eclipse/papyrus/model2doc/docx/internal/services/StyleServiceImpl.java
@@ -11,14 +11,20 @@
* Contributors:
* Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation
*****************************************************************************/
-package org.eclipse.papyrus.model2doc.docx.services;
+package org.eclipse.papyrus.model2doc.docx.internal.services;
+
+import java.util.List;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.papyrus.model2doc.core.builtintypes.AbstractTable;
+import org.eclipse.papyrus.model2doc.core.builtintypes.CellLocation;
+import org.eclipse.papyrus.model2doc.core.builtintypes.Row;
import org.eclipse.papyrus.model2doc.docx.Activator;
import org.eclipse.papyrus.model2doc.docx.internal.util.StyleConstants;
+import org.eclipse.papyrus.model2doc.docx.services.StyleService;
public class StyleServiceImpl implements StyleService {
@@ -50,16 +56,45 @@
}
/**
- * @see org.eclipse.papyrus.model2doc.docx.services.StyleService#applyTableStyle(org.apache.poi.xwpf.usermodel.XWPFTable, XWPFDocument)
+ * @see org.eclipse.papyrus.model2doc.docx.services.StyleService#applyTableStyle(org.apache.poi.xwpf.usermodel.XWPFTable, XWPFDocument, String)
*
- * @param table
+ * @param xwpfTable
+ * @param document
+ * @param tableDescription
* @return
*/
@Override
- public boolean applyTableStyle(XWPFTable table, XWPFDocument document) {
- String styleName = StyleConstants.TABLE_STYLE_VALUE;
+ public boolean applyTableStyle(XWPFTable xwpfTable, XWPFDocument document, AbstractTable tableDescription) {
+ String styleName;
+ boolean isRowHeader = false;
+ boolean isColumnHeader = false;
+ if (tableDescription.getRowsNumber() != 0) {
+ List<Row> rows = tableDescription.getRows();
+ isRowHeader = rows.stream()
+ .allMatch(
+ r -> r.getCells().get(0).getLocation().equals(CellLocation.ROW_HEADER)
+ || r.getCells().get(0).getLocation().equals(CellLocation.CORNER));
+ }
+ if (tableDescription.getColumnsNumber() != 0) {
+ List<Row> rows = tableDescription.getRows();
+ isColumnHeader = rows.get(0).getCells().stream()
+ .allMatch(
+ c -> c.getLocation() == CellLocation.COLUMN_HEADER
+ || c.getLocation() == CellLocation.CORNER);
+ }
+
+ if (isRowHeader && isColumnHeader) {
+ styleName = StyleConstants.ROW_AND_COLUMN_HEADER_STYLE_VALUE;
+ } else if (isRowHeader) {
+ styleName = StyleConstants.ROW_HEADER_ONLY_STYLE_VALUE;
+ } else if (isColumnHeader) {
+ styleName = StyleConstants.COLUMN_HEADER_ONLY_STYLE_VALUE;
+ } else {
+ styleName = StyleConstants.NO_HEADER_STYLE_VALUE;
+ }
+
if (document.getStyles().styleExist(styleName)) {
- table.setStyleID(styleName);
+ xwpfTable.setStyleID(styleName);
return true;
}
Activator.log.warn(NLS.bind("the style {0} does not exist in the template file", styleName)); //$NON-NLS-1$
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 5a62438..da2eea5 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
@@ -47,9 +47,9 @@
import org.eclipse.papyrus.model2doc.docx.Activator;
import org.eclipse.papyrus.model2doc.docx.Messages;
import org.eclipse.papyrus.model2doc.docx.internal.poi.CustomXWPFDocument;
+import org.eclipse.papyrus.model2doc.docx.internal.services.StyleServiceImpl;
import org.eclipse.papyrus.model2doc.docx.internal.util.ImageUtils;
import org.eclipse.papyrus.model2doc.docx.services.StyleService;
-import org.eclipse.papyrus.model2doc.docx.services.StyleServiceImpl;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSimpleField;
@@ -61,7 +61,7 @@
private CustomXWPFDocument document;
- private StyleService styleService;
+ protected StyleService styleService;
private int imageIndex = 1;
@@ -198,7 +198,6 @@
// create and fill the table
XWPFTable xwpfTable = document.createTable(rowsNumber, colNumbers);
- styleService.applyTableStyle(xwpfTable, document);
Iterator<Row> rowIter = table.getRows().iterator();
int rowNumber = 0;
while (rowIter.hasNext()) {
@@ -215,6 +214,10 @@
}
rowNumber++;
}
+
+ // apply style
+
+ styleService.applyTableStyle(xwpfTable, document, table);
}
@Override
diff --git a/plugins/docx/org.eclipse.papyrus.model2doc.docx/src/org/eclipse/papyrus/model2doc/docx/internal/util/StyleConstants.java b/plugins/docx/org.eclipse.papyrus.model2doc.docx/src/org/eclipse/papyrus/model2doc/docx/internal/util/StyleConstants.java
index 7028033..395ccb6 100755
--- a/plugins/docx/org.eclipse.papyrus.model2doc.docx/src/org/eclipse/papyrus/model2doc/docx/internal/util/StyleConstants.java
+++ b/plugins/docx/org.eclipse.papyrus.model2doc.docx/src/org/eclipse/papyrus/model2doc/docx/internal/util/StyleConstants.java
@@ -28,10 +28,16 @@
public static final String SECTION_STYLE_PREFIX = "Titre"; //$NON-NLS-1$
- public static final String TABLE_STYLE_VALUE = "Grilledutableau"; //$NON-NLS-1$
-
public static final String CAPTION_STYLE_VALUE = "Lgende"; //$NON-NLS-1$
+ public static final String ROW_AND_COLUMN_HEADER_STYLE_VALUE = "TableStyleWithBothHeader"; //$NON-NLS-1$
+
+ public static final String ROW_HEADER_ONLY_STYLE_VALUE = "TableStyleWithRowHeaderOnly"; //$NON-NLS-1$
+
+ public static final String COLUMN_HEADER_ONLY_STYLE_VALUE = "TableStyleWithColumnHeaderOnly"; //$NON-NLS-1$
+
+ public static final String NO_HEADER_STYLE_VALUE = "TableWithoutHeader"; //$NON-NLS-1$
+
/**
* Constructor.
*
diff --git a/plugins/docx/org.eclipse.papyrus.model2doc.docx/src/org/eclipse/papyrus/model2doc/docx/services/StyleService.java b/plugins/docx/org.eclipse.papyrus.model2doc.docx/src/org/eclipse/papyrus/model2doc/docx/services/StyleService.java
index 11e48e4..b1d4a49 100755
--- a/plugins/docx/org.eclipse.papyrus.model2doc.docx/src/org/eclipse/papyrus/model2doc/docx/services/StyleService.java
+++ b/plugins/docx/org.eclipse.papyrus.model2doc.docx/src/org/eclipse/papyrus/model2doc/docx/services/StyleService.java
@@ -16,6 +16,7 @@
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFTable;
+import org.eclipse.papyrus.model2doc.core.builtintypes.AbstractTable;
public interface StyleService {
@@ -43,12 +44,14 @@
/**
* Apply the style to the table
*
- * @param table
+ * @param xwpfTable
* the table on which the style will be applied
* @param document
* the document owning the table
+ * @param tableDescription
+ * the description of the table
*/
- boolean applyTableStyle(XWPFTable table, XWPFDocument document);
+ boolean applyTableStyle(XWPFTable xwpfTable, XWPFDocument document, AbstractTable tableDescription);
/**
* Apply the caption style to the paragraph
diff --git a/plugins/docx/org.eclipse.papyrus.model2doc.docx/templates/PapyrusTemplate.dotx b/plugins/docx/org.eclipse.papyrus.model2doc.docx/templates/PapyrusTemplate.dotx
index af0a8d5..898eb40 100755
--- a/plugins/docx/org.eclipse.papyrus.model2doc.docx/templates/PapyrusTemplate.dotx
+++ b/plugins/docx/org.eclipse.papyrus.model2doc.docx/templates/PapyrusTemplate.dotx
Binary files differ