From: Hannu Niemistö Date: Wed, 31 May 2017 12:49:02 +0000 (+0300) Subject: Merge "(refs #7259) Added Iterator.filter and MSet.filterInPlace" X-Git-Tag: v1.29.0~6 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=57fea6afc7ab4f548d1ccba0733416529fc4526d;hp=5fac43d7537c84cb2874e1d8c16d93212033a796 Merge "(refs #7259) Added Iterator.filter and MSet.filterInPlace" --- 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 index 000000000..9f0326831 --- /dev/null +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ResourceCollectionVariableMap.java @@ -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 Simantics/Variables function + * createVariableMap :: [Resource] -> VariableMap. + * + * @author Antti Villberg + * @since 1.29.0 + */ +public class ResourceCollectionVariableMap extends VariableMapImpl { + + final private Collection resources; + + public ResourceCollectionVariableMap(Collection resources) { + this.resources = resources; + } + + @Override + public Map getVariables(ReadGraph graph, Variable context, Map 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; + } + +} diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java index 17fc21ebb..cffd74727 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java @@ -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 diff --git a/bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph b/bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph index e71c13997..cd3f1f31f 100644 --- a/bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph +++ b/bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph @@ -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 -> [Resource]" + MOD.sclAction : L0.Template @template %action %expression %action : MOD.SCLAction diff --git a/bundles/org.simantics.scl.db/scl/Simantics/Variables.scl b/bundles/org.simantics.scl.db/scl/Simantics/Variables.scl index 1def7102c..a8ffd13db 100644 --- a/bundles/org.simantics.scl.db/scl/Simantics/Variables.scl +++ b/bundles/org.simantics.scl.db/scl/Simantics/Variables.scl @@ -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 "" + createVariableMap :: [Resource] -> VariableMap + importJava "org.simantics.db.layer0.variable.ValueAccessor" where data ValueAccessor