diff --git a/org.gecko.emf.exporter.ods.tests/test.bndrun b/org.gecko.emf.exporter.ods.tests/test.bndrun index 5213a5c6..29ef1b41 100644 --- a/org.gecko.emf.exporter.ods.tests/test.bndrun +++ b/org.gecko.emf.exporter.ods.tests/test.bndrun @@ -43,8 +43,8 @@ org.gecko.emf.util.model;version=snapshot,\ org.osgi.service.cm;version='[1.6.0,1.6.1)',\ com.github.miachm.sods;version='[1.5.3,1.5.4)',\ - org.gecko.emf.ods;version=snapshot,\ - org.gecko.emf.pushstreams;version=snapshot + org.gecko.emf.pushstreams;version=snapshot,\ + com.fasterxml.jackson.datatype.jackson-datatype-jsr310;version='[2.14.1,2.14.2)' -runrequires: bnd.identity;id='org.gecko.emf.exporter.ods.tests' diff --git a/org.gecko.emf.exporter.ods/src/org/gecko/emf/exporter/ods/EMFODSExporter.java b/org.gecko.emf.exporter.ods/src/org/gecko/emf/exporter/ods/EMFODSExporter.java index 5a5b7040..aa14b2b4 100644 --- a/org.gecko.emf.exporter.ods/src/org/gecko/emf/exporter/ods/EMFODSExporter.java +++ b/org.gecko.emf.exporter.ods/src/org/gecko/emf/exporter/ods/EMFODSExporter.java @@ -80,6 +80,8 @@ public class EMFODSExporter implements EMFExporter { "Default value", "Documentation"); private static final List METADATA_EENUM_SHEET_HEADERS = List.of("Name", "Literal", "Value", "Documentation"); + private static final String METADATA_DOCUMENTATION_HEADER = "Documentation"; + private static final String METADATA_SHEET_SUFFIX = "Metadata"; private static final String MAPPING_TABLE_SHEET_SUFFIX = "Mapping Table"; @@ -174,7 +176,7 @@ public void exportEObjectsTo(List eObjects, OutputStream outputStream, // @formatter:on if (exportMetadataEnabled(exportOptions)) { - exportMetadata(document, eObjectsClasses, eObjectsEnums); + exportMetadata(document, eObjectsClasses, eObjectsEnums, exportOptions); } document.save(outputStream); @@ -537,7 +539,9 @@ private void createSheetHeaderCell(Range sheetHeaderRow, int colIndex, String sh } private void adjustColumnWidth(Sheet sheet, int colIndex, int charsCount) { - sheet.setColumnWidth(colIndex, calculateColumnWidth(charsCount)); + if (sheet.getColumnWidth(colIndex) == null) { + sheet.setColumnWidth(colIndex, calculateColumnWidth(charsCount)); + } } private Double calculateColumnWidth(int charsCount) { @@ -552,7 +556,8 @@ private Double calculateRowHeight(String value) { return (Double.valueOf(value.length() / MAX_CHAR_PER_LINE_DEFAULT) * 5); } - @Deprecated + + @SuppressWarnings("unused") private void freezeSheetHeaderRow(Sheet sheet, int rowCount, int colCount) { // TODO: freezing rows is currently not supported in SODS } @@ -937,7 +942,9 @@ private boolean addMappingTableEnabled(Map exportOptions) { private boolean freezeHeaderRowEnabled(Map exportOptions) { // TODO: freezing rows is currently not supported in SODS - // return ((boolean) exportOptions.getOrDefault(EMFExportOptions.OPTION_FREEZE_HEADER_ROW, Boolean.FALSE)); + // return ((boolean) + // exportOptions.getOrDefault(EMFExportOptions.OPTION_FREEZE_HEADER_ROW, + // Boolean.FALSE)); return false; } @@ -959,56 +966,113 @@ private Sheet addMetadataSheet(SpreadSheet document, EEnum eEnum) { return metadataSheet; } - private void exportMetadata(SpreadSheet document, Set eClasses, Set eEnums) { - exportEClassesMetadata(document, eClasses); - exportEEnumsMetadata(document, eEnums); + private void exportMetadata(SpreadSheet document, Set eClasses, Set eEnums, + Map exportOptions) { + exportEClassesMetadata(document, eClasses, exportOptions); + exportEEnumsMetadata(document, eEnums, exportOptions); } - private void exportEClassesMetadata(SpreadSheet document, Set eClasses) { + private void exportEClassesMetadata(SpreadSheet document, Set eClasses, Map exportOptions) { for (EClass eClass : eClasses) { - Sheet metadataSheet = document.getSheet(constructEClassMetadataSheetName(eClass)); - createEClassMetadataSheetHeader(metadataSheet); + maybeSetEClassMetadataDocumentation(metadataSheet, eClass, exportOptions); + + createEClassMetadataSheetHeader(metadataSheet, exportOptions); createEClassMetadataSheetData(metadataSheet, eClass); } } - private void exportEEnumsMetadata(SpreadSheet document, Set eEnums) { + private void exportEEnumsMetadata(SpreadSheet document, Set eEnums, Map exportOptions) { for (EEnum eEnum : eEnums) { - Sheet metadataSheet = addMetadataSheet(document, eEnum); - createEEnumMetadataSheetHeader(metadataSheet); + maybeSetEEnumMetadataDocumentationValueCell(metadataSheet, eEnum, exportOptions); + + createEEnumMetadataSheetHeader(metadataSheet, exportOptions); createEEnumMetadataSheetData(metadataSheet, eEnum); } } - private void createEClassMetadataSheetHeader(Sheet metadataSheet) { - createMetadataSheetHeader(metadataSheet, METADATA_ECLASS_SHEET_HEADERS); + private void maybeSetEClassMetadataDocumentation(Sheet metadataSheet, EClass eClass, + Map exportOptions) { + EAnnotation genModelAnnotation = eClass.getEAnnotation(DOCUMENTATION_GENMODEL_SOURCE); + if (genModelAnnotation != null) { + setTypeLevelMetadataDocumentation(metadataSheet, genModelAnnotation, exportOptions); + } } - private void createEEnumMetadataSheetHeader(Sheet metadataSheet) { - createMetadataSheetHeader(metadataSheet, METADATA_EENUM_SHEET_HEADERS); + private void setEClassMetadataDocumentationValueCell(Range metadataSheetDataRow, + Map exportOptions) { + metadataSheetDataRow.getCell(0, 0).setValue(METADATA_DOCUMENTATION_HEADER); + metadataSheetDataRow.getCell(0, 0).setStyle(HEADER_STYLE); + + if (adjustColumnWidthEnabled(exportOptions)) { + adjustColumnWidth(metadataSheetDataRow.getSheet(), 0, + adjustColumnWidthCharsCount(METADATA_DOCUMENTATION_HEADER)); + } } - private void createMetadataSheetHeader(Sheet metadataSheet, List headers) { + private void maybeSetEEnumMetadataDocumentationValueCell(Sheet metadataSheet, EEnum eEnum, + Map exportOptions) { + EAnnotation genModelAnnotation = eEnum.getEAnnotation(DOCUMENTATION_GENMODEL_SOURCE); + if (genModelAnnotation != null) { + setTypeLevelMetadataDocumentation(metadataSheet, genModelAnnotation, exportOptions); + } + } + + private void setTypeLevelMetadataDocumentation(Sheet metadataSheet, EAnnotation genModelAnnotation, + Map exportOptions) { + Map genModelAnnotationDetails = genModelAnnotation.getDetails().map(); + + if (genModelAnnotationDetails.containsKey(DOCUMENTATION_GENMODEL_DETAILS)) { + + metadataSheet.appendColumn(); + + Range metadataSheetDocumentationRow = metadataSheet.getRange((metadataSheet.getMaxRows() - 1), 0, 1, 2); + + setEClassMetadataDocumentationValueCell(metadataSheetDocumentationRow, exportOptions); + + setMetadataDocumentationValueCell(metadataSheetDocumentationRow, 1, + genModelAnnotationDetails.get(DOCUMENTATION_GENMODEL_DETAILS)); + + metadataSheet.appendRow(); + } + } + + private void createEClassMetadataSheetHeader(Sheet metadataSheet, Map exportOptions) { + createMetadataSheetHeader(metadataSheet, METADATA_ECLASS_SHEET_HEADERS, exportOptions); + } + + private void createEEnumMetadataSheetHeader(Sheet metadataSheet, Map exportOptions) { + createMetadataSheetHeader(metadataSheet, METADATA_EENUM_SHEET_HEADERS, exportOptions); + } + + private void createMetadataSheetHeader(Sheet metadataSheet, List headers, + Map exportOptions) { int columnsCount = headers.size(); - metadataSheet.appendColumns(columnsCount - 1); + metadataSheet.appendColumns(columnsCount - metadataSheet.getMaxColumns()); + + Range metadataSheetHeaderRow = metadataSheet.getRange((metadataSheet.getMaxRows() - 1), 0, 1, + metadataSheet.getMaxColumns()); - Range metadataSheetHeaderRow = metadataSheet.getRange(0, 0, 1, metadataSheet.getMaxColumns()); metadataSheetHeaderRow.setStyle(HEADER_STYLE); for (int colIndex = 0; colIndex < metadataSheet.getMaxColumns(); colIndex++) { - createMetadataSheetHeaderCell(metadataSheetHeaderRow, colIndex, headers.get(colIndex)); + createMetadataSheetHeaderCell(metadataSheetHeaderRow, colIndex, headers.get(colIndex), exportOptions); } } - private void createMetadataSheetHeaderCell(Range metadataSheetHeaderRow, int colIndex, String headerName) { + private void createMetadataSheetHeaderCell(Range metadataSheetHeaderRow, int colIndex, String headerName, + Map exportOptions) { metadataSheetHeaderRow.getCell(0, colIndex).setValue(headerName); + + if (adjustColumnWidthEnabled(exportOptions)) { + adjustColumnWidth(metadataSheetHeaderRow.getSheet(), colIndex, adjustColumnWidthCharsCount(headerName)); + } } private void createEClassMetadataSheetData(Sheet metadataSheet, EClass eClass) { @@ -1068,7 +1132,7 @@ private void createEClassMetadataSheetDataCell(Range metadataSheetDataRow, int c setEClassMetadataDefaultValueCell(metadataSheetDataRow, colIndex, eStructuralFeature); break; case 5: // Documentation - setEClassMetadataDocumentationValueCell(metadataSheetDataRow, colIndex, eStructuralFeature); + setEStructuralFeatureMetadataDocumentationValueCell(metadataSheetDataRow, colIndex, eStructuralFeature); break; } } @@ -1085,7 +1149,7 @@ private void createEEnumMetadataSheetDataCell(Range metadataSheetDataRow, int co setEEnumMetadataValueValueCell(metadataSheetDataRow, colIndex, eEnumLiteral); break; case 3: // Documentation - setEEnumMetadataDocumentationValueCell(metadataSheetDataRow, colIndex, eEnumLiteral); + setEEnumLiteralMetadataDocumentationValueCell(metadataSheetDataRow, colIndex, eEnumLiteral); break; } } @@ -1155,7 +1219,7 @@ private void setEClassMetadataDefaultValueCell(Range metadataSheetDataRow, int c setVoidValueCell(metadataSheetDataRow, colIndex); } - private void setEClassMetadataDocumentationValueCell(Range metadataSheetDataRow, int colIndex, + private void setEStructuralFeatureMetadataDocumentationValueCell(Range metadataSheetDataRow, int colIndex, EStructuralFeature eStructuralFeature) { EAnnotation genModelAnnotation = eStructuralFeature.getEAnnotation(DOCUMENTATION_GENMODEL_SOURCE); @@ -1174,7 +1238,7 @@ private void setEEnumMetadataValueValueCell(Range metadataSheetDataRow, int colI setNumberValueCell(metadataSheetDataRow, colIndex, eEnumLiteral.getValue()); } - private void setEEnumMetadataDocumentationValueCell(Range metadataSheetDataRow, int colIndex, + private void setEEnumLiteralMetadataDocumentationValueCell(Range metadataSheetDataRow, int colIndex, EEnumLiteral eEnumLiteral) { EAnnotation genModelAnnotation = eEnumLiteral.getEAnnotation(DOCUMENTATION_GENMODEL_SOURCE); @@ -1187,12 +1251,16 @@ private void setMetadataDocumentationValueCell(Range metadataSheetDataRow, int c Map genModelAnnotationDetails = genModelAnnotation.getDetails().map(); if (genModelAnnotationDetails.containsKey(DOCUMENTATION_GENMODEL_DETAILS)) { - String documentation = genModelAnnotationDetails.get(DOCUMENTATION_GENMODEL_DETAILS); - setStringValueCell(metadataSheetDataRow, colIndex, documentation); + setMetadataDocumentationValueCell(metadataSheetDataRow, colIndex, + genModelAnnotationDetails.get(DOCUMENTATION_GENMODEL_DETAILS)); } + } else { + setVoidValueCell(metadataSheetDataRow, colIndex); } + } - setVoidValueCell(metadataSheetDataRow, colIndex); + private void setMetadataDocumentationValueCell(Range metadataSheetDataRow, int colIndex, String documentation) { + setStringValueCell(metadataSheetDataRow, colIndex, documentation); } private int getEObjectIdentifier(EObject eObject) {