]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/SCLProgressMonitor.java
Added syncActivateModel function for deterministic SCL script execution
[simantics/platform.git] / bundles / org.simantics.scl.osgi / src / org / simantics / scl / osgi / SCLProgressMonitor.java
1 package org.simantics.scl.osgi;
2
3 import org.eclipse.core.runtime.IProgressMonitor;
4 import org.simantics.scl.runtime.function.Function1;
5 import org.simantics.scl.runtime.function.Function2;
6 import org.simantics.scl.runtime.tuple.Tuple0;
7
8 public class SCLProgressMonitor implements IProgressMonitor {
9
10     private final Function2<String, Float, Tuple0> beginTask;
11     private final Function1<Tuple0, Tuple0> done;
12     private final Function1<Tuple0, Boolean> isCanceled;
13     private final Function1<Boolean, Tuple0> setCanceled;
14     private final Function1<String, Tuple0> setTaskName;
15     private final Function1<String, Tuple0> subTask;
16     private final Function1<Float, Tuple0> worked;
17
18     public SCLProgressMonitor(Function2<String, Float, Tuple0> beginTask, Function1<Tuple0, Tuple0> done,
19             Function1<Tuple0, Boolean> isCanceled, Function1<Boolean, Tuple0> setCanceled,
20             Function1<String, Tuple0> setTaskName, Function1<String, Tuple0> subTask, Function1<Float, Tuple0> worked) {
21         this.beginTask = beginTask;
22         this.done = done;
23         this.isCanceled = isCanceled;
24         this.setCanceled = setCanceled;
25         this.setTaskName = setTaskName;
26         this.subTask = subTask;
27         this.worked = worked;
28     }
29     
30     @Override
31     public void beginTask(String name, int totalWork) {
32         beginTask.apply(name, new Float(totalWork));
33     }
34
35     @Override
36     public void done() {
37         done.apply(Tuple0.INSTANCE);
38     }
39
40     @Override
41     public void internalWorked(double work) {
42     }
43
44     @Override
45     public boolean isCanceled() {
46         return isCanceled.apply(Tuple0.INSTANCE);
47     }
48
49     @Override
50     public void setCanceled(boolean value) {
51         setCanceled.apply(value);
52     }
53
54     @Override
55     public void setTaskName(String name) {
56         setTaskName.apply(name);
57     }
58
59     @Override
60     public void subTask(String name) {
61         subTask.apply(name);
62     }
63
64     @Override
65     public void worked(int work) {
66         worked.apply(new Float(work));
67     }
68
69 }