Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.eclipse.set.basis.FreeFieldInfo.LoadedPlanInformation
import org.eclipse.set.basis.FreeFieldInfo.SignificantInformation
import org.eclipse.set.basis.constants.ToolboxConstants
import org.eclipse.set.model.tablemodel.CellContent
import org.eclipse.set.model.tablemodel.ColumnDescriptor
import org.eclipse.set.model.tablemodel.CompareFootnoteContainer
import org.eclipse.set.model.tablemodel.CompareStateCellContent
import org.eclipse.set.model.tablemodel.CompareTableCellContent
Expand All @@ -31,6 +32,7 @@ import org.eclipse.set.model.tablemodel.MultiColorContent
import org.eclipse.set.model.tablemodel.PlanCompareRow
import org.eclipse.set.model.tablemodel.SimpleFootnoteContainer
import org.eclipse.set.model.tablemodel.Table
import org.eclipse.set.model.tablemodel.TableCell
import org.eclipse.set.model.tablemodel.TableContent
import org.eclipse.set.model.tablemodel.TableRow
import org.eclipse.set.model.tablemodel.extensions.TableExtensions.FootnoteInfo
Expand Down Expand Up @@ -211,7 +213,7 @@ class TableToTableDocument {

cells.indexed.forEach [
logger.debug('''column=«key»''')
val isRemarkColumn = value.isRemarkColumn(cells)
val isRemarkColumn = value.isRemarkColumn

// Check for required span merges
var rowSpan = 1
Expand Down Expand Up @@ -275,9 +277,22 @@ class TableToTableDocument {
return cellElement
}

private def boolean isRemarkColumn(CellContent content,
List<CellContent> rowContent) {
return rowContent.last === content
static def boolean isRemarkColumn(CellContent content) {
return isRemarkColumn((content.eContainer as TableCell))
}

static def boolean isRemarkColumn(TableCell cell) {
return isRemarkColumn(cell.columndescriptor)
}

static def boolean isRemarkColumn(ColumnDescriptor columnDescriptor) {
if (columnDescriptor === null) {
return false;
}
if (columnDescriptor.isRemarkColumn) {
return true;
}
return isRemarkColumn(columnDescriptor.parent)
}

private def Attr create doc.createAttribute("group-number") transformToGroupNumber(
Expand Down Expand Up @@ -432,17 +447,15 @@ class TableToTableDocument {
if (!remarkTextInlnie) {
element.setAttribute("keep-inline", "true")
// Sort unchanged & new footnotes together, then the old foonotes
#[unchangedFootnotes, newFootnotes].flatten.distinctBy[toShorthand].
sortBy[index].forEach [
val remark = unchangedFootnotes.exists [ unchanged |
unchanged.bearbeitungsvermerk ===
bearbeitungsvermerk &&
toShorthand == toShorthand
] ? WARNING_MARK_BLACK : WARNING_MARK_RED
element.addFootnoteChild(toShorthand, remark, columnNumber,
isRemarkColumn)
]
oldFootnotes.distinctBy[toShorthand].sortBy[index].forEach [
#[unchangedFootnotes, newFootnotes].flatten.processFootnotes.forEach [
val remark = unchangedFootnotes.exists [ unchanged |
unchanged.bearbeitungsvermerk === bearbeitungsvermerk &&
toShorthand == toShorthand
] ? WARNING_MARK_BLACK : WARNING_MARK_RED
element.addFootnoteChild(toShorthand, remark, columnNumber,
isRemarkColumn)
]
oldFootnotes.processFootnotes.forEach [
element.addFootnoteChild(toShorthand, WARNING_MARK_YELLOW,
columnNumber, isRemarkColumn)
]
Expand All @@ -463,11 +476,17 @@ class TableToTableDocument {
isRemarkColumn)
}

static def List<FootnoteInfo> processFootnotes(Iterable<FootnoteInfo> fn) {
return fn.filterNull.distinctBy[toShorthand].sortBy [
index
].toList
}

private def String footnotesToString(Iterable<FootnoteInfo> fn) {
val separator = remarkTextInlnie ? FOOTNOTE_INLINE_TEXT_SEPARATOR : FOOTNOTE_MARK_SEPRATOR
return fn.filterNull.sortBy[index].map [
return fn.processFootnotes.map [
remarkTextInlnie ? toText : toShorthand
].toSet.iterableToString(separator)
].iterableToString(separator)
}

private def Element createMultiColorElement(MultiColorContent content,
Expand Down Expand Up @@ -512,9 +531,8 @@ class TableToTableDocument {
private def Element addContentToElement(String content, Element element,
int columnNumber, boolean isRemarkColumn) {
val checkOutput = content.checkForTestOutput(columnNumber)
element.textContent = isRemarkColumn
? checkOutput
: checkOutput.intersperseWithZeroSpacesSC
element.textContent = isRemarkColumn ? checkOutput : checkOutput.
intersperseWithZeroSpacesSC
return element
}

Expand Down Expand Up @@ -577,19 +595,23 @@ class TableToTableDocument {

private def Element create doc.createElement("SignificantInformation") transformToSignificantInformation(
SignificantInformation significantInformation) {
appendChild(transformLoadedPlanInformation("MainPlan", significantInformation.mainPlan))
appendChild(
transformLoadedPlanInformation("MainPlan",
significantInformation.mainPlan))
if (significantInformation.comparePlan !== null) {
appendChild(transformLoadedPlanInformation("ComparePlan", significantInformation.comparePlan))
appendChild(
transformLoadedPlanInformation("ComparePlan",
significantInformation.comparePlan))
}
}

private def Element create doc.createElement("LoadedPlan") transformLoadedPlanInformation(String id, LoadedPlanInformation info) {

private def Element create doc.createElement("LoadedPlan") transformLoadedPlanInformation(
String id, LoadedPlanInformation info) {
val idAttr = doc.createAttribute("id")
idAttr.value = id
attributeNode = idAttr
textContent = '''«info.name» «info.timestamp» MD5: «info.checksum»'''
}


private def Element create doc.createElement("Footnotes")
transformToFootnotes(Table table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
*/
package org.eclipse.set.feature.export.xlsx;

import static org.eclipse.set.utils.excel.ExcelWorkbookExtension.*;
import static org.eclipse.set.utils.excel.ExcelWorkbookExtension.getCellAt;
import static org.eclipse.set.utils.excel.ExcelWorkbookExtension.getCellStringValue;
import static org.eclipse.set.utils.excel.ExcelWorkbookExtension.getHeaderLastColumnIndex;
import static org.eclipse.set.utils.excel.ExcelWorkbookExtension.getHeaderLastRowIndex;

import java.awt.image.BufferedImage;
import java.io.FileInputStream;
Expand All @@ -20,7 +23,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -209,6 +211,7 @@ private static void fillFootnoteSheet(final Sheet footnoteSheet,
}
}

@SuppressWarnings("resource")
private static void fillSheet(final Sheet sheet, final List<TableRow> rows,
final int rowIndex, final int columnCount,
final boolean inlineFootnote) {
Expand All @@ -233,8 +236,20 @@ private static void fillSheet(final Sheet sheet, final List<TableRow> rows,

if (cell == null) {
cell = sheetRow.createCell(i + 1);
// in the excel template it might be the case that a certain
// cell is was never defined/styled.
// If that is the case we take at least the font from the
// definitely defined first cell from the header so that all
// the cells are using the same font.
cell.getCellStyle()
.setFont(sheet.getWorkbook()
.getFontAt(sheet.getRow(0)
.getCell(1)
.getCellStyle()
.getFontIndex()));
}
if (i == columnCount - 1) {
if (TableToTableDocument
.isRemarkColumn(row.getCells().get(i))) {
fillFootnoteCell(cell, content, allFootnotes, footnotes,
inlineFootnote);
continue;
Expand Down Expand Up @@ -268,23 +283,22 @@ private static void fillFootnoteCell(final Cell cell,
final String cellContent, final List<FootnoteInfo> allFootnotes,
final FootnoteContainer fnContainer, final boolean inlineFootnote) {
final List<Footnote> footnotes = getFootnotes(fnContainer);
final List<FootnoteInfo> fnInfo = footnotes.stream()
.map(fn -> TableExtensions.getFootnoteInfo(allFootnotes, fn))
.filter(Objects::nonNull)
.toList();
final List<FootnoteInfo> fnInfo = TableToTableDocument
.processFootnotes(footnotes.stream()
.map(fn -> TableExtensions.getFootnoteInfo(allFootnotes,
fn))
.toList());
final StringBuilder builder = new StringBuilder();
if (!cellContent.isEmpty() && !cellContent.isBlank()) {
builder.append(cellContent);
builder.append(TableToTableDocument.FOOTNOTE_INLINE_TEXT_SEPARATOR);
}
final String footnoteValue = inlineFootnote ? fnInfo.stream()
.map(FootnoteInfo::toText)
.collect(Collectors.joining(
TableToTableDocument.FOOTNOTE_INLINE_TEXT_SEPARATOR))
: fnInfo.stream()
.map(fn -> "*" + fn.index) //$NON-NLS-1$
.collect(Collectors.joining(
TableToTableDocument.FOOTNOTE_MARK_SEPRATOR));
final String footnoteValue = fnInfo.stream()
.map(inlineFootnote ? FootnoteInfo::toText
: FootnoteInfo::toShorthand)
.collect(Collectors.joining(inlineFootnote
? TableToTableDocument.FOOTNOTE_INLINE_TEXT_SEPARATOR
: TableToTableDocument.FOOTNOTE_MARK_SEPRATOR));
builder.append(footnoteValue);
cell.setCellValue(builder.toString());
}
Expand Down Expand Up @@ -318,6 +332,7 @@ private static void addTableSpans(final Sheet sheet,
if (!spanUtils.isMergeAllowed(column, row)) {
continue;
}
final int sheetColumn = column + 1;

final int spanUp = spanUtils.getRowSpanUp(column, row);
final int spanDown = spanUtils.getRowSpanDown(column, row);
Expand All @@ -334,7 +349,7 @@ private static void addTableSpans(final Sheet sheet,
}

sheet.addMergedRegion(new CellRangeAddress(sheetRowIndex,
sheetRowIndex + spanDown, column, column));
sheetRowIndex + spanDown, sheetColumn, sheetColumn));
}

sheetRowIndex++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -98,9 +99,23 @@ public ColumnDescriptor fillHeaderDescriptions(
throw new RuntimeException(e);
}
cols = getColumnsListe(root.getGroupRoot());

getColumnDescriptor(getRemarkColumnPosition())
.ifPresent(col -> col.setIsRemarkColumn(true));

return root.getGroupRoot();
}

protected Optional<ColumnDescriptor> getColumnDescriptor(
final String position) {
if (position == null) {
return Optional.empty();
}
return cols.stream()
.filter(col -> position.equals(col.getColumnPosition()))
.findFirst();
}

@Override
public Set<Integer> getFixedColumnsPos() {
final Set<Integer> repeatingColumns = getRepeatingColumns(
Expand Down Expand Up @@ -169,6 +184,12 @@ public Table transform(final MultiContainer_AttributeGroup model) {

protected abstract List<String> getTopologicalColumnPosition();

/**
* @return the column position of the remark column or null if the table has
* no remark column
*/
protected abstract String getRemarkColumnPosition();

protected abstract Map<Class<?>, String> getFootnotesColumnReferences();

protected void setTopologicalColumnHightlight(final Table table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ protected List<String> getTopologicalColumnPosition() {
return Collections.emptyList();
}

@Override
protected String getRemarkColumnPosition() {
return SsbbColumns.Bemerkung;
}

@Override
protected Map<Class<?>, String> getFootnotesColumnReferences() {
return Map.of(ID_Strecke_TypeClass.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ protected List<String> getTopologicalColumnPosition() {
return Collections.emptyList();
}

@Override
protected String getRemarkColumnPosition() {
return SsitColumns.Bemerkung;
}

@Override
protected Map<Class<?>, String> getFootnotesColumnReferences() {
return Map.of(ID_Strecke_TypeClass.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ protected List<String> getTopologicalColumnPosition() {
return Collections.emptyList();
}

@Override
protected String getRemarkColumnPosition() {
return SskaColumns.Bemerkung;
}

@Override
protected Map<Class<?>, String> getFootnotesColumnReferences() {
return Map.of(ID_Strecke_TypeClass.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ protected List<String> getTopologicalColumnPosition() {
return Collections.emptyList();
}

@Override
protected String getRemarkColumnPosition() {
return SskfColumns.Bemerkung;
}

@Override
protected Map<Class<?>, String> getFootnotesColumnReferences() {
return Map.of();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ protected List<String> getTopologicalColumnPosition() {
return List.of(SskgColumns.Bezugspunkt_Abstand);
}

@Override
protected String getRemarkColumnPosition() {
return SskgColumns.Bemerkung;
}

@Override
protected Map<Class<?>, String> getFootnotesColumnReferences() {
return Map.of(ID_Strecke_TypeClass.class, SskgColumns.Standort_Strecke,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ protected List<String> getTopologicalColumnPosition() {
return Collections.emptyList();
}

@Override
protected String getRemarkColumnPosition() {
return SskoColumns.Bemerkung;
}

@Override
protected Map<Class<?>, String> getFootnotesColumnReferences() {
return Map.of(ID_Strecke_TypeClass.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,8 @@ public ColumnDescriptor fillHeaderDescriptions(
SskpColumns.GeschwindigkeitsKlasse, //
SskpColumns.PZB_Schutzstrecke_Soll, //
SskpColumns.PZB_Schutzstrecke_Ist)
.forEach(it -> cols.forEach(col -> {
if (it.equals(col.getColumnPosition())) {
col.setMergeCommonValues(RowMergeMode.DISABLED);
}
.forEach(it -> getColumnDescriptor(it).ifPresent(col -> {
col.setMergeCommonValues(RowMergeMode.DISABLED);
}));

return cd;
Expand All @@ -199,6 +197,11 @@ protected List<String> getTopologicalColumnPosition() {
Abstand_vorsignalWdh_GM_2000);
}

@Override
protected String getRemarkColumnPosition() {
return SskpColumns.Bemerkung;
}

@Override
protected Map<Class<?>, String> getFootnotesColumnReferences() {
return Collections.emptyMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ protected List<String> getTopologicalColumnPosition() {
return List.of(Schaltkasten_Entfernung, Lichtraumprofil, Ueberhoehung);
}

@Override
protected String getRemarkColumnPosition() {
return SsksColumns.Bemerkung;
}

@Override
protected Map<Class<?>, String> getFootnotesColumnReferences() {
return Map.of(ID_Strecke_TypeClass.class, SsksColumns.Strecke,
Expand Down
Loading
Loading