]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java
Still working for multiple readers
[simantics/platform.git] / bundles / org.simantics.document.server / src / org / simantics / document / server / Functions.java
index a6e9d6ab6818eba35ff09cd6ea5d0549bde1f0aa..ebaa5fc0a30d5151cbdb206f560b9aaae617d0be 100644 (file)
@@ -25,7 +25,7 @@ import org.simantics.db.Statement;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.common.primitiverequest.Adapter;
 import org.simantics.db.common.procedure.adapter.TransientCacheListener;
-import org.simantics.db.common.request.UnaryRead;
+import org.simantics.db.common.request.BinaryRead;
 import org.simantics.db.common.request.UniqueRead;
 import org.simantics.db.common.request.WriteResultRequest;
 import org.simantics.db.common.utils.Logger;
@@ -583,6 +583,7 @@ public class Functions {
        }
     }
 
+    @Deprecated
     public static AbstractEventHandler emptyOnClick(ReadGraph graph) throws DatabaseException {
         return new EventHandler() {
             @Override
@@ -592,6 +593,7 @@ public class Functions {
         };
     }
 
+    @Deprecated
     public static AbstractEventHandler writeEventHandler(ReadGraph graph, final Variable variable, final Function fn) {
 
        final Session session = graph.getSession();
@@ -624,15 +626,11 @@ public class Functions {
                                                        return (String)response;
                                                    }
                                                    return null;
-                                               } catch (Throwable t) {
-                                                   t.printStackTrace();
                                                } finally {
                                                        sclContext.put("graph", oldGraph);
                                                        sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
                                                }
 
-                                               return null;
-
                                            }
 
                                        });
@@ -649,6 +647,7 @@ public class Functions {
         };
     }
 
+    @Deprecated
     public static AbstractEventHandler readEventHandler(ReadGraph graph, final Variable variable, final Function fn) {
 
        final Session session = graph.getSession();
@@ -681,15 +680,11 @@ public class Functions {
                                                        return (String)response;
                                                    }
                                                    return null;
-                                               } catch (Throwable t) {
-                                                   t.printStackTrace();
                                                } finally {
                                                        sclContext.put("graph", oldGraph);
                                                        sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
                                                }
 
-                                               return null;
-
                                            }
 
                                        });
@@ -706,6 +701,7 @@ public class Functions {
         };
     }
 
+    @Deprecated
     public static AbstractEventHandler readEventHandler2(ReadGraph graph, final Function fn) {
 
        final Session session = graph.getSession();
@@ -732,15 +728,11 @@ public class Functions {
                                                        return (CommandResult)response;
                                                    }
                                                    return null;
-                                               } catch (Throwable t) {
-                                                   t.printStackTrace();
                                                } finally {
                                                        sclContext.put("graph", oldGraph);
                                                        sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
                                                }
 
-                                               return null;
-
                                            }
 
                                        });
@@ -764,12 +756,12 @@ public class Functions {
 
         final List<TCon> effects = ServerSCLHandlerValueRequest.getEffects(graph, anyFunction);
 
-       final Function1<CommandContext, CommandResult> fn = anyFunction.getValue(graph);
-        String expression = anyFunction.getPropertyValue(graph, "expression");
+       Function1<CommandContext, CommandResult> fn = anyFunction.getValue(graph);
+        //String expression = anyFunction.getPropertyValue(graph, "expression");
 
        final Session session = graph.getSession();
 
-        return new AbstractResponseHandler(expression) {
+        return new AbstractResponseHandler(fn) {
 
                private String formatError(RequestProcessor proc, Throwable t) {
 
@@ -830,10 +822,7 @@ public class Functions {
                                                Object oldGraph = sclContext.put("graph", graph);
                                                Object oldPrinter = sclContext.put(SCLReportingHandler.REPORTING_HANDLER, printer);
                                                try {
-                                                       Object response = fn.apply(parameters);
-                                                       return response;
-                                               } catch (Throwable t) {
-                                                       return new org.simantics.document.server.serverResponse.Error(formatError(graph, t));
+                                                       return fn.apply(parameters);
                                                } finally {
                                                        sclContext.put("graph", oldGraph);
                                                        sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
@@ -854,10 +843,7 @@ public class Functions {
                                                Object oldPrinter = sclContext.put(SCLReportingHandler.REPORTING_HANDLER, printer);
 
                                                try {
-                                                       Object response = fn.apply(parameters);
-                                                       return response;
-                                               } catch (Throwable t) {
-                                                       return new org.simantics.document.server.serverResponse.Error(formatError(graph, t));
+                                                       return fn.apply(parameters);
                                                } finally {
                                                        sclContext.put("graph", oldGraph);
                                                        sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
@@ -899,6 +885,7 @@ public class Functions {
         };
     }
 
+    @Deprecated
     public static AbstractEventHandler writeEventHandler2(ReadGraph graph, final Function fn) {
 
        final Session session = graph.getSession();
@@ -925,15 +912,11 @@ public class Functions {
                                                        return (CommandResult)response;
                                                    }
                                                    return null;
-                                               } catch (Throwable t) {
-                                                   t.printStackTrace();
                                                } finally {
                                                        sclContext.put("graph", oldGraph);
                                                        sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
                                                }
 
-                                               return null;
-
                                            }
 
                                        });
@@ -950,6 +933,8 @@ public class Functions {
         };
     }
 
+
+    @Deprecated
     public static AbstractEventHandler eventHandler2(ReadGraph graph, final Function fn) {
 
         return new AbstractEventHandler() {
@@ -969,14 +954,10 @@ public class Functions {
                                        return (CommandResult)response;
                                }
                                return null;
-                       } catch (Throwable t) {
-                               t.printStackTrace();
                        } finally {
                                sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
                        }
 
-                       return null;
-
                                } catch (Throwable e) {
                                        Logger.defaultLogError(e);
                                        return new org.simantics.document.server.serverResponse.Error(e.getMessage()); 
@@ -987,6 +968,7 @@ public class Functions {
         };
     }
 
+    @Deprecated
     public static AbstractEventHandler eventHandler(ReadGraph graph, final Function fn) {
 
         return new AbstractEventHandler() {
@@ -1013,8 +995,6 @@ public class Functions {
                                    if(response instanceof String) {
                                        result = (String)response;
                                    }
-                               } catch (Throwable t) {
-                                   t.printStackTrace();
                                } finally {
                                        sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
                                }
@@ -1276,11 +1256,11 @@ public class Functions {
                                                return true;
                                        }
                                } else {
-                                       Variable parentCp = graph.sync(new UnaryRead<Connection, Variable>(conn) {
+                                       Variable parentCp = graph.sync(new BinaryRead<Variable, Connection, Variable>(widget, conn) {
                                    @Override
                                    public Variable perform(ReadGraph graph) throws DatabaseException {
                                        DocumentationResource DOC = DocumentationResource.getInstance(graph);
-                                       Collection<VariableConnectionPointDescriptor> descs = parameter.getConnectionPointDescriptors(graph, null);
+                                       Collection<VariableConnectionPointDescriptor> descs = parameter2.getConnectionPointDescriptors(graph, parameter, null);
 
                                                for(VariableConnectionPointDescriptor desc : descs) {
                                                        if (DOC.Relations_partN.equals(desc.getConnectionPointResource(graph))) {
@@ -1312,7 +1292,7 @@ public class Functions {
 
     public static String compileDocumentSCLValueExpression(ReadGraph graph, Variable context) {
         try {
-            ServerSCLValueRequest.compile(graph, context);
+            ServerSCLValueRequest.validate(graph, context);
             return "";
         } catch (Exception e) {
             return resolveIssueMessage(e);
@@ -1332,5 +1312,33 @@ public class Functions {
             LOGGER.debug("", e);
         return e.getMessage();
     }
+    
+    static class StandardDocumentProperties implements DocumentProperties {
+
+               @Override
+               public Collection<String> getKeys(ReadGraph graph, Variable context) throws DatabaseException {
+                       
+               DocumentationResource DOC = DocumentationResource.getInstance(graph);
+                       StandardGraphPropertyVariable asd = new StandardGraphPropertyVariable(graph, context, DOC.Properties_primitiveProperties);
+                       Map<String, Variable> ps = primitiveProperties.getVariables(graph, asd, null);
+                       return ps.keySet();
+                       
+               }
+
+               @Override
+               public Object getValue(ReadGraph graph, Variable context, String key) throws DatabaseException {
+                       
+               DocumentationResource DOC = DocumentationResource.getInstance(graph);
+                       StandardGraphPropertyVariable asd = new StandardGraphPropertyVariable(graph, context, DOC.Properties_primitiveProperties);
+                       Map<String, Variable> ps = primitiveProperties.getVariables(graph, asd, null);
+                       return ps.get(key).getValue(graph);
+                       
+               }
+       
+    }
+    
+    public static DocumentProperties primitiveProperties() throws DatabaseException {
+       return new StandardDocumentProperties();
+    }
 
 }
\ No newline at end of file