]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
ResourceCollectionVariableMap for defining custom variable spaces in SCL 71/571/2
authorAntti Villberg <antti.villberg@semantum.fi>
Tue, 30 May 2017 11:32:26 +0000 (14:32 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 31 May 2017 06:56:35 +0000 (09:56 +0300)
refs #7257

Change-Id: Ia523efed9fbcb9248e65938c790b347e6ad3a41a

bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ResourceCollectionVariableMap.java [new file with mode: 0644]
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 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