--- /dev/null
+package org.simantics.document.linking.actions;\r
+\r
+import org.eclipse.ui.PlatformUI;\r
+import org.simantics.Simantics;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.adapter.ActionFactory;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.document.linking.ontology.DocumentLink;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
+import org.simantics.workbench.search.ISearchService;\r
+import org.simantics.workbench.search.SearchQuery;\r
+\r
+public class SearchLinksAction implements ActionFactory {\r
+ \r
+ \r
+ \r
+ @Override\r
+ public Runnable create(Object target) {\r
+ if(!(target instanceof Resource))\r
+ return null;\r
+ final Resource resource = (Resource)target;\r
+ return new Runnable() {\r
+ \r
+ @Override\r
+ public void run() {\r
+ try {\r
+ String name = Simantics.getSession().syncRequest(new Read<String>() {\r
+ @Override\r
+ public String perform(ReadGraph graph)\r
+ throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ String s = graph.getPossibleRelatedValue(resource, l0.HasLabel, Bindings.STRING);\r
+ if (s == null)\r
+ s = graph.getRelatedValue(resource, l0.HasName, Bindings.STRING); \r
+ return s;\r
+ }\r
+ });\r
+ ISearchService searchService = (ISearchService)PlatformUI.getWorkbench().getService(ISearchService.class);\r
+ SearchQuery query = new SearchQuery(name);\r
+ query.setSearchFlag("Name", "on");\r
+ query.setSearchFlag(DocumentLink.URIs.SearchFunction, "on");\r
+ searchService.performQuery(query, ISearchService.ResultBrowser.VIEW, true);\r
+ } catch (DatabaseException e) {\r
+ ExceptionUtils.logAndShowError("Cannot perform search",e);\r
+ }\r
+ \r
+ \r
+ }\r
+ };\r
+ }\r
+\r
+}\r