From: Antti Villberg Date: Tue, 30 May 2017 11:32:26 +0000 (+0300) Subject: ResourceCollectionVariableMap for defining custom variable spaces in SCL X-Git-Tag: v1.29.0~10 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F71%2F571%2F2;p=simantics%2Fplatform.git ResourceCollectionVariableMap for defining custom variable spaces in SCL refs #7257 Change-Id: Ia523efed9fbcb9248e65938c790b347e6ad3a41a --- 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.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