From 74045ae2a729ae2ec57db0816709a948eea7d392 Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Sat, 2 Dec 2017 22:12:15 +0200 Subject: [PATCH] SCL Image Rule refs #7657 Change-Id: I912bb432b45c06c25d242299924495f5cc59ea0f --- .../graph/ModelingViewpoint.pgraph | 10 ++++ .../graph/scl/SCLMain.scl | 1 + bundles/org.simantics.modeling/adapters.xml | 8 +++ .../modeling/adapters/SCLImageRule.java | 51 +++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SCLImageRule.java diff --git a/bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph b/bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph index d392fa2cb..e3c551d0a 100644 --- a/bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph +++ b/bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph @@ -23,6 +23,9 @@ MOD.SCLChildRule -- MOD.SCLLabelRule.getLabels ==> "Resource -> [String]" -- MOD.SCLImageRule.getImages ==> "Resource -> [(String,ImageDescriptor)]" MOD.SCLAction.action ==> "Resource -> ()" [String]" +MOD.sclImageRule : L0.Template + @template %action %expression + %action : MOD.SCLImageRule + MOD.SCLImageRule.getImages _ : MOD.SCLValue + L0.SCLValue.expression %expression + L0.HasValueType "Resource -> [(String,ImageDescriptor)]" + MOD.sclAction : L0.Template @template %action %expression %action : MOD.SCLAction diff --git a/bundles/org.simantics.modeling.ontology/graph/scl/SCLMain.scl b/bundles/org.simantics.modeling.ontology/graph/scl/SCLMain.scl index f517dfbe8..d0a1bafeb 100644 --- a/bundles/org.simantics.modeling.ontology/graph/scl/SCLMain.scl +++ b/bundles/org.simantics.modeling.ontology/graph/scl/SCLMain.scl @@ -1,2 +1,3 @@ include "Simantics/All" include "Simantics/SelectionView/TabContribution/SVG" +include "Simantics/Testing" diff --git a/bundles/org.simantics.modeling/adapters.xml b/bundles/org.simantics.modeling/adapters.xml index b74449f82..d96981fd4 100644 --- a/bundles/org.simantics.modeling/adapters.xml +++ b/bundles/org.simantics.modeling/adapters.xml @@ -189,6 +189,14 @@ + + + + + + + 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 index 000000000..ae4dd57d5 --- /dev/null +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SCLImageRule.java @@ -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 getImage(ReadGraph graph, Object content) throws DatabaseException { + ModelingResources MOD = ModelingResources.getInstance(graph); + + Variable ruleVariable = Variables.getVariable(graph, rule); + + Function1> getImages = ruleVariable.getPossiblePropertyValue(graph, MOD.SCLImageRule_getImages); + if(getImages == null) return Collections.emptyMap(); + + List value = Simantics.applySCLRead(graph, getImages, content); + Map result = new HashMap<>(); + for(Tuple t : value) { + result.put((String)t.get(0), (ImageDescriptor)t.get(1)); + } + return result; + + } + +} -- 2.47.1