Salome HOME
Applet's fix. Now the alert shows before starting the SALOME.
authormka <mka@opencascade.com>
Fri, 20 Sep 2013 09:16:30 +0000 (09:16 +0000)
committermka <mka@opencascade.com>
Fri, 20 Sep 2013 09:16:30 +0000 (09:16 +0000)
Workspace/Siman/src/org/splat/launcher/ToolbarApplet.java

index 015da70b3ea3bafbb7fd778c600702a1e6fe5631..31600d9fe2102854526b666d9bfa0e9d5ff14911 100644 (file)
@@ -184,6 +184,56 @@ public class ToolbarApplet extends java.applet.Applet implements ActionListener
                        error.printStackTrace(); // RKV: NOPMD: Applet output
                }
        }
+       
+       /**
+        * The class that reads output of the process passed in constructor in a separate thread.
+        * (a quick fix to the problem that we need to read bash script
+        * output in order for it to proceed correctly).
+        */
+       class ScriptOutputReader implements Runnable {
+
+               /**
+                * A quick fix to the problem that we need to read bash script output in order for it to proceed correctly.
+                */
+               Process _proc;
+
+               /**
+                * Constructor from process to take output from.
+                * @param proc
+                *              the process to read from.
+                */
+               public ScriptOutputReader(final Process proc) {
+                       _proc = proc;
+               }
+
+               /** 
+                * {@inheritDoc}
+                * @see java.lang.Runnable#run()
+                */
+               @Override
+               public void run() {
+                       try {
+                               BufferedReader bri = new BufferedReader(new InputStreamReader(
+                                               _proc.getInputStream()));
+                               BufferedReader bre = new BufferedReader(new InputStreamReader(
+                                               _proc.getErrorStream()));
+                               String line = bri.readLine();
+                               while (line != null) {
+                                       System.out.println(line); // RKV: NOPMD: Applet output
+                                       line = bri.readLine();
+                               }
+                               bri.close();
+                               line = bre.readLine();
+                               while (line != null) {
+                                       System.err.println(line); // RKV: NOPMD: Applet output
+                                       line = bre.readLine();
+                               }
+                               bre.close();
+                       } catch(Exception e) {
+                               // NOPMD: empty catch block - nothing really to do here.
+                       }
+               }
+       }
 
        /**
         * Checkout a scenario and start Salome with it.
@@ -252,22 +302,10 @@ public class ToolbarApplet extends java.applet.Applet implements ActionListener
                                                cmd.toArray(new String[] {}), null,
                                                new File(SALOME_HOME));
                                
-                               BufferedReader bri = new BufferedReader(new InputStreamReader(
-                                               proc.getInputStream()));
-                               BufferedReader bre = new BufferedReader(new InputStreamReader(
-                                               proc.getErrorStream()));
-                               String line = bri.readLine();
-                               while (line != null) {
-                                       System.out.println(line); // RKV: NOPMD: Applet output
-                                       line = bri.readLine();
-                               }
-                               bri.close();
-                               line = bre.readLine();
-                               while (line != null) {
-                                       System.err.println(line); // RKV: NOPMD: Applet output
-                                       line = bre.readLine();
-                               }
-                               bre.close();
+                               // Read script's output in separate thread.
+                               ScriptOutputReader appletOutputReader = new ScriptOutputReader(proc);
+                               Thread thread = new Thread(appletOutputReader);
+                               thread.start();
                        } else {
                                // Checkout of the scenario is failed at the beginning.
                                if (response != null) {