[571056] Update SessionDetailsReport

Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=571056
Change-Id: I3d561bf2ca1e09845821c45b4054bc5a6613d973
Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/propertypage/SiriusSessionDetailsPropertyPageTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/propertypage/SiriusSessionDetailsPropertyPageTest.java
index 3fce0d3..a06ba3a 100644
--- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/propertypage/SiriusSessionDetailsPropertyPageTest.java
+++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/propertypage/SiriusSessionDetailsPropertyPageTest.java
@@ -27,6 +27,7 @@
 import org.eclipse.sirius.tests.swtbot.support.api.condition.TreeItemSelected;
 import org.eclipse.sirius.tests.swtbot.support.api.editor.SWTBotSiriusDiagramEditor;
 import org.eclipse.sirius.ui.business.internal.session.SiriusSessionDetailsPropertyPage;
+import org.eclipse.sirius.viewpoint.Messages;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
 import org.eclipse.swtbot.swt.finder.SWTBot;
@@ -161,19 +162,21 @@
         strBuilder.append("Loaded representations:  3\n");
         strBuilder.append("Representation elements in loaded representations:  22\n");
         strBuilder.append("\n");
-        strBuilder.append("Loaded representations containing elements with no semantic target (2)\n");
+        strBuilder.append("Loaded representations containing elements with no semantic target(red cross decorator) (2)\n");
         strBuilder.append("  root package entities BROKEN - uid: _X14A0Gu5EeucgZBzLx9xaw\n");
         strBuilder.append("  Classes in root package - uid: _KjzRUGu6EeucgZBzLx9xaw\n");
+        strBuilder.append(Messages.SessionQuery_LoadedBrokenRepsInfo + "\n");
         strBuilder.append("\n");
         strBuilder.append("Invalid representations (0)\n");
+        strBuilder.append(Messages.SessionQuery_InvalidRepsInfo + "\n");
         strBuilder.append("\n");
         strBuilder.append("Representation descriptors details (3)\n");
         strBuilder.append(
-                "  root package entities - uid: _8t7_oGu3EeuuXbLvG4gakA - description: platform:/plugin/org.eclipse.sirius.sample.ecore.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities'] - repPath: platform:/resource/DesignerTestProject/representations.aird#_8tukQGu3EeuuXbLvG4gakA -> {eClass: ecore::EPackage, name: root}  [Loaded][Diagram]\n");
+                "  root package entities - uid: _8t7_oGu3EeuuXbLvG4gakA - description: Entities - viewpoint: Design - repPath: platform:/resource/DesignerTestProject/representations.aird#_8tukQGu3EeuuXbLvG4gakA -> {eClass: ecore::EPackage, name: root}  [Loaded][Diagram]\n");
         strBuilder.append(
-                "  root package entities BROKEN - uid: _X14A0Gu5EeucgZBzLx9xaw - description: platform:/plugin/org.eclipse.sirius.sample.ecore.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities'] - repPath: platform:/resource/DesignerTestProject/representations.aird#_X1N5gGu5EeucgZBzLx9xaw -> {eClass: ecore::EPackage, name: root}  [Loaded][Diagram]\n");
+                "  root package entities BROKEN - uid: _X14A0Gu5EeucgZBzLx9xaw - description: Entities - viewpoint: Design - repPath: platform:/resource/DesignerTestProject/representations.aird#_X1N5gGu5EeucgZBzLx9xaw -> {eClass: ecore::EPackage, name: root}  [Loaded][Diagram]\n");
         strBuilder.append(
-                "  Classes in root package - uid: _KjzRUGu6EeucgZBzLx9xaw - description: platform:/plugin/org.eclipse.sirius.sample.ecore.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Classes'] - repPath: platform:/resource/DesignerTestProject/representations.aird#_Kh3-sGu6EeucgZBzLx9xaw -> {eClass: ecore::EPackage, name: root}  [Loaded][EditionTable]\n");
+                "  Classes in root package - uid: _KjzRUGu6EeucgZBzLx9xaw - description: Classes - viewpoint: Design - repPath: platform:/resource/DesignerTestProject/representations.aird#_Kh3-sGu6EeucgZBzLx9xaw -> {eClass: ecore::EPackage, name: root}  [Loaded][EditionTable]\n");
         strBuilder.append("\n");
         strBuilder.append("Representations opened in an editor (1)\n");
         strBuilder.append("  root package entities - uid: _8t7_oGu3EeuuXbLvG4gakA\n");
diff --git a/plugins/org.eclipse.sirius.ui/plugin.properties b/plugins/org.eclipse.sirius.ui/plugin.properties
index ab136ea..90616ce 100644
--- a/plugins/org.eclipse.sirius.ui/plugin.properties
+++ b/plugins/org.eclipse.sirius.ui/plugin.properties
@@ -430,7 +430,7 @@
 command.uncontrol.name = Uncontrol
 command.update.rep.location.name = Update Representations Location
 command.update.rep.location.label = Update Representations Location
-commonFilter.invalidRepresentations.description = Hides the invalid representations. Invalid representations corresponds to:\n- representations without target represented element or whose target element has been detached or deleted\n- representations which can not be reached because it has been deleted or because of a technical issue
+commonFilter.invalidRepresentations.description = Hides the invalid representations. A representation is invalid when:\n  - it has no target represented element or its target element has been detached or deleted\n  - it can not be reached because it has been deleted or because of a technical issue
 commonFilter.invalidRepresentations.name = Representations known as invalid
 commonFilter.emptyRepresentationType.description = Hides Representation descriptions without instances
 commonFilter.emptyRepresentationType.name = Representation descriptions without instance
diff --git a/plugins/org.eclipse.sirius/plugin.properties b/plugins/org.eclipse.sirius/plugin.properties
index f012705..9cea495 100644
--- a/plugins/org.eclipse.sirius/plugin.properties
+++ b/plugins/org.eclipse.sirius/plugin.properties
@@ -279,8 +279,10 @@
 SessionQuery_Sequence=Sequence
 SessionQuery_LoadedReps=Loaded representations:
 SessionQuery_NbRepElements=Representation elements in loaded representations:
-SessionQuery_LoadedBrokenReps=Loaded representations containing elements with no semantic target ({0})
+SessionQuery_LoadedBrokenReps=Loaded representations containing elements with no semantic target (red cross decorator) ({0})
+SessionQuery_LoadedBrokenRepsInfo=Tip: The next (manual or automatic) refresh  will remove those elements. The red cross is displayed when the represented element has been detached or deleted from the model.
 SessionQuery_InvalidReps=Invalid representations ({0})
+SessionQuery_InvalidRepsInfo=Information: A representation is invalid when:\n  - it has no target represented element or its target element has been detached or deleted\n  - it can not be reached because it has been deleted or because of a technical issue
 SessionQuery_RepresentationDescriptorDetails=Representation descriptors details ({0})
 SessionQuery_TagInvalid=Invalid
 SessionQuery_TagLoaded=Loaded
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/query/SessionDetailsReport.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/query/SessionDetailsReport.java
index 9ce93cb..9511a6f 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/query/SessionDetailsReport.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/query/SessionDetailsReport.java
@@ -21,6 +21,7 @@
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.Spliterator;
 import java.util.Spliterators;
@@ -42,7 +43,6 @@
 import org.eclipse.sirius.business.api.query.EObjectQuery;
 import org.eclipse.sirius.business.api.query.URIQuery;
 import org.eclipse.sirius.business.api.session.Session;
-import org.eclipse.sirius.common.tools.api.interpreter.EvaluationException;
 import org.eclipse.sirius.ext.base.Option;
 import org.eclipse.sirius.viewpoint.DAnalysisSessionEObject;
 import org.eclipse.sirius.viewpoint.DRepresentation;
@@ -50,6 +50,7 @@
 import org.eclipse.sirius.viewpoint.DRepresentationElement;
 import org.eclipse.sirius.viewpoint.DView;
 import org.eclipse.sirius.viewpoint.Messages;
+import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
 import org.eclipse.sirius.viewpoint.description.Viewpoint;
 
 /**
@@ -118,32 +119,61 @@
         // Gather information
         Collection<DRepresentation> loadedReps = DialectManager.INSTANCE.getAllLoadedRepresentations(session);
         //@formatter:off
-        @SuppressWarnings("unchecked")
         List<DRepresentationElement> repElements = loadedReps.stream()
-            .flatMap(rep -> {
-                try {
-                    // Using aql allows to optimize performances
-                    return ((Collection<DRepresentationElement>) session.getInterpreter().evaluate(rep, "aql:self.eAllContents(viewpoint::DRepresentationElement)")).stream(); //$NON-NLS-1$
-                } catch (EvaluationException e) {
-                }
-                return null;
-            })
+            .flatMap(rep -> rep.getRepresentationElements().stream())
+            .filter(Objects::nonNull)
             .collect(Collectors.toList());
         
         Set<DRepresentation> representationsWithoutTarget = repElements.stream()
-            .filter(repElement -> repElement.getTarget() == null || repElement.getTarget().eResource() == null)
+            .filter(repElement -> {
+                EObject target = repElement.getTarget();
+                return target == null || target.eResource() == null;
+            })
             .map(repElement -> new DRepresentationElementQuery(repElement).getParentRepresentation())
+            .filter(Objects::nonNull)
             .collect(Collectors.toCollection(LinkedHashSet::new));
         //@formatter:on
 
         Collection<DRepresentationDescriptor> allRepDescs = DialectManager.INSTANCE.getAllRepresentationDescriptors(session);
+        List<DRepresentationDescriptor> invalidReps = new ArrayList<DRepresentationDescriptor>();
+        Map<DRepresentationDescriptor, String> repDescToTags = new LinkedHashMap<DRepresentationDescriptor, String>();
+
+        processGeneralInformation(informations, allRepDescs, invalidReps, repDescToTags);
+
+        informations.append(CR).append(Messages.SessionQuery_LoadedReps).append(TAB).append(loadedReps.size()).append(CR);
+        informations.append(Messages.SessionQuery_NbRepElements).append(TAB).append(repElements.size()).append(CR);
+
+        informations.append(CR).append(MessageFormat.format(Messages.SessionQuery_LoadedBrokenReps, representationsWithoutTarget.size())).append(CR);
+        representationsWithoutTarget.stream().map(rep -> new DRepresentationQuery(rep).getRepresentationDescriptor()).forEach(repDescriptor -> {
+            informations.append(TAB);
+            addRepresentationDescriptorSimpleInfo(informations, repDescriptor);
+            informations.append(CR);
+        });
+        informations.append(Messages.SessionQuery_LoadedBrokenRepsInfo).append(CR);
+
+        informations.append(CR).append(MessageFormat.format(Messages.SessionQuery_InvalidReps, invalidReps.size())).append(CR);
+        invalidReps.stream().forEach(repDescriptor -> {
+            informations.append(TAB);
+            addRepresentationDescriptorSimpleInfo(informations, repDescriptor);
+            informations.append(CR);
+        });
+        informations.append(Messages.SessionQuery_InvalidRepsInfo).append(CR);
+
+        informations.append(CR).append(MessageFormat.format(Messages.SessionQuery_RepresentationDescriptorDetails, allRepDescs.size())).append(CR);
+        allRepDescs.stream().forEach(repDescriptor -> {
+            informations.append(TAB);
+            addRepresentationDescriptorExtendedInfo(informations, repDescriptor, repDescToTags);
+            informations.append(CR);
+        });
+    }
+
+    private void processGeneralInformation(StringBuilder informations, Collection<DRepresentationDescriptor> allRepDescs, List<DRepresentationDescriptor> invalidReps,
+            Map<DRepresentationDescriptor, String> repDescToTags) {
         long nbDiagram = 0;
         long nbEditionTables = 0;
         long nbCrossTables = 0;
         long nbTree = 0;
         long nbSequence = 0;
-        List<DRepresentationDescriptor> invalidReps = new ArrayList<DRepresentationDescriptor>();
-        Map<DRepresentationDescriptor, String> repDescToTags = new LinkedHashMap<DRepresentationDescriptor, String>();
         for (DRepresentationDescriptor dRepresentationDescriptor : allRepDescs) {
             StringBuilder tags = new StringBuilder();
             if (!new DRepresentationDescriptorQuery(dRepresentationDescriptor).isRepresentationValid()) {
@@ -185,30 +215,6 @@
         informations.append(TAB).append(Messages.SessionQuery_EditionTable).append(COLON).append(SPACE).append(nbEditionTables).append(CR);
         informations.append(TAB).append(Messages.SessionQuery_CrossTable).append(COLON).append(SPACE).append(nbCrossTables).append(CR);
         informations.append(TAB).append(Messages.SessionQuery_Tree).append(COLON).append(SPACE).append(nbTree).append(CR);
-
-        informations.append(CR).append(Messages.SessionQuery_LoadedReps).append(TAB).append(loadedReps.size()).append(CR);
-        informations.append(Messages.SessionQuery_NbRepElements).append(TAB).append(repElements.size()).append(CR);
-
-        informations.append(CR).append(MessageFormat.format(Messages.SessionQuery_LoadedBrokenReps, representationsWithoutTarget.size())).append(CR);
-        representationsWithoutTarget.stream().map(rep -> new DRepresentationQuery(rep).getRepresentationDescriptor()).forEach(repDescriptor -> {
-            informations.append(TAB);
-            addRepresentationDescriptorSimpleInfo(informations, repDescriptor);
-            informations.append(CR);
-        });
-
-        informations.append(CR).append(MessageFormat.format(Messages.SessionQuery_InvalidReps, invalidReps.size())).append(CR);
-        invalidReps.stream().forEach(repDescriptor -> {
-            informations.append(TAB);
-            addRepresentationDescriptorSimpleInfo(informations, repDescriptor);
-            informations.append(CR);
-        });
-
-        informations.append(CR).append(MessageFormat.format(Messages.SessionQuery_RepresentationDescriptorDetails, allRepDescs.size())).append(CR);
-        allRepDescs.stream().forEach(repDescriptor -> {
-            informations.append(TAB);
-            addRepresentationDescriptorExtendedInfo(informations, repDescriptor, repDescToTags);
-            informations.append(CR);
-        });
     }
 
     private void addResourcesInformation(StringBuilder informations) {
@@ -239,21 +245,38 @@
 
     private String getViewpointDescription(Viewpoint viewpoint) {
         String vpDescription = null;
-        Resource resource = viewpoint.eResource();
-        if (resource == null) {
-            // toString allows to get the eProxyURI
-            vpDescription = viewpoint.toString();
-        } else {
-            vpDescription = viewpoint.getName() + SPACE + Messages.SessionQuery_LoadedFromResource + SPACE + resource.getURI().toString();
+        if (viewpoint != null) {
+            Resource resource = viewpoint.eResource();
+            if (resource == null) {
+                // toString allows to get the eProxyURI
+                vpDescription = viewpoint.toString();
+            } else {
+                vpDescription = viewpoint.getName() + SPACE + Messages.SessionQuery_LoadedFromResource + SPACE + resource.getURI().toString();
+            }
         }
+
         return vpDescription;
     }
 
     private void addRepresentationDescriptorExtendedInfo(StringBuilder informations, DRepresentationDescriptor repDescriptor, Map<DRepresentationDescriptor, String> repDescToTags) {
         addRepresentationDescriptorSimpleInfo(informations, repDescriptor);
         informations.append(SEPARATOR);
-        informations.append("description: "); //$NON-NLS-1$
-        informations.append(EcoreUtil.getURI(repDescriptor.getDescription()));
+        RepresentationDescription description = repDescriptor.getDescription();
+        if (description != null) {
+            informations.append("description: "); //$NON-NLS-1$
+            informations.append(description.getName());
+            informations.append(SEPARATOR);
+
+            Viewpoint vp = (Viewpoint) description.eContainer();
+            if (vp != null) {
+                informations.append("viewpoint: "); //$NON-NLS-1$
+                informations.append(vp.getName());
+            } else {
+                informations.append("viewpoint: null"); //$NON-NLS-1$
+            }
+        } else {
+            informations.append("description: null"); //$NON-NLS-1$
+        }
         informations.append(SEPARATOR);
         informations.append("repPath: "); //$NON-NLS-1$
         informations.append(repDescriptor.getRepPath().toString());
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/viewpoint/Messages.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/viewpoint/Messages.java
index 779bb01..f4e8cc2 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/viewpoint/Messages.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/viewpoint/Messages.java
@@ -624,9 +624,15 @@
     public static String SessionQuery_LoadedBrokenReps;
 
     @TranslatableMessage
+    public static String SessionQuery_LoadedBrokenRepsInfo;
+
+    @TranslatableMessage
     public static String SessionQuery_InvalidReps;
 
     @TranslatableMessage
+    public static String SessionQuery_InvalidRepsInfo;
+
+    @TranslatableMessage
     public static String SessionQuery_RepresentationDescriptorDetails;
 
     @TranslatableMessage