MOD.SCLLabelRule <T VP.VisualsRule
>-- MOD.SCLLabelRule.getLabels ==> "Resource -> <ReadGraph> [String]" <R L0.HasProperty : L0.FunctionalRelation
+MOD.SCLImageRule <T VP.VisualsRule
+ >-- MOD.SCLImageRule.getImages ==> "Resource -> <ReadGraph> [(String,ImageDescriptor)]" <R L0.HasProperty : L0.FunctionalRelation
+
MOD.SCLAction <T ACT.Action
--> MOD.SCLAction.action ==> "Resource -> <Proc> ()" <R L0.HasProperty : L0.FunctionalRelation
L0.SCLValue.expression %expression
L0.HasValueType "Resource -> <ReadGraph> [String]"
+MOD.sclImageRule : L0.Template
+ @template %action %expression
+ %action : MOD.SCLImageRule
+ MOD.SCLImageRule.getImages _ : MOD.SCLValue
+ L0.SCLValue.expression %expression
+ L0.HasValueType "Resource -> <ReadGraph> [(String,ImageDescriptor)]"
+
MOD.sclAction : L0.Template
@template %action %expression
%action : MOD.SCLAction
</type>
</target>
+ <target interface="org.simantics.browsing.ui.model.visuals.VisualsRule">
+ <type uri="http://www.simantics.org/Modeling-0.0/SCLImageRule"
+ class="org.simantics.modeling.adapters.SCLImageRule">
+ <graph />
+ <this />
+ </type>
+ </target>
+
<target interface="org.simantics.browsing.ui.model.tests.Test">
<type uri="http://www.simantics.org/Modeling-0.0/SCLTest"
class="org.simantics.modeling.adapters.SCLTest">
--- /dev/null
+package org.simantics.modeling.adapters;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.simantics.Simantics;
+import org.simantics.browsing.ui.model.images.ImageRule;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.layer0.variable.Variables;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.scl.runtime.function.Function1;
+import org.simantics.scl.runtime.tuple.Tuple;
+
+public class SCLImageRule implements ImageRule {
+
+ private Resource rule;
+
+ public SCLImageRule(ReadGraph graph, Resource rule) {
+ this.rule = rule;
+ }
+
+ @Override
+ public boolean isCompatible(Class<?> contentType) {
+ return contentType.equals(Resource.class) || contentType.equals(Variable.class);
+ }
+
+ @Override
+ public Map<String, ImageDescriptor> getImage(ReadGraph graph, Object content) throws DatabaseException {
+ ModelingResources MOD = ModelingResources.getInstance(graph);
+
+ Variable ruleVariable = Variables.getVariable(graph, rule);
+
+ Function1<Object,List<Tuple>> getImages = ruleVariable.getPossiblePropertyValue(graph, MOD.SCLImageRule_getImages);
+ if(getImages == null) return Collections.emptyMap();
+
+ List<Tuple> value = Simantics.applySCLRead(graph, getImages, content);
+ Map<String,ImageDescriptor> result = new HashMap<>();
+ for(Tuple t : value) {
+ result.put((String)t.get(0), (ImageDescriptor)t.get(1));
+ }
+ return result;
+
+ }
+
+}