Fixed a bug where selected element was not displayed in trace viewers
In some circumstances, the selected element, e.g., in the Papyrus
diagram editor, was not displayed in the trace viewers, e.g., in the
PlantUML View. Instead, a different element that is a child of the
selected element was displayed. This was due to the fact that
EMFHelper.linearize() put the root of the element tree last in the list.
This commit fixes the behaviour. The change also reorders the elements
in the traceability matrix view to show the container first and
contained elements afterwards.
Change-Id: I7af69ddee4198444241bd5d0bd085eeee05380a7
diff --git a/bundles/org.eclipse.capra.core/src/org/eclipse/capra/core/helpers/EMFHelper.java b/bundles/org.eclipse.capra.core/src/org/eclipse/capra/core/helpers/EMFHelper.java
index 78c70d9..34b590e 100644
--- a/bundles/org.eclipse.capra.core/src/org/eclipse/capra/core/helpers/EMFHelper.java
+++ b/bundles/org.eclipse.capra.core/src/org/eclipse/capra/core/helpers/EMFHelper.java
@@ -154,7 +154,8 @@
/**
* Linearizes a tree to a list. The function checks if the provided parameter is
- * of type {@link EObject} and linearizes only if that is the case.
+ * of type {@link EObject} and linearizes only if that is the case. The root of
+ * the tree will always be the first element in the list.
*
* @param object the object to linearize
* @return a list of {@link EObject}s originally contained in the tree structure
@@ -165,8 +166,8 @@
ArrayList<EObject> elementList = new ArrayList<EObject>();
if (object instanceof EObject) {
EObject root = (EObject) object;
- root.eAllContents().forEachRemaining(element -> elementList.add(element));
elementList.add(root);
+ root.eAllContents().forEachRemaining(element -> elementList.add(element));
}
return elementList;
}
diff --git a/tests/org.eclipse.capra.testsuite/src/org/eclipse/capra/testsuite/TestTraceabiltyMatrix.java b/tests/org.eclipse.capra.testsuite/src/org/eclipse/capra/testsuite/TestTraceabiltyMatrix.java
index cd729af..da578a8 100644
--- a/tests/org.eclipse.capra.testsuite/src/org/eclipse/capra/testsuite/TestTraceabiltyMatrix.java
+++ b/tests/org.eclipse.capra.testsuite/src/org/eclipse/capra/testsuite/TestTraceabiltyMatrix.java
@@ -75,11 +75,11 @@
private static final String EXPECTED_TEXT_FOR_SELECTED_PACKAGES_TRANSITIVE = "@startuml" + LINE_SEPARATOR + "salt"
+ LINE_SEPARATOR + "{#" + LINE_SEPARATOR
- + ".|A : EClass|AA : EClass|modelA : EPackage|B : EClass|BB : EClass|modelB : EPackage" + LINE_SEPARATOR
- + "A : EClass |. |. |. |X |. |." + LINE_SEPARATOR + "AA : EClass |. |. |. |. |X |." + LINE_SEPARATOR
- + "modelA : EPackage |. |. |. |. |. |X" + LINE_SEPARATOR + "B : EClass |X |. |. |. |. |." + LINE_SEPARATOR
- + "BB : EClass |. |X |. |. |. |." + LINE_SEPARATOR + "modelB : EPackage |. |. |X |. |. |." + LINE_SEPARATOR
- + "}" + LINE_SEPARATOR + LINE_SEPARATOR + "@enduml" + LINE_SEPARATOR;
+ + ".|modelA : EPackage|A : EClass|AA : EClass|modelB : EPackage|B : EClass|BB : EClass" + LINE_SEPARATOR
+ + "modelA : EPackage |. |. |. |X |. |." + LINE_SEPARATOR + "A : EClass |. |. |. |. |X |." + LINE_SEPARATOR
+ + "AA : EClass |. |. |. |. |. |X" + LINE_SEPARATOR + "modelB : EPackage |X |. |. |. |. |." + LINE_SEPARATOR
+ + "B : EClass |. |X |. |. |. |." + LINE_SEPARATOR + "BB : EClass |. |. |X |. |. |." + LINE_SEPARATOR + "}"
+ + LINE_SEPARATOR + LINE_SEPARATOR + "@enduml" + LINE_SEPARATOR;
private static final String EXPECTED_TEXT_FOR_SELECTED_CLASSES = "@startuml" + LINE_SEPARATOR + "salt"
+ LINE_SEPARATOR + "{#" + LINE_SEPARATOR + ".|A : EClass|B : EClass|AA : EClass|BB : EClass"