From: Tuukka Lehtonen Date: Thu, 8 Dec 2016 21:48:11 +0000 (+0200) Subject: Fixed labels for search results restored from previous search memento X-Git-Tag: v1.25.0~15 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=50bf4a2427626eed7ff59449c72e72ab49434bcb;ds=sidebyside Fixed labels for search results restored from previous search memento 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 --- diff --git a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/SearchResourceDialog.java b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/SearchResourceDialog.java index 1ae23d719..ffdc68175 100644 --- a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/SearchResourceDialog.java +++ b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/SearchResourceDialog.java @@ -115,11 +115,12 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog { @Override public String perform(ReadGraph g) throws DatabaseException { String name = NameUtils.getSafeName(g, r); - String uri = g.getPossibleURI(r); - String label = "[" + r.getResourceId() + "] - " + name; - if (uri != null) - label = label + " - " + uri; - return label; + String uri = DebugUtils.getPossibleRootRelativePath(g, r); + return + "[" + r.getResourceId() + "] - " + + name + + (uri != null ? " - " : "") + + (uri != null ? uri : ""); } }); } catch (DatabaseException e) { @@ -216,7 +217,7 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog { return null; try { try { - return g.adapt(r, String.class); + return DebugUtils.getSafeLabel(g, r); } catch (Exception ex) { System.out.println("Exception thrown from restoreItemFromMemento"); } diff --git a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/DebugUtils.java b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/DebugUtils.java index c65517c74..c1f9afd22 100644 --- a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/DebugUtils.java +++ b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/DebugUtils.java @@ -12,12 +12,16 @@ *******************************************************************************/ package org.simantics.debug.ui.internal; +import java.util.Set; + import org.eclipse.swt.widgets.Shell; +import org.simantics.databoard.util.URIStringUtils; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.Statement; import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.PossibleIndexRoot; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; @@ -53,6 +57,25 @@ public class DebugUtils { return name; } + public static String getPossibleRootRelativePath(ReadGraph graph, Resource r) throws DatabaseException { + Resource indexRoot = graph.syncRequest(new PossibleIndexRoot(r)); + String uri = graph.getPossibleURI(r); + if (indexRoot != null && uri != null) { + Layer0 L0 = Layer0.getInstance(graph); + Set types = graph.getTypes(indexRoot); + if (!types.contains(L0.Ontology)) { + Resource indexRootParent = graph.getPossibleObject(indexRoot, L0.PartOf); + if (indexRootParent != null) { + String rootParentUri = graph.getPossibleURI(indexRootParent); + if (rootParentUri != null) { + return URIStringUtils.unescape( uri.substring(rootParentUri.length()+1) ); + } + } + } + } + return uri; + } + @SuppressWarnings("unchecked") public static void addResource(Session s, GraphDebugger debugger) throws DatabaseException { Shell shell = debugger.getShell();