Skip to content

Commit

Permalink
Metadata documentation improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Michael H. Siemaszko <[email protected]>
  • Loading branch information
Michael H. Siemaszko authored and juergen-albert committed Jan 8, 2024
1 parent c4b2b5e commit 5e22c55
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 31 deletions.
4 changes: 2 additions & 2 deletions org.gecko.emf.exporter.ods.tests/test.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public class EMFODSExporter implements EMFExporter {
"Default value", "Documentation");
private static final List<String> 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";

Expand Down Expand Up @@ -174,7 +176,7 @@ public void exportEObjectsTo(List<EObject> eObjects, OutputStream outputStream,
// @formatter:on

if (exportMetadataEnabled(exportOptions)) {
exportMetadata(document, eObjectsClasses, eObjectsEnums);
exportMetadata(document, eObjectsClasses, eObjectsEnums, exportOptions);
}

document.save(outputStream);
Expand Down Expand Up @@ -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) {
Expand All @@ -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
}
Expand Down Expand Up @@ -937,7 +942,9 @@ private boolean addMappingTableEnabled(Map<Object, Object> exportOptions) {

private boolean freezeHeaderRowEnabled(Map<Object, Object> 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;
}

Expand All @@ -959,56 +966,113 @@ private Sheet addMetadataSheet(SpreadSheet document, EEnum eEnum) {
return metadataSheet;
}

private void exportMetadata(SpreadSheet document, Set<EClass> eClasses, Set<EEnum> eEnums) {
exportEClassesMetadata(document, eClasses);
exportEEnumsMetadata(document, eEnums);
private void exportMetadata(SpreadSheet document, Set<EClass> eClasses, Set<EEnum> eEnums,
Map<Object, Object> exportOptions) {
exportEClassesMetadata(document, eClasses, exportOptions);
exportEEnumsMetadata(document, eEnums, exportOptions);
}

private void exportEClassesMetadata(SpreadSheet document, Set<EClass> eClasses) {
private void exportEClassesMetadata(SpreadSheet document, Set<EClass> eClasses, Map<Object, Object> 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<EEnum> eEnums) {
private void exportEEnumsMetadata(SpreadSheet document, Set<EEnum> eEnums, Map<Object, Object> 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<Object, Object> 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<Object, Object> 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<String> headers) {
private void maybeSetEEnumMetadataDocumentationValueCell(Sheet metadataSheet, EEnum eEnum,
Map<Object, Object> exportOptions) {
EAnnotation genModelAnnotation = eEnum.getEAnnotation(DOCUMENTATION_GENMODEL_SOURCE);
if (genModelAnnotation != null) {
setTypeLevelMetadataDocumentation(metadataSheet, genModelAnnotation, exportOptions);
}
}

private void setTypeLevelMetadataDocumentation(Sheet metadataSheet, EAnnotation genModelAnnotation,
Map<Object, Object> exportOptions) {
Map<String, String> 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<Object, Object> exportOptions) {
createMetadataSheetHeader(metadataSheet, METADATA_ECLASS_SHEET_HEADERS, exportOptions);
}

private void createEEnumMetadataSheetHeader(Sheet metadataSheet, Map<Object, Object> exportOptions) {
createMetadataSheetHeader(metadataSheet, METADATA_EENUM_SHEET_HEADERS, exportOptions);
}

private void createMetadataSheetHeader(Sheet metadataSheet, List<String> headers,
Map<Object, Object> 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<Object, Object> exportOptions) {
metadataSheetHeaderRow.getCell(0, colIndex).setValue(headerName);

if (adjustColumnWidthEnabled(exportOptions)) {
adjustColumnWidth(metadataSheetHeaderRow.getSheet(), colIndex, adjustColumnWidthCharsCount(headerName));
}
}

private void createEClassMetadataSheetData(Sheet metadataSheet, EClass eClass) {
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -1187,12 +1251,16 @@ private void setMetadataDocumentationValueCell(Range metadataSheetDataRow, int c
Map<String, String> 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) {
Expand Down

0 comments on commit 5e22c55

Please sign in to comment.