1 package org.simantics.document.linking.actions;
3 import org.eclipse.ui.PlatformUI;
4 import org.simantics.Simantics;
5 import org.simantics.databoard.Bindings;
6 import org.simantics.db.ReadGraph;
7 import org.simantics.db.Resource;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.layer0.adapter.ActionFactory;
10 import org.simantics.db.request.Read;
11 import org.simantics.document.linking.ontology.DocumentLink;
12 import org.simantics.layer0.Layer0;
13 import org.simantics.utils.ui.ExceptionUtils;
14 import org.simantics.workbench.search.ISearchService;
15 import org.simantics.workbench.search.SearchQuery;
17 public class SearchLinksAction implements ActionFactory {
22 public Runnable create(Object target) {
23 if(!(target instanceof Resource))
25 final Resource resource = (Resource)target;
26 return new Runnable() {
31 String name = Simantics.getSession().syncRequest(new Read<String>() {
33 public String perform(ReadGraph graph)
34 throws DatabaseException {
35 Layer0 l0 = Layer0.getInstance(graph);
36 String s = graph.getPossibleRelatedValue(resource, l0.HasLabel, Bindings.STRING);
38 s = graph.getRelatedValue(resource, l0.HasName, Bindings.STRING);
42 ISearchService searchService = (ISearchService)PlatformUI.getWorkbench().getService(ISearchService.class);
43 SearchQuery query = new SearchQuery(name);
44 query.setSearchFlag("Name", "on");
45 query.setSearchFlag(DocumentLink.URIs.SearchFunction, "on");
46 searchService.performQuery(query, ISearchService.ResultBrowser.VIEW, true);
47 } catch (DatabaseException e) {
48 ExceptionUtils.logAndShowError("Cannot perform search",e);