public final Resource Module_parameterOverride_Inverse;\r
public final Resource Module_redeclaration;\r
public final Resource Module_redeclaration_Inverse;\r
+ public final Resource ModulesSearchFunction;\r
public final Resource NormalDistribution;\r
public final Resource NormalDistribution_maxValue;\r
public final Resource NormalDistribution_maxValue_Inverse;\r
public static final String Module_parameterOverride_Inverse = "http://www.simantics.org/Sysdyn-1.1/Module/parameterOverride/Inverse";\r
public static final String Module_redeclaration = "http://www.simantics.org/Sysdyn-1.1/Module/redeclaration";\r
public static final String Module_redeclaration_Inverse = "http://www.simantics.org/Sysdyn-1.1/Module/redeclaration/Inverse";\r
+ public static final String ModulesSearchFunction = "http://www.simantics.org/Sysdyn-1.1/ModulesSearchFunction";\r
public static final String NormalDistribution = "http://www.simantics.org/Sysdyn-1.1/NormalDistribution";\r
public static final String NormalDistribution_maxValue = "http://www.simantics.org/Sysdyn-1.1/NormalDistribution/maxValue";\r
public static final String NormalDistribution_maxValue_Inverse = "http://www.simantics.org/Sysdyn-1.1/NormalDistribution/maxValue/Inverse";\r
Module_parameterOverride_Inverse = getResourceOrNull(graph, URIs.Module_parameterOverride_Inverse);\r
Module_redeclaration = getResourceOrNull(graph, URIs.Module_redeclaration);\r
Module_redeclaration_Inverse = getResourceOrNull(graph, URIs.Module_redeclaration_Inverse);\r
+ ModulesSearchFunction = getResourceOrNull(graph, URIs.ModulesSearchFunction);\r
NormalDistribution = getResourceOrNull(graph, URIs.NormalDistribution);\r
NormalDistribution_maxValue = getResourceOrNull(graph, URIs.NormalDistribution_maxValue);\r
NormalDistribution_maxValue_Inverse = getResourceOrNull(graph, URIs.NormalDistribution_maxValue_Inverse);\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.function;\r
+\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.HashSet;\r
+import java.util.Map;\r
+import java.util.Set;\r
+\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.Logger;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.genericrelation.Dependencies;\r
+import org.simantics.diagram.stubs.DiagramResource;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.operation.Layer0X;\r
+import org.simantics.scl.runtime.function.FunctionImpl4;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.workbench.search.NamedResource;\r
+import org.simantics.workbench.search.QueryResult;\r
+import org.simantics.workbench.search.SearchResult;\r
+import org.simantics.workbench.search.Searching;\r
+\r
+//import fi.vtt.apros.AprosBuiltins;\r
+import freemarker.template.TemplateException;\r
+\r
+/**\r
+ * modulesSearchFunction:\r
+ * (ReadGraph, query : String, maxResults : Integer) -> QueryResult\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class ModulesSearchFunction extends FunctionImpl4<IProgressMonitor, ReadGraph, String, Integer, Collection<SearchResult>> {\r
+\r
+ @Override\r
+ public Collection<SearchResult> apply(IProgressMonitor monitor, ReadGraph graph, String query, Integer maxResults) {\r
+ try {\r
+ Collection<Map<String, Object>> results = Searching.performSearch(graph,\r
+ Layer0X.getInstance(graph).Dependencies, query, maxResults);\r
+\r
+ return generateSearchResults(graph, results);\r
+ } catch (DatabaseException e) {\r
+ Logger.defaultLogError(e);\r
+ }\r
+ return null;\r
+ }\r
+\r
+ public static final Collection<SearchResult> generateSearchResults(ReadGraph graph,\r
+ Collection<Map<String, Object>> results) throws DatabaseException {\r
+ System.out.println(results.size());\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ SysdynResource SR = SysdynResource.getInstance(graph);\r
+ DiagramResource DIA = DiagramResource.getInstance(graph);\r
+\r
+ Collection<SearchResult> result = new ArrayList<SearchResult>(results.size());\r
+ Set<Resource> processed = new HashSet<Resource>();\r
+\r
+ for (Map<String, Object> r : results) {\r
+ Resource resource = (Resource) r.get(Dependencies.FIELD_RESOURCE);\r
+\r
+ // Ignore non-AprosModules\r
+ /*if (!graph.isInstanceOf(resource, APROS.AprosModule))\r
+ continue;\r
+\r
+ // Ignore attached default modules.\r
+ if (graph.hasStatement(resource, APROS.AttachedModule))\r
+ continue;*/\r
+\r
+ // Prevent index corruption from producing duplicate results.\r
+ if (!processed.add(resource))\r
+ continue;\r
+\r
+ // Prevent diagram elements from being collected into the results.\r
+ Collection<Resource> typeResources = graph.getTypes(resource);\r
+ if (typeResources.contains(DIA.Element))\r
+ continue;\r
+\r
+ Resource parent = (Resource) r.get(Dependencies.FIELD_PARENT);\r
+ String name = (String) r.get(Dependencies.FIELD_NAME);\r
+\r
+ SearchResult rst = new SearchResult();\r
+ rst.resource = NamedResource.of(graph, resource, name);\r
+ rst.parent = NamedResource.of(graph, parent);\r
+\r
+ Collection<Resource> principalTypeResources = graph.getPrincipalTypes(resource);\r
+ if (!typeResources.isEmpty()) {\r
+ rst.types = new ArrayList<NamedResource>(typeResources.size());\r
+ rst.principalTypes = new ArrayList<NamedResource>(principalTypeResources.size());\r
+ for (Resource t : typeResources) {\r
+ String aprosName = graph.getPossibleRelatedValue(t, L0.HasName, Bindings.STRING);\r
+ if (aprosName == null)\r
+ aprosName = NameUtils.getSafeLabel(graph, t);\r
+ NamedResource nr = NamedResource.of(graph, t, aprosName);\r
+ rst.types.add(nr);\r
+ if (principalTypeResources.contains(t))\r
+ rst.principalTypes.add(nr);\r
+ }\r
+ }\r
+\r
+ result.add(rst);\r
+ }\r
+ return result;\r
+ }\r
+\r
+}\r
import org.simantics.sysdyn.ui.editor.SysdynEditorNamingService;\r
import org.simantics.ui.workbench.IEditorNamingService;\r
import org.simantics.utils.FileUtils;\r
+import org.simantics.workbench.ontology.WorkbenchResource;\r
\r
public class SysdynProject extends AbstractProjectFeature {\r
private static final String DEFAULT_PERSPECTIVE = "org.simantics.sysdyn.ui.perspective";\r
}\r
\r
\r
- VirtualGraphSupport support = session.getService(VirtualGraphSupport.class);\r
+ final VirtualGraphSupport support = session.getService(VirtualGraphSupport.class);\r
\r
support.getWorkspacePersistent("experiments");\r
support.getWorkspacePersistent("profiles");\r
- // support.getWorkspacePersistent("preferences");\r
+ support.getWorkspacePersistent("preferences");\r
support.getWorkspacePersistent("issues");\r
+ \r
+ // Before activating, make sure that the necessary activations have been installed into the project.\r
+ //final Set<Resource> requiredActivations = new HashSet<Resource>();\r
+ //requiredActivations.add(APROS.IndexActivation);\r
+ \r
+ session.syncRequest(new WriteRequest(support.getWorkspacePersistent("activations")) {\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+\r
+ final SysdynResource SR = SysdynResource.getInstance(graph);\r
+ \r
+ //for (Resource activation : graph.getObjects(project.get(), L0X.HasActivation))\r
+ // requiredActivations.remove(activation);\r
+ //for (Resource requiredActivation : requiredActivations)\r
+ // if (requiredActivation != null)\r
+ // graph.claim(project.get(), L0X.HasActivation, null, requiredActivation);\r
+ \r
+ // Initialize Modules function as workbench search function.\r
+ graph.syncRequest(new WriteRequest(support.getWorkspacePersistent("preferences")) {\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ WorkbenchResource WB = WorkbenchResource.getInstance(graph);\r
+ graph.deny(project.get(), WB.HasWorkbenchSearchFunction);\r
+ graph.claim(project.get(), WB.HasWorkbenchSearchFunction, SR.ModulesSearchFunction);\r
+ }\r
+ });\r
+ }\r
+ });\r
\r
} catch (DatabaseException e) {\r
\r