From 3e4337c00ad28af2d4755bc452f4e48a0b3334f6 Mon Sep 17 00:00:00 2001 From: miettinen Date: Fri, 13 Sep 2013 12:56:08 +0000 Subject: [PATCH] Ctrl+F search to Sysdyn (refs #2873). Changed some visibility definitions of Simantics ssarch to allow inheriting SearchTrim. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27833 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.sysdyn.ui/META-INF/MANIFEST.MF | 3 +- org.simantics.sysdyn.ui/plugin.xml | 14 +++ .../ui/function/ModulesSearchFunction.java | 66 +++++++++-- .../sysdyn/ui/handlers/FindReplaceDialog.java | 107 ++++++++++++++++++ .../ui/handlers/FindReplaceHandler.java | 61 ++++++++++ .../sysdyn/ui/handlers/FindSearchTrim.java | 38 +++++++ 6 files changed, 280 insertions(+), 9 deletions(-) create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/FindReplaceDialog.java create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/FindReplaceHandler.java create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/FindSearchTrim.java diff --git a/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF b/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF index 25222644..119c139f 100644 --- a/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF +++ b/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF @@ -56,7 +56,8 @@ Require-Bundle: org.simantics.layer0.utils;bundle-version="0.6.2", org.eclipse.nebula.widgets.tablecombo;bundle-version="1.0.0", org.simantics.fmu;bundle-version="1.0.0", org.simantics.jfreechart;bundle-version="1.0.0", - org.simantics.db.indexing;bundle-version="1.1.0" + org.simantics.db.indexing;bundle-version="1.1.0", + org.simantics.workbench Bundle-Activator: org.simantics.sysdyn.ui.Activator Bundle-ActivationPolicy: lazy Export-Package: org.simantics.sysdyn.ui.browser.nodes diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index 5e5a19a9..69dc4a06 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -1004,6 +1004,11 @@ + + @@ -1087,6 +1092,11 @@ label="Paste" style="push"> + + + + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/function/ModulesSearchFunction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/function/ModulesSearchFunction.java index e1c422e5..c228b394 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/function/ModulesSearchFunction.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/function/ModulesSearchFunction.java @@ -18,18 +18,28 @@ import java.util.Map; import java.util.Set; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.utils.Logger; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; +import org.simantics.db.exception.ServiceException; import org.simantics.db.layer0.genericrelation.Dependencies; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.modeling.ui.diagramEditor.DiagramEditor; import org.simantics.operation.Layer0X; import org.simantics.scl.runtime.function.FunctionImpl5; import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.handlers.FindSearchTrim; +import org.simantics.sysdyn.ui.handlers.FindSearchTrim.Scope; import org.simantics.workbench.search.NamedResource; import org.simantics.workbench.search.SearchResult; import org.simantics.workbench.search.Searching; @@ -39,6 +49,7 @@ import org.simantics.workbench.search.Searching; * (IProgressMonitor, ReadGraph, model : Resource, query : String, maxResults : Integer) -> QueryResult * * @author Tuukka Lehtonen + * @author Tuomas Miettinen */ public class ModulesSearchFunction extends FunctionImpl5> { @@ -47,18 +58,53 @@ public class ModulesSearchFunction extends FunctionImpl5 apply(IProgressMonitor monitor, ReadGraph graph, Resource model, String query, Integer maxResults) { try { - Collection> results = Searching.performSearch(graph, - Layer0X.getInstance(graph).Dependencies, model, query, MAX_RESULTS); - - return generateSearchResults(graph, results); + // Check whether only currently open diagram is searched + String filteredQuery = query.replace(FindSearchTrim.CURRENT_DIAGRAM_OPTION, ""); + Collection> results = Searching.performSearch(graph, + Layer0X.getInstance(graph).Dependencies, model, filteredQuery, MAX_RESULTS); + + if (filteredQuery.equals(query)) + return generateSearchResults(graph, results, Scope.ALL_MODELS); + else + return generateSearchResults(graph, results, Scope.CURRENT_DIAGRAM); } catch (DatabaseException e) { Logger.defaultLogError(e); } return null; } + + private static boolean resourceFoundInCurrentDiagram(ReadGraph graph, Resource diagram) throws ManyObjectsForFunctionalRelationException, ServiceException { + + DiagramEditor editor = null; + IWorkbench workbench = PlatformUI.getWorkbench(); + IWorkbenchWindow[] windows = workbench.getWorkbenchWindows(); + // To ask for the active window doesn't work, so browse through all + // windows and when an active editor is found, use that + for (IWorkbenchWindow window : windows) { + IWorkbenchPage page = window.getActivePage(); + if (page != null) { + try { + editor = (DiagramEditor)page.getActiveEditor(); + if (editor != null) + // Found one + break; + } catch (ClassCastException e) { + continue; + } + } + } + if (editor != null) { + Resource inputResource = editor.getInputResource(); + ModelingResources MOD = ModelingResources.getInstance(graph); + Resource editorResource = graph.getPossibleObject(inputResource, MOD.DiagramToComposite); + if (diagram.equalsResource(editorResource)) + return true; + } + return false; + } - public static final Collection generateSearchResults(ReadGraph graph, - Collection> results) throws DatabaseException { + private static final Collection generateSearchResults(ReadGraph graph, + Collection> results, Scope scope) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); DiagramResource DIA = DiagramResource.getInstance(graph); SysdynResource SYSDYN = SysdynResource.getInstance(graph); @@ -84,9 +130,13 @@ public class ModulesSearchFunction extends FunctionImpl5