]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/scl/SCL.java
Revert of SCL context using try-finally
[simantics/platform.git] / bundles / org.simantics.document.swt.core / src / org / simantics / document / swt / core / scl / SCL.java
index f8732aebcedffa44571b747c77247a36e143e5f8..ad5cf709169a75f392e0d12165b416949e3501bb 100644 (file)
-package org.simantics.document.swt.core.scl;\r
-\r
-import java.util.List;\r
-\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.db.layer0.variable.Variables;\r
-import org.simantics.document.server.handler.AbstractEventHandler;\r
-import org.simantics.document.server.handler.EventHandler;\r
-import org.simantics.document.server.handler.WriteEventHandler;\r
-import org.simantics.document.server.io.CommandContext;\r
-import org.simantics.document.server.io.CommandResult;\r
-import org.simantics.document.server.serverResponse.ServerResponse;\r
-import org.simantics.document.swt.core.SWTViews;\r
-import org.simantics.scl.runtime.SCLContext;\r
-import org.simantics.scl.runtime.function.Function1;\r
-import org.simantics.scl.runtime.reporting.SCLReportingHandler;\r
-import org.simantics.scl.runtime.tuple.Tuple0;\r
-import org.simantics.ui.selection.WorkbenchSelectionElement;\r
-import org.simantics.ui.selection.WorkbenchSelectionUtils;\r
-\r
-public class SCL {\r
-    \r
-    public static final String SCL_VALUE_PROPERTY = "sclValueProperty";\r
-    \r
-    public static EventHandler eventHandler(final Function1<Object, Object> fn) {\r
-       return new EventHandler() {\r
-                       \r
-                       @Override\r
-                       protected ServerResponse handle(ReadGraph graph, CommandContext parameters) throws DatabaseException {\r
-\r
-                           final SCLReportingHandler printer = (SCLReportingHandler)SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER); \r
-                               graph.async(new WriteRequest() {\r
-                                       \r
-                                       @Override\r
-                                       public void perform(WriteGraph graph) throws DatabaseException {\r
-                                           SCLContext sclContext = SCLContext.getCurrent();\r
-                                           Object oldPrinter = sclContext.put(SCLReportingHandler.REPORTING_HANDLER, printer);\r
-                                               Object oldGraph = sclContext.put("graph", graph);\r
-                                               fn.apply(Tuple0.INSTANCE);\r
-                                               sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);\r
-                                               sclContext.put("graph", oldGraph);\r
-                                       }\r
-                                       \r
-                               });\r
-                               \r
-                               return null;\r
-                               \r
-                       }\r
-                       \r
-               };\r
-    }\r
-    \r
-    public static String getURI(ReadGraph graph, Variable variable) throws DatabaseException {\r
-        return variable.getURI(graph);\r
-    }\r
-    \r
-    public static String propertyDisplayValue(ReadGraph graph, Variable variable, String property) throws DatabaseException {\r
-        Variable var = variable.getProperty(graph, property);\r
-        Variable var2 = var.getProperty(graph, Variables.DISPLAY_VALUE);\r
-        return var2.getValue(graph);\r
-    }\r
-    \r
-    public static AbstractEventHandler propertyValueSetter(ReadGraph graph, Variable variable, String property) throws DatabaseException {\r
-        String uri = variable.getURI(graph);\r
-        return new ValueSetter(uri, property);\r
-    }\r
-    \r
-    public static String propertyGetter(ReadGraph graph, Variable variable) throws DatabaseException {\r
-        String value = variable.getPossiblePropertyValue(graph, SCL_VALUE_PROPERTY);\r
-        return value;\r
-    }\r
-    \r
-    static class ValueSetter extends WriteEventHandler {\r
-        \r
-        private String varUri;\r
-        private String property;\r
-        \r
-        public ValueSetter(String varUri, String property) {\r
-            this.varUri = varUri;\r
-            this.property = property;\r
-        }\r
-        \r
-        @Override\r
-        protected CommandResult handle(WriteGraph graph, CommandContext parameters) throws DatabaseException {\r
-            Variable variable = Variables.getVariable(graph, varUri);\r
-            Variable var = variable.getPossibleProperty(graph, property);\r
-            Variable var2 = var.getPossibleProperty(graph, Variables.DISPLAY_VALUE);\r
-            var2.setValue(graph, parameters.getString("text"), Bindings.STRING);\r
-            return null;\r
-        }\r
-    };\r
-\r
-    @SuppressWarnings("unchecked")\r
-    public static List<WorkbenchSelectionElement> decodeWSES(String key) {\r
-        return (List<WorkbenchSelectionElement>)SWTViews.decode(key);\r
-    }\r
-    \r
-    public static Resource wseResource(ReadGraph graph, WorkbenchSelectionElement wse) throws DatabaseException {\r
-        return WorkbenchSelectionUtils.getPossibleResource(wse);\r
-    }\r
-\r
-}\r
+package org.simantics.document.swt.core.scl;
+
+import java.util.List;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.layer0.variable.Variables;
+import org.simantics.document.server.handler.AbstractEventHandler;
+import org.simantics.document.server.handler.EventHandler;
+import org.simantics.document.server.handler.WriteEventHandler;
+import org.simantics.document.server.io.CommandContext;
+import org.simantics.document.server.io.CommandResult;
+import org.simantics.document.server.serverResponse.ServerResponse;
+import org.simantics.document.swt.core.SWTViews;
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.function.Function1;
+import org.simantics.scl.runtime.reporting.SCLReportingHandler;
+import org.simantics.scl.runtime.tuple.Tuple0;
+import org.simantics.ui.selection.WorkbenchSelectionElement;
+import org.simantics.ui.selection.WorkbenchSelectionUtils;
+
+public class SCL {
+    
+    public static final String SCL_VALUE_PROPERTY = "sclValueProperty";
+    
+    public static EventHandler eventHandler(final Function1<Object, Object> fn) {
+       return new EventHandler() {
+                       
+                       @Override
+                       protected ServerResponse handle(ReadGraph graph, CommandContext parameters) throws DatabaseException {
+
+                           final SCLReportingHandler printer = (SCLReportingHandler)SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER); 
+                               graph.async(new WriteRequest() {
+                                       
+                                       @Override
+                                       public void perform(WriteGraph graph) throws DatabaseException {
+                                           SCLContext sclContext = SCLContext.getCurrent();
+                                           Object oldPrinter = sclContext.put(SCLReportingHandler.REPORTING_HANDLER, printer);
+                                               Object oldGraph = sclContext.put("graph", graph);
+                                               try {
+                                                       fn.apply(Tuple0.INSTANCE);
+                                               } finally {
+                                                       sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
+                                                       sclContext.put("graph", oldGraph);
+                                               }
+                                       }
+                                       
+                               });
+                               
+                               return null;
+                               
+                       }
+                       
+               };
+    }
+    
+    public static String getURI(ReadGraph graph, Variable variable) throws DatabaseException {
+        return variable.getURI(graph);
+    }
+    
+    public static String propertyDisplayValue(ReadGraph graph, Variable variable, String property) throws DatabaseException {
+        Variable var = variable.getProperty(graph, property);
+        Variable var2 = var.getProperty(graph, Variables.DISPLAY_VALUE);
+        return var2.getValue(graph);
+    }
+    
+    public static AbstractEventHandler propertyValueSetter(ReadGraph graph, Variable variable, String property) throws DatabaseException {
+        String uri = variable.getURI(graph);
+        return new ValueSetter(uri, property);
+    }
+    
+    public static String propertyGetter(ReadGraph graph, Variable variable) throws DatabaseException {
+        String value = variable.getPossiblePropertyValue(graph, SCL_VALUE_PROPERTY);
+        return value;
+    }
+    
+    static class ValueSetter extends WriteEventHandler {
+        
+        private String varUri;
+        private String property;
+        
+        public ValueSetter(String varUri, String property) {
+            this.varUri = varUri;
+            this.property = property;
+        }
+        
+        @Override
+        protected CommandResult handle(WriteGraph graph, CommandContext parameters) throws DatabaseException {
+            Variable variable = Variables.getVariable(graph, varUri);
+            Variable var = variable.getPossibleProperty(graph, property);
+            Variable var2 = var.getPossibleProperty(graph, Variables.DISPLAY_VALUE);
+            var2.setValue(graph, parameters.getString("text"), Bindings.STRING);
+            return null;
+        }
+    };
+
+    @SuppressWarnings("unchecked")
+    public static List<WorkbenchSelectionElement> decodeWSES(String key) {
+        return (List<WorkbenchSelectionElement>)SWTViews.decode(key);
+    }
+    
+    public static Resource wseResource(ReadGraph graph, WorkbenchSelectionElement wse) throws DatabaseException {
+        return WorkbenchSelectionUtils.getPossibleResource(wse);
+    }
+
+}