]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Improvements to SCL browse context contributions 55/3155/3
authorAntti Villberg <antti.villberg@semantum.fi>
Mon, 26 Aug 2019 07:00:30 +0000 (10:00 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 26 Aug 2019 07:20:05 +0000 (07:20 +0000)
gitlab #364

Change-Id: Iaa5d45e3c1a1023ca62110066947d4a822037991

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

index 47931cc4f1172e7eb0bc631471114d8fd648209b..98b7aa98120c69217aba16c8a9cf709a98bccbf0 100644 (file)
@@ -32,6 +32,9 @@ MOD.SCLLabelForegroundColorRule <T VP.VisualsRule
 MOD.SCLLabelBackgroundColorRule <T VP.VisualsRule
   >-- MOD.SCLLabelBackgroundColorRule.getColor ==> "Resource -> Maybe (Double, Double, Double) -> String -> Integer -> <ReadGraph> Maybe (Double, Double, Double)]" <R L0.HasProperty : L0.FunctionalRelation
 
+MOD.SCLCheckedStateRule <T VP.VisualsRule
+  >-- MOD.SCLCheckedStateRule.getState ==> "BrowseNodeRule CheckedState" <R L0.HasProperty : L0.FunctionalRelation
+
 MOD.SCLAction <T ACT.Action
   --> MOD.SCLAction.action ==> "Resource -> <Proc> ()" <R L0.HasProperty : L0.FunctionalRelation 
 
@@ -412,6 +415,13 @@ MOD.sclLabelBackgroundColorRule : L0.Template
             L0.SCLValue.expression %expression
             L0.HasValueType "Resource -> Maybe (Double, Double, Double) -> String -> Integer -> <ReadGraph> Maybe (Double, Double, Double)"
 
+MOD.sclCheckedStateRule : L0.Template
+    @template %action %expression
+        %action : MOD.SCLCheckedStateRule
+          MOD.SCLCheckedStateRule.getState _ : MOD.SCLValue
+            L0.SCLValue.expression %expression
+            L0.HasValueType "Browsable a => a -> <ReadGraph> CheckedState"
+
 MOD.sclAction : L0.Template
     @template %action %expression
         %action : MOD.SCLAction
index 7693586d8029b79dcb5ccc80d838e3821644e791..063a661c94bbd6bab2285b7df0826562438ae6b8 100644 (file)
         </type>
     </target>
 
+    <target interface="org.simantics.browsing.ui.model.visuals.VisualsRule">
+        <type uri="http://www.simantics.org/Modeling-0.0/SCLCheckedStateRule"
+            class="org.simantics.modeling.adapters.SCLCheckedStateRule">
+            <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/SCLCheckedStateRule.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SCLCheckedStateRule.java
new file mode 100644 (file)
index 0000000..0c7da8d
--- /dev/null
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.modeling.adapters;
+
+import org.simantics.browsing.ui.CheckedState;
+import org.simantics.browsing.ui.model.check.CheckedStateRule;
+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.VariableOrResource;
+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;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SCLCheckedStateRule implements CheckedStateRule {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(SCLCheckedStateRule.class);
+
+    private Resource rule;
+
+    public SCLCheckedStateRule(ReadGraph graph, Resource rule) {
+        this.rule = rule;
+    }
+
+    @Override
+    public boolean isCompatible(Class<?> contentType) {
+        return contentType.equals(Resource.class) || contentType.equals(Variable.class);
+    }
+
+    @Override
+    public CheckedState getCheckedState(ReadGraph graph, Object content) throws DatabaseException {
+
+        ModelingResources MOD = ModelingResources.getInstance(graph);
+
+        Variable ruleVariable = Variables.getVariable(graph, rule);
+
+        Function1<Object,CheckedState> getLabels = ruleVariable.getPossiblePropertyValue(graph, MOD.SCLCheckedStateRule_getState);
+        if(getLabels == null) {
+            LOGGER.warn("Didn't find value for subject={}, predicate={}.", rule, ModelingResources.URIs.SCLCheckedStateRule_getState);
+            return CheckedState.NOT_CHECKED;
+        }
+
+        SCLContext sclContext = SCLContext.getCurrent();
+        Object oldGraph = sclContext.get("graph");
+        try {
+            sclContext.put("graph", graph);
+            return getLabels.apply(VariableOrResource.make(content));
+        } catch (Throwable t) {
+            LOGGER.error("Calculating checked state failed.", t);
+            throw new DatabaseException(t);
+        } finally {
+            sclContext.put("graph", oldGraph);
+        }
+
+    }
+
+}
index a04b9315f544d698913c655ce084e485ec05224a..1ea88caf4377bb7cb66b31e8b55b8eeafec32ac9 100644 (file)
@@ -41,7 +41,7 @@ public class SCLChildRule implements ChildRule {
         
         Variable ruleVariable = Variables.getVariable(graph, rule);
 
-        Function1<Resource,List<Resource>> getChildren = ruleVariable.getPossiblePropertyValue(graph, MOD.SCLChildRule_getChildren);
+        Function1<Object,List<Resource>> getChildren = ruleVariable.getPossiblePropertyValue(graph, MOD.SCLChildRule_getChildren);
         if(getChildren == null) return Collections.emptyList();
 
         SCLContext sclContext = SCLContext.getCurrent();