1 package org.simantics.modeling.adapters;
3 import java.util.Collections;
4 import java.util.HashMap;
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;
20 public class SCLImageRule implements ImageRule {
22 private Resource rule;
24 public SCLImageRule(ReadGraph graph, Resource rule) {
29 public boolean isCompatible(Class<?> contentType) {
30 return contentType.equals(Resource.class) || contentType.equals(Variable.class);
34 public Map<String, ImageDescriptor> getImage(ReadGraph graph, Object content) throws DatabaseException {
35 ModelingResources MOD = ModelingResources.getInstance(graph);
37 Variable ruleVariable = Variables.getVariable(graph, rule);
39 Function1<Object,List<Tuple>> getImages = ruleVariable.getPossiblePropertyValue(graph, MOD.SCLImageRule_getImages);
40 if(getImages == null) return Collections.emptyMap();
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));