changeset 6558:c037c7fb6786

RT-36238 [Ensemble8] SwingInterop throws IllegalStateException: Not on FX application thread
author Martin Sladecek <martin.sladecek@oracle.com>
date Tue, 25 Mar 2014 11:05:07 +0100
parents baf51881af79
children a4f4d7834a8f
files apps/samples/Ensemble8/src/samples/java/ensemble/samples/language/swing/ProcessListener.java apps/samples/Ensemble8/src/samples/java/ensemble/samples/language/swing/SwingInteropApp.java apps/samples/Ensemble8/src/samples/java/ensemble/samples/language/swing/SwingInteropService.java apps/samples/Ensemble8/src/samples/java/ensemble/samples/language/swing/SwingInteropTask.java
diffstat 4 files changed, 29 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/apps/samples/Ensemble8/src/samples/java/ensemble/samples/language/swing/ProcessListener.java	Tue Mar 25 10:14:26 2014 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2008, 2013 Oracle and/or its affiliates.
- * All rights reserved. Use is subject to license terms.
- *
- * This file is available and licensed under the following license:
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *  - Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  - Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the distribution.
- *  - Neither the name of Oracle Corporation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package ensemble.samples.language.swing;
-
-public interface ProcessListener {
-    public void setProcess(Process proc);
-}
--- a/apps/samples/Ensemble8/src/samples/java/ensemble/samples/language/swing/SwingInteropApp.java	Tue Mar 25 10:14:26 2014 +0100
+++ b/apps/samples/Ensemble8/src/samples/java/ensemble/samples/language/swing/SwingInteropApp.java	Tue Mar 25 11:05:07 2014 +0100
@@ -73,10 +73,6 @@
 
     @Override
     public void stop() {
-        Process proc = service.procObj.getValue();
-        if (proc != null) {
-            proc.destroy();
-        }
         if (service.isRunning()) {
             service.cancel();
         }
--- a/apps/samples/Ensemble8/src/samples/java/ensemble/samples/language/swing/SwingInteropService.java	Tue Mar 25 10:14:26 2014 +0100
+++ b/apps/samples/Ensemble8/src/samples/java/ensemble/samples/language/swing/SwingInteropService.java	Tue Mar 25 11:05:07 2014 +0100
@@ -36,23 +36,32 @@
 import javafx.concurrent.Service;
 import javafx.concurrent.Task;
 
-public class SwingInteropService extends Service<Process> implements ProcessListener {
+public class SwingInteropService extends Service<Process> {
 
-    public SimpleObjectProperty<Process> procObj = new SimpleObjectProperty<>();
-    public SimpleBooleanProperty bp = new SimpleBooleanProperty(false);
+    SimpleBooleanProperty bp = new SimpleBooleanProperty(false);
 
     @Override
     protected Task createTask() {
-        return new SwingInteropTask(this);
+        return new SwingInteropTask();
     }
 
     @Override
-    public void setProcess(Process proc) {
-        procObj.setValue(proc);
-        if (proc == null) {
-            bp.set(false);
-        } else {
-            bp.set(true);
-        }
+    protected void scheduled() {
+        bp.set(true);
+    }
+
+    @Override
+    protected void cancelled() {
+        bp.set(false);
+    }
+
+    @Override
+    protected void succeeded() {
+        bp.set(false);
+    }
+
+    @Override
+    protected void failed() {
+        bp.set(false);
     }
 }
\ No newline at end of file
--- a/apps/samples/Ensemble8/src/samples/java/ensemble/samples/language/swing/SwingInteropTask.java	Tue Mar 25 10:14:26 2014 +0100
+++ b/apps/samples/Ensemble8/src/samples/java/ensemble/samples/language/swing/SwingInteropTask.java	Tue Mar 25 11:05:07 2014 +0100
@@ -38,11 +38,9 @@
 
 public class SwingInteropTask extends Task<Process> {
 
-    Process proc = null;
-    ProcessListener pListener;
+    private Process proc = null;
 
-    public SwingInteropTask(ProcessListener pListener) {
-        this.pListener = pListener;
+    public SwingInteropTask() {
     }
 
     @Override
@@ -60,14 +58,16 @@
         ProcessBuilder pb = new ProcessBuilder(command);
         proc = pb.start();
         //Assuming there is little output to stdout, stderr
-        pListener.setProcess(proc);
-        int exitVal = proc.waitFor();
-        pListener.setProcess(null);
+        proc.waitFor();
 
         return proc;
     }
 
-    public Process getSwingInteropProc() {
-        return proc;
+    @Override
+    protected void cancelled() {
+        if (proc != null) {
+            proc.destroy();
+        }
     }
+
 }
\ No newline at end of file