]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
SCL Image Rule 77/1277/3
authorAntti Villberg <antti.villberg@semantum.fi>
Sat, 2 Dec 2017 20:12:15 +0000 (22:12 +0200)
committerAntti Villberg <antti.villberg@semantum.fi>
Sun, 3 Dec 2017 05:22:44 +0000 (07:22 +0200)
refs #7657

Change-Id: I912bb432b45c06c25d242299924495f5cc59ea0f

bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph
bundles/org.simantics.modeling.ontology/graph/scl/SCLMain.scl
bundles/org.simantics.modeling/adapters.xml
bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SCLImageRule.java [new file with mode: 0644]

index d392fa2cbaf7322be3a7a21684a547fe87803bd5..e3c551d0a2f45faf7d361a98e6c90bc77fa3eae1 100644 (file)
@@ -23,6 +23,9 @@ MOD.SCLChildRule <T VP.ChildRule
 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 
 
@@ -382,6 +385,13 @@ MOD.sclLabelRule : L0.Template
             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
index f517dfbe8956bef3ddda7bd4f65d562d37246773..d0a1bafeb17a7d3ce6be6ca65c4a31b52459edf9 100644 (file)
@@ -1,2 +1,3 @@
 include "Simantics/All"
 include "Simantics/SelectionView/TabContribution/SVG"
+include "Simantics/Testing"
index b74449f822ed4ad9eb5084f70f7a4992fe5f2085..d96981fd4c1d2b788bb08c98661230208217dd66 100644 (file)
         </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">
diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SCLImageRule.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SCLImageRule.java
new file mode 100644 (file)
index 0000000..ae4dd57
--- /dev/null
@@ -0,0 +1,51 @@
+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;
+        
+    }
+
+}