]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/Sources.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.spreadsheet.graph / src / org / simantics / spreadsheet / graph / Sources.java
1 package org.simantics.spreadsheet.graph;
2
3 import java.util.Collections;
4 import java.util.HashMap;
5 import java.util.List;
6 import java.util.Map;
7
8 import org.simantics.Simantics;
9 import org.simantics.db.ReadGraph;
10 import org.simantics.db.Resource;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.db.layer0.adapter.Instances;
13 import org.simantics.db.layer0.request.VariableRead;
14 import org.simantics.db.layer0.variable.Variable;
15 import org.simantics.db.layer0.variable.Variables;
16 import org.simantics.scl.runtime.function.Function;
17 import org.simantics.spreadsheet.resource.SpreadsheetResource;
18
19 public class Sources extends VariableRead<Map<String,Variable>> {
20
21         public Sources(Variable variable) {
22                 super(variable);
23         }
24
25         @Override
26         public Map<String,Variable> perform(ReadGraph graph) throws DatabaseException {
27                 
28                 SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph);
29                 Instances query = graph.adapt(SHEET.SourceContribution, Instances.class);
30                 Resource indexRoot = variable.getIndexRoot(graph);
31                 if(indexRoot == null) return Collections.emptyMap();
32                 
33                 Map<String,Variable> result = new HashMap<String,Variable>();
34                 for(Resource source : query.find(graph, indexRoot)) {
35
36                         Variable sv = Variables.getVariable(graph, source);
37                         @SuppressWarnings("rawtypes")
38                         Function f = sv.getPropertyValue(graph, SHEET.SourceContribution_function);
39                         List<Variable> in = Simantics.<List<Variable>>applySCLRead(graph, f, variable.getRepresents(graph));
40                         for(Variable var : in) {
41                                 Function f2 = sv.getPropertyValue(graph, SHEET.SourceContribution_labeler);
42                                 String key = Simantics.<String>applySCLRead(graph, f2, var);
43                                 result.put(key, var);
44                         }
45                 }
46                 return result;
47         }
48         
49 }