]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/ThreadingModificationProxy.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / synchronization / ThreadingModificationProxy.java
diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/ThreadingModificationProxy.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/ThreadingModificationProxy.java
new file mode 100644 (file)
index 0000000..e047181
--- /dev/null
@@ -0,0 +1,73 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.diagram.synchronization;\r
+\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.utils.threads.IThreadWorkQueue;\r
+import org.simantics.utils.threads.ThreadUtils;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class ThreadingModificationProxy extends ModificationAdapter {\r
+    private final IModification    m;\r
+    private final IThreadWorkQueue completionThread;\r
+    private final boolean          syncCompletion;\r
+\r
+    public ThreadingModificationProxy(IModification m, IThreadWorkQueue completionThread, boolean syncCompletion) {\r
+        super(m.getPriority());\r
+        this.m = m;\r
+        this.completionThread = completionThread;\r
+        this.syncCompletion = syncCompletion;\r
+    }\r
+    @Override\r
+    public void completed() {\r
+        if (completionThread != null) {\r
+            Runnable r = new Runnable() {\r
+                @Override\r
+                public void run() {\r
+                    m.completed();\r
+                }\r
+            };\r
+            if (syncCompletion)\r
+                ThreadUtils.syncExec(completionThread, r);\r
+            else\r
+                ThreadUtils.asyncExec(completionThread, r);\r
+        } else {\r
+            m.completed();\r
+        }\r
+    }\r
+    @Override\r
+    public boolean isComplete() {\r
+        return m.isComplete();\r
+    }\r
+    @Override\r
+    public void markComplete() {\r
+        m.markComplete();\r
+    }\r
+    @Override\r
+    public void perform(WriteGraph g) throws Exception {\r
+        m.perform(g);\r
+    }\r
+    @Override\r
+    public Throwable getException() {\r
+        return m.getException();\r
+    }\r
+    @Override\r
+    public void setException(Throwable t) {\r
+        m.setException(t);\r
+    }\r
+    @Override\r
+    public String toString() {\r
+        return getClass().getSimpleName() + "[" + m + "]";\r
+    }\r
+}
\ No newline at end of file