]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
SCLProgressMonitor implements IProgressMonitor 33/833/1
authorjsimomaa <jani.simomaa@gmail.com>
Mon, 14 Aug 2017 03:55:32 +0000 (06:55 +0300)
committerjsimomaa <jani.simomaa@gmail.com>
Mon, 14 Aug 2017 03:55:32 +0000 (06:55 +0300)
refs #7426

Change-Id: I17975178e3627db2ba623edc22cf938e4df9c9b8

bundles/org.simantics.scl.osgi/scl/UI/Progress.scl
bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/SCLProgressMonitor.java [new file with mode: 0644]

index 6e8c0ed30c1f56826ad81db874360f78fcbb6ffd..05e870406f38219483aa09d022e3dd29e18db595 100644 (file)
@@ -11,3 +11,7 @@ importJava "org.eclipse.core.runtime.IProgressMonitor" where
 importJava "org.eclipse.core.runtime.NullProgressMonitor" where
     @JavaName "<init>"
     createNullProgressMonitor :: () -> <Proc> ProgressMonitor
+
+importJava "org.simantics.scl.osgi.SCLProgressMonitor" where
+    @JavaName "<init>"
+    sclProgressMonitor :: (String -> Float -> <Proc> ()) -> (() -> <Proc> ()) -> (() -> <Proc> Boolean) -> (Boolean -> <Proc> ()) -> (String -> <Proc> ()) -> (String -> <Proc> ()) -> (Float -> <Proc> ()) -> <Proc> ProgressMonitor
diff --git a/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/SCLProgressMonitor.java b/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/SCLProgressMonitor.java
new file mode 100644 (file)
index 0000000..4f115a8
--- /dev/null
@@ -0,0 +1,69 @@
+package org.simantics.scl.osgi;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.simantics.scl.runtime.function.Function1;
+import org.simantics.scl.runtime.function.Function2;
+import org.simantics.scl.runtime.tuple.Tuple0;
+
+public class SCLProgressMonitor implements IProgressMonitor {
+
+    private final Function2<String, Float, Tuple0> beginTask;
+    private final Function1<Tuple0, Tuple0> done;
+    private final Function1<Tuple0, Boolean> isCanceled;
+    private final Function1<Boolean, Tuple0> setCanceled;
+    private final Function1<String, Tuple0> setTaskName;
+    private final Function1<String, Tuple0> subTask;
+    private final Function1<Float, Tuple0> worked;
+
+    public SCLProgressMonitor(Function2<String, Float, Tuple0> beginTask, Function1<Tuple0, Tuple0> done,
+            Function1<Tuple0, Boolean> isCanceled, Function1<Boolean, Tuple0> setCanceled,
+            Function1<String, Tuple0> setTaskName, Function1<String, Tuple0> subTask, Function1<Float, Tuple0> worked) {
+        this.beginTask = beginTask;
+        this.done = done;
+        this.isCanceled = isCanceled;
+        this.setCanceled = setCanceled;
+        this.setTaskName = setTaskName;
+        this.subTask = subTask;
+        this.worked = worked;
+    }
+    
+    @Override
+    public void beginTask(String name, int totalWork) {
+        beginTask.apply(name, new Float(totalWork));
+    }
+
+    @Override
+    public void done() {
+        done.apply(Tuple0.INSTANCE);
+    }
+
+    @Override
+    public void internalWorked(double work) {
+    }
+
+    @Override
+    public boolean isCanceled() {
+        return isCanceled.apply(Tuple0.INSTANCE);
+    }
+
+    @Override
+    public void setCanceled(boolean value) {
+        setCanceled.apply(value);
+    }
+
+    @Override
+    public void setTaskName(String name) {
+        setTaskName.apply(name);
+    }
+
+    @Override
+    public void subTask(String name) {
+        subTask.apply(name);
+    }
+
+    @Override
+    public void worked(int work) {
+        worked.apply(new Float(work));
+    }
+
+}