Create new callback types for uninterruptible callbacks.
[scilab.git] / scilab / modules / gui / src / java / org / scilab / modules / gui / events / callback / ScilabCallBack.java
index 79f643d..0341e1b 100644 (file)
@@ -27,6 +27,8 @@ public abstract class ScilabCallBack extends CommonCallBack {
 
     private static final long serialVersionUID = -4923246233703990342L;
 
+    private boolean isInterruptible = true;
+
     /**
      * Constructor
      * @param command : the command to execute.
@@ -35,6 +37,10 @@ public abstract class ScilabCallBack extends CommonCallBack {
         super(command, CallBack.UNTYPED);
     }
 
+    private ScilabCallBack(String command, boolean isInterruptible) {
+        super(command, CallBack.UNTYPED);
+        this.isInterruptible = isInterruptible;
+    }
     /**
      * Callback Factory to easily create a callback
      * just like in scilab.
@@ -42,14 +48,28 @@ public abstract class ScilabCallBack extends CommonCallBack {
      * @return a usable Scilab callback
      */
     public static ScilabCallBack create(String command) {
-        return (new ScilabCallBack(command) {
+        return create(command, true);
+    }
+
+    /**
+     * Callback Factory to easily create a callback
+     * just like in scilab.
+     * @param command : the command to execute.
+     * @return a usable Scilab callback
+     */
+    public static ScilabCallBack create(String command, boolean isInterruptible) {
+        return (new ScilabCallBack(command, isInterruptible) {
 
             private static final long serialVersionUID = -7286803341046313407L;
 
             public void callBack() {
                 Thread launchMe = new Thread() {
                     public void run() {
-                        InterpreterManagement.putCommandInScilabQueue(getCommand());
+                        if (isInterruptible()) {
+                            InterpreterManagement.putCommandInScilabQueue(getCommand());
+                        } else {
+                            InterpreterManagement.requestScilabExec(getCommand());
+                        }
                     }
                 };
                 launchMe.start();
@@ -57,6 +77,10 @@ public abstract class ScilabCallBack extends CommonCallBack {
         });
     }
 
+    boolean isInterruptible() {
+        return isInterruptible;
+    }
+
     /**
      * Callback Factory to easily create a callback
      * just like in scilab.