]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
ValueType modifications to satisfy compilation of SCL-expressions 66/1166/2
authorjsimomaa <jani.simomaa@gmail.com>
Tue, 31 Oct 2017 05:44:32 +0000 (07:44 +0200)
committerJani Simomaa <jani.simomaa@semantum.fi>
Tue, 31 Oct 2017 05:44:41 +0000 (07:44 +0200)
Also adding a validator for plain ServerSCLValueRequest (DOC.SCLValue)

refs #7575

Change-Id: Ib34fbd9c53ec2003680b9546e7344506100a01b0

bundles/org.simantics.document.base.ontology/graph/Components.pgraph
bundles/org.simantics.document.base.ontology/graph/Properties.pgraph
bundles/org.simantics.document.server/scl/Document/All.scl
bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java
bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java

index 5fa11e906f7433e02c585926695e3e1a710dd15a..8c03f41c5e9935fd4d47c485460040e102ffd999 100644 (file)
@@ -21,13 +21,13 @@ connectionPoint = COMPONENTS.connectionPoint : L0.Template
             >-- %relation    
 
 sclAttribute = COMPONENTS.sclAttribute : L0.Template
-    @template %subject %relation %command
+    @template %subject %relation %command %valueType
         %subject
             >-- %relation
             L0.Asserts _ : L0.Assertion
                 L0.HasPredicate %relation
                 L0.HasObject _ : DOC.SCLValue
-                  L0.HasValueType "String"
+                  L0.HasValueType %valueType
                   L0.SCLValue.expression %command
                   L0.default false
 
@@ -49,6 +49,7 @@ DOC.sclValue : L0.Template
             L0.HasValueType %valueType
 
 DOC.SCLValue <T L0.SCLValue
+  @L0.scl L0.SCLValueType.validator """\self -> compileDocumentSCLValueExpression self""" "Variable -> <ReadGraph> String"
   @L0.assert L0.ConvertsToValueWith
     DOC.Functions.sclValue : L0.ExternalValue
 
@@ -59,13 +60,12 @@ COMPONENTS.Component <T STR.Component
     @attribute PROPERTIES.session FUNCTIONS.session
     @attribute PROPERTIES.state FUNCTIONS.state
     @attribute PROPERTIES.icstate FUNCTIONS.icstate
-    @sclAttribute PROPERTIES.commands "commandList self"
+    @sclAttribute PROPERTIES.commands "commandList self" "[Command]"
 
 COMPONENTS.PrimitiveComponent <T COMPONENTS.Component
     @L0.assert PROPERTIES.primitiveProperties
       _ : L0.Value
         L0.domainProperties FUNCTIONS.primitiveProperties
-        
 
 COMPONENTS.ParentlessComponent <T COMPONENTS.PrimitiveComponent /* Component without a parent, e.g. Root, DialogBox */
 
@@ -84,8 +84,8 @@ COMPONENTS.Event <T COMPONENTS.ParentlessComponent
  
 COMPONENTS.CommandEvent <T COMPONENTS.Event
    @connectionPoint RELATIONS.data1
-   @sclAttribute PROPERTIES.dataDefinitions "dataDefinitions self"   
-   @sclAttribute PROPERTIES.SCLFunction "emptyOnClick ()"
+   @sclAttribute PROPERTIES.dataDefinitions "dataDefinitions self" "[DataDefinition]"
+   @sclAttribute PROPERTIES.SCLFunction "emptyOnClick ()" "String"
 
 DOC.commandEvent : L0.Template
     @template %instance %expression %valueType
index 4fb8b227860e33753fc2c3defaf5bb59ead5518b..d0394de6693251707724921758b93ec8df5f7cab 100644 (file)
@@ -63,13 +63,13 @@ PROPERTIES.pathExists
     L0.RequiresValueType "Boolean" 
 
 PROPERTIES.commands
-    @defAttribute L0.String    
-    L0.RequiresValueType "String" 
+    @defAttribute L0.Value
+    L0.RequiresValueType "[Command]"
     L0.HasLabel "Commands"
     
 PROPERTIES.dataDefinitions
-    @defAttribute L0.String    
-    L0.RequiresValueType "String" 
+    @defAttribute L0.Value
+    L0.RequiresValueType "[DataDefinition]"
     L0.HasLabel "Data Definitions"
 
 PROPERTIES.SCLFunction : PROPERTIES.ParameterType
index 7781cfdb3ffaa9595eb322be7d01ffc286bf48c0..641f4fdc158f1e6e5546f1d6f6dbd601da3b6538 100644 (file)
@@ -137,6 +137,8 @@ importJava "org.simantics.document.server.Functions" where
     
     stateVariable :: Variable -> <ReadGraph> Variable
     
+    compileDocumentSCLValueExpression :: Variable -> <ReadGraph> String
+    
 propertyValueCached :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> a
 propertyValueCached var prop = propertyValueCached_ var prop binding
     
index 13444fdba944701e2454fea1174283d89045f8ca..a6e9d6ab6818eba35ff09cd6ea5d0549bde1f0aa 100644 (file)
@@ -38,6 +38,7 @@ import org.simantics.db.layer0.request.PropertyInfoRequest;
 import org.simantics.db.layer0.request.VariableProperty;
 import org.simantics.db.layer0.request.VariableRead;
 import org.simantics.db.layer0.request.VariableValueWithBinding;
+import org.simantics.db.layer0.scl.SCLDatabaseException;
 import org.simantics.db.layer0.variable.ConstantPropertyVariable;
 import org.simantics.db.layer0.variable.ProxyChildVariable;
 import org.simantics.db.layer0.variable.ProxySessionRequest;
@@ -74,6 +75,7 @@ import org.simantics.modeling.services.CaseInsensitiveComponentFunctionNamingStr
 import org.simantics.modeling.services.ComponentNamingStrategy;
 import org.simantics.operation.Layer0X;
 import org.simantics.project.IProject;
+import org.simantics.scl.compiler.module.repository.ImportFailureException;
 import org.simantics.scl.compiler.types.TCon;
 import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.Types;
@@ -96,11 +98,14 @@ import org.simantics.simulation.project.IExperimentManager;
 import org.simantics.structural2.variables.Connection;
 import org.simantics.structural2.variables.StandardProceduralChildVariable;
 import org.simantics.structural2.variables.VariableConnectionPointDescriptor;
+import org.slf4j.LoggerFactory;
 
 import gnu.trove.map.hash.THashMap;
 
 public class Functions {
 
+    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(Functions.class);
+    
     private static class PrimitivePropertyStatementsProcedure implements AsyncProcedure<DirectStatements> {
 
         public DirectStatements result;
@@ -1305,4 +1310,27 @@ public class Functions {
        return graph.syncRequest(new PathExistsRequest(context));
     }
 
+    public static String compileDocumentSCLValueExpression(ReadGraph graph, Variable context) {
+        try {
+            ServerSCLValueRequest.compile(graph, context);
+            return "";
+        } catch (Exception e) {
+            return resolveIssueMessage(e);
+        }
+    }
+    
+    private static String resolveIssueMessage(Exception e) {
+        if (e instanceof ImportFailureException)
+            return "";
+        if (e.getCause() != null && e.getCause() instanceof ImportFailureException)
+            return "";
+        if (e instanceof SCLDatabaseException) {
+            SCLDatabaseException ee = (SCLDatabaseException) e;
+            return ee.getMessage();
+        }
+        if (LOGGER.isDebugEnabled())
+            LOGGER.debug("", e);
+        return e.getMessage();
+    }
+
 }
\ No newline at end of file
index e6cdf6ff5b43712b098594d172a91b7595de63cb..68602de69022bc6eeaf4f24375c1ff3c01bcf763 100644 (file)
@@ -91,8 +91,7 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest<
                SCLContext sclContext = SCLContext.getCurrent();
         Object oldGraph = sclContext.get("graph");
                try {
-                       Function1<Variable,Object> exp = graph.syncRequest(new ServerSCLValueRequest(graph, context),
-                                       TransientCacheListener.<Function1<Variable,Object>>instance());
+                       Function1<Variable,Object> exp = compile(graph, context);
                        sclContext.put("graph", graph);
                        return exp.apply(context);
                } catch (DatabaseException e) {
@@ -103,6 +102,10 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest<
             sclContext.put("graph", oldGraph);
                }
        }
+       
+       public static Function1<Variable, Object> compile(ReadGraph graph, Variable context) throws DatabaseException {
+           return graph.syncRequest(new ServerSCLValueRequest(graph, context), TransientCacheListener.<Function1<Variable,Object>>instance());
+       }
 
        @Override
        protected String getExpressionText(ReadGraph graph)