X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fadapters%2FSCLTest.java;h=7f87f3cd9eee1c1856d7da554d1ebe64d28fdec1;hb=ad0e5bf4b34705988e23c9ee3f8e4fcbb760c701;hp=7444939a8f3e96aa091983be3439a45a46e9cde1;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SCLTest.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SCLTest.java index 7444939a8..7f87f3cd9 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SCLTest.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SCLTest.java @@ -1,49 +1,49 @@ -package org.simantics.modeling.adapters; - -import org.simantics.browsing.ui.model.tests.Test; -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.SCLContext; -import org.simantics.scl.runtime.function.Function1; - -public class SCLTest implements Test { - - private Resource rule; - - public SCLTest(ReadGraph graph, Resource rule) { - this.rule = rule; - } - - @Override - public boolean isCompatible(Class contentType) { - return contentType.equals(Resource.class) || contentType.equals(Variable.class); - } - - @Override - public boolean test(ReadGraph graph, Object content) throws DatabaseException { - - ModelingResources MOD = ModelingResources.getInstance(graph); - - Variable ruleVariable = Variables.getVariable(graph, rule); - Function1 test = ruleVariable.getPossiblePropertyValue(graph, MOD.SCLTest_test); - if(test == null) return false; - - SCLContext sclContext = SCLContext.getCurrent(); - Object oldGraph = sclContext.get("graph"); - try { - sclContext.put("graph", graph); - Object value = test.apply((Resource)content); - return (Boolean)value; - } catch (Throwable t) { - throw new DatabaseException(t); - } finally { - sclContext.put("graph", oldGraph); - } - - } - -} +package org.simantics.modeling.adapters; + +import org.simantics.browsing.ui.model.tests.Test; +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.SCLContext; +import org.simantics.scl.runtime.function.Function1; + +public class SCLTest implements Test { + + private Resource rule; + + public SCLTest(ReadGraph graph, Resource rule) { + this.rule = rule; + } + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class) || contentType.equals(Variable.class); + } + + @Override + public boolean test(ReadGraph graph, Object content) throws DatabaseException { + + ModelingResources MOD = ModelingResources.getInstance(graph); + + Variable ruleVariable = Variables.getVariable(graph, rule); + Function1 test = ruleVariable.getPossiblePropertyValue(graph, MOD.SCLTest_test); + if(test == null) return false; + + SCLContext sclContext = SCLContext.getCurrent(); + Object oldGraph = sclContext.get("graph"); + try { + sclContext.put("graph", graph); + Object value = test.apply((Resource)content); + return (Boolean)value; + } catch (Throwable t) { + throw new DatabaseException(t); + } finally { + sclContext.put("graph", oldGraph); + } + + } + +}