]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SCLImageRule.java
Expose proxied subject in GroupProxySymbolItem
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / adapters / SCLImageRule.java
1 package org.simantics.modeling.adapters;
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.eclipse.jface.resource.ImageDescriptor;
9 import org.simantics.Simantics;
10 import org.simantics.browsing.ui.model.images.ImageRule;
11 import org.simantics.db.ReadGraph;
12 import org.simantics.db.Resource;
13 import org.simantics.db.exception.DatabaseException;
14 import org.simantics.db.layer0.variable.Variable;
15 import org.simantics.db.layer0.variable.Variables;
16 import org.simantics.modeling.ModelingResources;
17 import org.simantics.scl.runtime.function.Function1;
18 import org.simantics.scl.runtime.tuple.Tuple;
19
20 public class SCLImageRule implements ImageRule {
21
22     private Resource rule;
23     
24     public SCLImageRule(ReadGraph graph, Resource rule) {
25         this.rule = rule;
26     }
27     
28     @Override
29     public boolean isCompatible(Class<?> contentType) {
30         return contentType.equals(Resource.class) || contentType.equals(Variable.class);
31     }
32
33     @Override
34     public Map<String, ImageDescriptor> getImage(ReadGraph graph, Object content) throws DatabaseException {
35         ModelingResources MOD = ModelingResources.getInstance(graph);
36         
37         Variable ruleVariable = Variables.getVariable(graph, rule);
38
39         Function1<Object,List<Tuple>> getImages = ruleVariable.getPossiblePropertyValue(graph, MOD.SCLImageRule_getImages);
40         if(getImages == null) return Collections.emptyMap();
41
42         List<Tuple> value = Simantics.applySCLRead(graph, getImages, content);
43         Map<String,ImageDescriptor> result = new HashMap<>();
44         for(Tuple t : value) {
45                 result.put((String)t.get(0), (ImageDescriptor)t.get(1));
46         }
47         return result;
48         
49     }
50
51 }