]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "(refs #7259) Added Iterator.filter and MSet.filterInPlace"
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 31 May 2017 12:49:02 +0000 (15:49 +0300)
committerGerrit Code Review <gerrit2@www.simantics.org>
Wed, 31 May 2017 12:49:02 +0000 (15:49 +0300)
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ResourceCollectionVariableMap.java [new file with mode: 0644]
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java
bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph
bundles/org.simantics.scl.db/scl/Simantics/Variables.scl

diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ResourceCollectionVariableMap.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ResourceCollectionVariableMap.java
new file mode 100644 (file)
index 0000000..9f03268
--- /dev/null
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.layer0.variable;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+
+/**
+ * Used for defining custom variable spaces in SCL.
+ * See SCL module <code>Simantics/Variables</code> function
+ * <code>createVariableMap :: [Resource] -> VariableMap</code>.
+ *
+ * @author Antti Villberg
+ * @since 1.29.0
+ */
+public class ResourceCollectionVariableMap extends VariableMapImpl {
+
+       final private Collection<Resource> resources;
+
+       public ResourceCollectionVariableMap(Collection<Resource> resources) {
+               this.resources = resources;
+       }
+
+       @Override
+       public Map<String, Variable> getVariables(ReadGraph graph, Variable context, Map<String, Variable> map)
+                       throws DatabaseException {
+               for(Resource resource : resources) {
+                       if(map == null) map = new HashMap<>();
+                       Variable child = new StandardGraphChildVariable(context, null, resource);
+                       map.put(child.getName(graph), child);
+               }
+               return map;
+       }
+
+}
index 17fc21ebb911bb2130ff3cd10c662f9a083b9162..cffd74727c8000ed8e84cb15dfc582480702c106 100644 (file)
@@ -264,7 +264,9 @@ public class StandardGraphChildVariable extends AbstractChildVariable {
 
        protected VariableMap getPossibleChildVariableMap(ReadGraph graph) throws DatabaseException {
            if(resource == null) return All.standardChildDomainChildren;
-               return graph.getPossibleRelatedValue2(resource, Layer0.getInstance(graph).domainChildren, this);
+           Resource domainChildren = Layer0.getInstance(graph).domainChildren;
+               return graph.getPossibleRelatedValue2(resource, domainChildren, 
+                               new StandardGraphPropertyVariable(graph, this, domainChildren));
        }
        
        @Override
index e71c13997a661d9c729872e23054efe5883b3824..cd3f1f31f996a4d8eb4a26237b7ca09baab4870a 100644 (file)
@@ -365,6 +365,13 @@ IMAGES.ComponentLock : IMAGE.PngImage
 MBC
     @VP.dropActionContribution MOD.Subscription MAC.Actions.SubscriptionDropAction 1.0
 
+MOD.sclChildRule : L0.Template
+    @template %action %expression
+        %action : MOD.SCLChildRule
+          MOD.SCLChildRule.getChildren _ : MOD.SCLValue
+            L0.SCLValue.expression %expression
+            L0.HasValueType "Resource -> <ReadGraph> [Resource]"
+
 MOD.sclAction : L0.Template
     @template %action %expression
         %action : MOD.SCLAction
index 1def7102cd72382f27baa20bc058b219048f80f8..a8ffd13db76dedbe5ff5093e5e9ee722a96c7aea 100644 (file)
@@ -90,6 +90,10 @@ importJava "org.simantics.db.layer0.function.All" where
 importJava "org.simantics.db.layer0.variable.VariableMap" where
     data VariableMap
 
+importJava "org.simantics.db.layer0.variable.ResourceCollectionVariableMap" where
+    @JavaName "<init>"
+    createVariableMap :: [Resource] -> VariableMap
+
 importJava "org.simantics.db.layer0.variable.ValueAccessor" where
     data ValueAccessor