Skip to content
Open
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 @@ -13,11 +13,18 @@

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.set.model.planpro.Basisobjekte.Ur_Objekt;
import org.eclipse.set.model.tablemodel.MultiColorCellContent;
import org.eclipse.set.model.tablemodel.MultiColorContent;
import org.eclipse.set.model.tablemodel.Table;
import org.eclipse.set.model.tablemodel.TableCell;
import org.eclipse.set.model.tablemodel.TableRow;
import org.eclipse.set.model.tablemodel.TablemodelFactory;
import org.eclipse.set.model.tablemodel.extensions.TableExtensions;
import org.eclipse.set.model.tablemodel.extensions.TableRowExtensions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -366,4 +373,96 @@ public void testSimpleChange() {
assertEquals("[1]/[B]",
TableExtensions.getPlainStringValue(diffTable, 1, "B"));
}

@Test
void testMultiColorCellSimpleChange() {
final Table oldTable = TableExtensions.create("oldTable", "A");
TableExtensions.addRow(LEADING_OBJECT, 0, oldTable,
createMultiColorTableCell("1", "%s (R)", true));
TableExtensions.addRow(LEADING_OBJECT, 1, oldTable, "");

final Table newTable = EcoreUtil.copy(oldTable);
final List<TableRow> tableRows = TableExtensions.getTableRows(newTable);
TableRowExtensions.set(tableRows.get(0),
TableExtensions.getColumns(newTable).getFirst(), "");
final MultiColorContent multiColorContent = createMultiColorContent("1",
"%s (L)", true);
TableRowExtensions.set(tableRows.get(1),
TableExtensions.getColumns(newTable).getFirst(),
List.of(multiColorContent), "/n");
final Table diffTable = service.createDiffTable(oldTable, newTable);
System.out.println(TableExtensions.toDebugString(oldTable, 1));
System.out.println(TableExtensions.toDebugString(newTable, 1));
System.out.println(TableExtensions.toDebugString(diffTable, 10));
final List<TableRow> diffRows = TableExtensions.getTableRows(diffTable);
assertEquals(
"<p style=\"text-align:center\"><span style=\"background-color:rgb(255,255, 0)\"><s>1 ​(R)​</s></span></p>",
TableRowExtensions.getRichTextValue(diffRows.get(0), 0));
assertEquals(
"<p style=\"text-align:center\"><span style=\"color:rgb(255, 0, 0)\">1 ​(L)​</span></p>",
TableRowExtensions.getRichTextValue(diffRows.get(1), 0));
}

@Test
void testMultiColorCellChange() {
final Table oldTable = TableExtensions.create("oldTable", "A");
TableExtensions.addRow(LEADING_OBJECT, 0, oldTable,
createMultiColorTableCell("1", "%s (R)", true));
TableExtensions.addRow(LEADING_OBJECT, 1, oldTable,
createMultiColorTableCell("2", "%s (R)", true));

final Table newTable = EcoreUtil.copy(oldTable);
final List<TableRow> newTableRows = TableExtensions
.getTableRows(newTable);
for (int i = 0; i < newTableRows.size(); i++) {
final MultiColorContent multiColorContent = createMultiColorContent(
String.valueOf(i + 2), "%s (L)", false);
TableRowExtensions.set(newTableRows.get(i),
TableExtensions.getColumns(newTable).getFirst(),
List.of(multiColorContent), "/n");
}
// Test multi color cell in FINAL state
assertEquals(
"<p style=\"text-align:center\"><span><span style=\"background-color:rgb(255,255, 0)\">2</span><span style=\"color:rgb(255, 0, 0)\">2</span> (L)</span></p>",
TableRowExtensions.getRichTextValue(newTableRows.getFirst(),
0));
final Table diffTable = service.createDiffTable(oldTable, newTable);
System.out.println(TableExtensions.toDebugString(oldTable, 1));
System.out.println(TableExtensions.toDebugString(newTable, 1));
System.out.println(TableExtensions.toDebugString(diffTable, 10));
final List<TableRow> diffRows = TableExtensions.getTableRows(diffTable);
assertEquals(
"<p style=\"text-align:center\"><span style=\"color:rgb(255, 0, 0)\">2 ​(L)​</span><br></br><span style=\"background-color:rgb(255,255, 0)\"><s>1 ​(R)​</s></span></p>",
TableRowExtensions.getRichTextValue(diffRows.get(0), 0));
assertEquals(
"<p style=\"text-align:center\"><span style=\"color:rgb(255, 0, 0)\">3 ​(L)​</span><br></br><span style=\"background-color:rgb(255,255, 0)\"><s>2 ​(R)​</s></span></p>",
TableRowExtensions.getRichTextValue(diffRows.get(1), 0));
}

private static TableCell createMultiColorTableCell(
final String multiColorValue, final String stringFormat,
final boolean disableMultiColor) {
final MultiColorCellContent multiColorCellContent = TablemodelFactory.eINSTANCE
.createMultiColorCellContent();
multiColorCellContent.getValue()
.add(createMultiColorContent(multiColorValue, stringFormat,
disableMultiColor));
final TableCell tableCell = TablemodelFactory.eINSTANCE
.createTableCell();
tableCell.setContent(multiColorCellContent);
return tableCell;
}

private static MultiColorContent createMultiColorContent(
final String multiColorValue, final String stringFormat,
final boolean disableMultiColor) {
final MultiColorContent multiColorContent = TablemodelFactory.eINSTANCE
.createMultiColorContent();
multiColorContent.setMultiColorValue(multiColorValue);
multiColorContent.setStringFormat(stringFormat);
multiColorContent.setDisableMultiColor(disableMultiColor);
return multiColorContent;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
package org.eclipse.set.feature.table.diff;

import static org.eclipse.set.model.tablemodel.extensions.CellContentExtensions.createStringCellContent;
import static org.eclipse.set.model.tablemodel.extensions.CellContentExtensions.*;
import static org.eclipse.set.model.tablemodel.extensions.TableCellExtensions.getIterableStringValue;

import java.util.Collections;
Expand All @@ -23,7 +23,6 @@
import org.eclipse.set.model.tablemodel.StringCellContent;
import org.eclipse.set.model.tablemodel.TableCell;
import org.eclipse.set.model.tablemodel.TablemodelFactory;
import org.eclipse.set.model.tablemodel.extensions.CellContentExtensions;
import org.eclipse.set.ppmodel.extensions.EObjectExtensions;
import org.eclipse.set.services.table.TableDiffService;
import org.osgi.service.component.annotations.Component;
Expand Down Expand Up @@ -51,8 +50,8 @@ CellContent createDiffContent(final TableCell oldCell,
if (oldCell.getContent() instanceof MultiColorCellContent
|| newCell != null && newCell
.getContent() instanceof MultiColorCellContent) {
createMultiColorDiffCotent(oldCell, newCell);
return oldCell.getContent();
return createMultiColorDiffContent(oldCell.getContent(),
newCell.getContent());
}

if (!(oldCell.getContent() instanceof StringCellContent)
Expand All @@ -78,38 +77,93 @@ CellContent createDiffContent(final TableCell oldCell,
return compareContent;
}

private static void createMultiColorDiffCotent(final TableCell oldCell,
final TableCell newCell) {
if (oldCell
.getContent() instanceof final MultiColorCellContent oldCellContent
&& newCell != null && newCell
.getContent() instanceof final MultiColorCellContent newCellContent) {
if (CellContentExtensions.getPlainStringValue(oldCellContent)
.equals(CellContentExtensions
.getPlainStringValue(newCellContent))) {
oldCellContent.getValue()
.forEach(e -> e.setDisableMultiColor(false));
return;
@SuppressWarnings("nls")
private static CellContent createMultiColorDiffContent(
final CellContent oldContent, final CellContent newContent) {
if (oldContent == null
&& newContent instanceof final MultiColorCellContent newMuliColorCellContent) {
return createCompareStateCellContent(oldContent,
createStringCellContent(
getStringValueIterable(newMuliColorCellContent)));
}

if (oldContent == null) {
throw new IllegalArgumentException();
}

return switch (oldContent) {
case final StringCellContent oldStringCellContent -> {
if (newContent instanceof final MultiColorCellContent newMultiColorCellContent) {
yield createMultiColorDiffContent(oldStringCellContent,
newMultiColorCellContent);
}
throw new IllegalArgumentException(
"At least one cell content is multicolor cellcontent");
}
case final MultiColorCellContent oldMultiColorCellContent -> {
if (newContent instanceof final StringCellContent newStringCellContent) {
yield createMultiColorDiffContent(oldMultiColorCellContent,
newStringCellContent);
}

if (newContent instanceof final MultiColorCellContent newMultiColorCellContent) {
yield createMultiColorDiffContent(oldMultiColorCellContent,
newMultiColorCellContent);
}
throw new IllegalArgumentException(
"At least one cell content is multicolor cellcontent");
}

default -> throw new IllegalArgumentException(
"At least one cell content is multicolor cellcontent");
};
}

private static CellContent createMultiColorDiffContent(
final StringCellContent oldContent,
final MultiColorCellContent newContent) {
final String plainStringValue = getPlainStringValue(oldContent);
if (!plainStringValue.isEmpty()) {
throw new IllegalArgumentException(
"The compare cells content must be same type"); //$NON-NLS-1$
}
return createCompareStateCellContent(oldContent,
createStringCellContent(getStringValueIterable(newContent)));
}

private static CellContent createMultiColorDiffContent(
final MultiColorCellContent oldContent,
final StringCellContent newContent) {
if (!getPlainStringValue(newContent).isEmpty()) {
throw new IllegalArgumentException(
"The compare cells content must be same type"); //$NON-NLS-1$
}
return createCompareStateCellContent(
createStringCellContent(getStringValueIterable(oldContent)),
newContent);
}

// Convert to CompareCellContent, when give different between
// initial
// and final state
final CompareStateCellContent compareCellContent = TablemodelFactory.eINSTANCE
.createCompareStateCellContent();
oldCellContent.getValue()
.forEach(colorContent -> compareCellContent
.setOldValue(createStringCellContent(String.format(
colorContent.getStringFormat(),
colorContent.getMultiColorValue()))));

newCellContent.getValue()
.forEach(colorContent -> compareCellContent
.setNewValue(createStringCellContent(String.format(
colorContent.getStringFormat(),
colorContent.getMultiColorValue()))));
oldCell.setContent(compareCellContent);
private static CellContent createMultiColorDiffContent(
final MultiColorCellContent oldContent,
final MultiColorCellContent newContent) {
if (getPlainStringValue(oldContent)
.equals(getPlainStringValue(newContent))) {
oldContent.getValue()
.forEach(value -> value.setDisableMultiColor(false));
return oldContent;
}
return createCompareStateCellContent(
createStringCellContent(getStringValueIterable(oldContent)),
createStringCellContent(getStringValueIterable(newContent)));
}

private static CompareStateCellContent createCompareStateCellContent(
final CellContent oldContent, final CellContent newContent) {
final CompareStateCellContent compareStateCellContent = TablemodelFactory.eINSTANCE
.createCompareStateCellContent();
compareStateCellContent.setOldValue(oldContent);
compareStateCellContent.setNewValue(newContent);
return compareStateCellContent;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,17 @@ class CellContentExtensions {
!blank && !nullOrEmpty
] ?: #[]
}

static def dispatch Iterable<String> getStringValueIterable(MultiColorCellContent content) {
return content?.value?.filterNull?.map[v |
String.format(v.stringFormat, v.multiColorValue).trim
]?.filter[!blank && !nullOrEmpty]
}

static def List<String> getStringValueList(CellContent content) {
return content.stringValueIterable.toList
}


/**
* @param text the text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package org.eclipse.set.model.tablemodel.extensions
import java.util.Set
import org.eclipse.set.model.tablemodel.TableCell
import org.eclipse.set.model.tablemodel.TableRow
import org.eclipse.set.model.tablemodel.TablemodelFactory
import org.eclipse.set.model.tablemodel.format.CellFormat
import org.eclipse.set.model.tablemodel.format.TableformatFactory
import org.eclipse.set.model.tablemodel.format.TextAlignment
Expand Down Expand Up @@ -98,8 +99,9 @@ class TableCellExtensions {
TextAlignment textAlignment) {
cell.format.textAlignment = textAlignment
}

def static void setTopologicalCalcultation(TableCell cell, boolean isTopologicalCalculation) {

def static void setTopologicalCalcultation(TableCell cell,
boolean isTopologicalCalculation) {
cell.format.topologicalCalculation = isTopologicalCalculation
}

Expand All @@ -115,4 +117,10 @@ class TableCellExtensions {
}
return results.get(0)
}

def static void addContents(TableCell cell, String... contents) {
val stringContent = TablemodelFactory.eINSTANCE.createStringCellContent
stringContent.value.addAll(contents)
cell.content = stringContent
}
}
Loading
Loading