]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fixed labels for search results restored from previous search memento 94/194/2
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 8 Dec 2016 21:48:11 +0000 (23:48 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 8 Dec 2016 21:47:30 +0000 (23:47 +0200)
Also made the details label shown at the bottom of the dialog for the
selected entry a bit more legible. The URI that was previously shown is
now a root relative unescaped path for results contained by a model
root.

refs #6855

Change-Id: Iccd0762707d938009ea046f4ac8ef20571e353a1

bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/SearchResourceDialog.java
bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/DebugUtils.java

index 1ae23d7197c0b61bd5f039611872388f9641a739..ffdc681754940015690d29e92ed7a6f832a4d4b4 100644 (file)
@@ -115,11 +115,12 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog {
                     @Override\r
                     public String perform(ReadGraph g) throws DatabaseException {\r
                         String name = NameUtils.getSafeName(g, r);\r
-                        String uri = g.getPossibleURI(r);\r
-                        String label = "[" + r.getResourceId() + "] - " + name;\r
-                        if (uri != null)\r
-                            label = label + " - " + uri;\r
-                        return label;\r
+                        String uri = DebugUtils.getPossibleRootRelativePath(g, r);\r
+                        return\r
+                                "[" + r.getResourceId() + "] - "\r
+                                + name\r
+                                + (uri != null ? " - " : "")\r
+                                + (uri != null ? uri : "");\r
                     }\r
                 });\r
             } catch (DatabaseException e) {\r
@@ -216,7 +217,7 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog {
                             return null;\r
                         try {\r
                             try {\r
-                                return g.adapt(r, String.class);\r
+                                return DebugUtils.getSafeLabel(g, r);\r
                             } catch (Exception ex) {\r
                                 System.out.println("Exception thrown from restoreItemFromMemento");\r
                             }\r
index c65517c744e5787b9419f1ed4ee10282e5b00855..c1f9afd228124485eadcbf5292da0175958d01c6 100644 (file)
  *******************************************************************************/\r
 package org.simantics.debug.ui.internal;\r
 \r
+import java.util.Set;\r
+\r
 import org.eclipse.swt.widgets.Shell;\r
+import org.simantics.databoard.util.URIStringUtils;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.Session;\r
 import org.simantics.db.Statement;\r
 import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.PossibleIndexRoot;\r
 import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
@@ -53,6 +57,25 @@ public class DebugUtils {
         return name;\r
     }\r
 \r
+    public static String getPossibleRootRelativePath(ReadGraph graph, Resource r) throws DatabaseException {\r
+        Resource indexRoot = graph.syncRequest(new PossibleIndexRoot(r));\r
+        String uri = graph.getPossibleURI(r);\r
+        if (indexRoot != null && uri != null) {\r
+            Layer0 L0 = Layer0.getInstance(graph);\r
+            Set<Resource> types = graph.getTypes(indexRoot);\r
+            if (!types.contains(L0.Ontology)) {\r
+                Resource indexRootParent = graph.getPossibleObject(indexRoot, L0.PartOf);\r
+                if (indexRootParent != null) {\r
+                    String rootParentUri = graph.getPossibleURI(indexRootParent);\r
+                    if (rootParentUri != null) {\r
+                        return URIStringUtils.unescape( uri.substring(rootParentUri.length()+1) );\r
+                    }\r
+                }\r
+            }\r
+        }\r
+        return uri;\r
+    }\r
+\r
     @SuppressWarnings("unchecked")\r
     public static void addResource(Session s, GraphDebugger debugger) throws DatabaseException {\r
         Shell shell = debugger.getShell();\r