Xcos tab restoration fixed 59/19059/2
Clément DAVID [Wed, 8 Feb 2017 15:14:48 +0000 (16:14 +0100)]
The newly created tab should be part of the opened diagrams before
being restored. On error a stacktrace is now printed.

Change-Id: I84734a6fbdc88c339c44c096fd0cb3562cd8afec

scilab/modules/xcos/src/java/org/scilab/modules/xcos/Xcos.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/XcosTab.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/configuration/ConfigurationManager.java

index c4f8c21..55b3540 100644 (file)
@@ -74,7 +74,8 @@ import com.mxgraph.model.mxICell;
 import com.mxgraph.util.mxEvent;
 import com.mxgraph.util.mxEventObject;
 import com.mxgraph.view.mxStylesheet;
-import java.util.stream.Collectors;
+import javax.swing.Timer;
+import org.scilab.modules.commons.ScilabCommons;
 import org.scilab.modules.xcos.graph.model.ScicosObjectOwner;
 import org.scilab.modules.xcos.graph.model.XcosGraphModel;
 
@@ -112,12 +113,18 @@ public final class Xcos {
     private static volatile Xcos sharedInstance;
 
     static {
-        Scilab.registerInitialHook(new Runnable() {
-            @Override
-            public void run() {
+        Scilab.registerInitialHook(() -> {
+            // wait the Scilab startup termination
+            final Timer t = new Timer(500, null);
+            t.addActionListener((e) -> {
+                if (ScilabCommons.getStartProcessing() == 1)
+                    return;
+                t.stop();
+
                 /* load scicos libraries (macros) */
                 InterpreterManagement.requestScilabExec(LOAD_XCOS_LIBS_LOAD_SCICOS);
-            }
+            });
+            t.start();
         });
 
         XConfiguration.addXConfigurationListener(new XcosConfiguration());
index 31c6bea..51c3072 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2010-2011 - DIGITEO - Clement DAVID
- * Copyright (C) 2011-2015 - Scilab Enterprises - Clement DAVID
+ * Copyright (C) 2011-2017 - Scilab Enterprises - Clement DAVID
  *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
index 0f64a8d..491a63c 100644 (file)
@@ -409,6 +409,8 @@ public final class ConfigurationManager {
             graph = new XcosDiagram(controller, controller.createObject(Kind.DIAGRAM), Kind.DIAGRAM, "");
             graph.installListeners();
 
+            Xcos.getInstance().addDiagram(new ScicosObjectOwner(graph.getUID(), Kind.DIAGRAM), graph);
+
             if (f != null) {
                 final String filename = f.getCanonicalPath();
                 final XcosFileType filetype = XcosFileType.findFileType(f);
@@ -416,12 +418,15 @@ public final class ConfigurationManager {
                 filetype.load(filename, graph);
                 graph.postLoad(f);
             }
-            Xcos.getInstance().addDiagram(new ScicosObjectOwner(graph.getUID(), Kind.DIAGRAM), graph);
+
 
             graph = loadPath(doc, graph);
 
             graph.setGraphTab(doc.getUuid());
         } catch (Exception e) {
+            // the only way to spot something on window restoration is to print the stacktrace
+            e.printStackTrace();
+
             Logger.getLogger(ConfigurationManager.class.getName()).log(Level.SEVERE, null, e);
             graph = null;
         }