]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ResourceCollectionVariableMap.java
Index tokenized lowercase versions of name and types for UI searches
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / ResourceCollectionVariableMap.java
1 /*******************************************************************************
2  * Copyright (c) 2017 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.layer0.variable;
13
14 import java.util.Collection;
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.exception.DatabaseException;
21
22 /**
23  * Used for defining custom variable spaces in SCL.
24  * See SCL module <code>Simantics/Variables</code> function
25  * <code>createVariableMap :: [Resource] -> VariableMap</code>.
26  *
27  * @author Antti Villberg
28  * @since 1.29.0
29  */
30 public class ResourceCollectionVariableMap extends VariableMapImpl {
31
32         final private Collection<Resource> resources;
33
34         public ResourceCollectionVariableMap(Collection<Resource> resources) {
35                 this.resources = resources;
36         }
37
38         @Override
39         public Map<String, Variable> getVariables(ReadGraph graph, Variable context, Map<String, Variable> map)
40                         throws DatabaseException {
41                 for(Resource resource : resources) {
42                         if(map == null) map = new HashMap<>();
43                         Variable child = new StandardGraphChildVariable(context, null, resource);
44                         map.put(child.getName(graph), child);
45                 }
46                 return map;
47         }
48
49 }