Force tab closure to be performed by EDT. 14/10714/2
Bruno JOFRET [Wed, 6 Mar 2013 13:18:44 +0000 (14:18 +0100)]
Change-Id: I118f2a28e743639e1c36af1a5d92608f704b335b

scilab/modules/gui/src/java/org/scilab/modules/gui/SwingView.java

index a7419f8..fdd9b37 100644 (file)
@@ -563,15 +563,41 @@ public final class SwingView implements GraphicView {
         if (requestedObject != null) {
             switch (requestedObject.getType()) {
             case Figure:
-                final SwingScilabTab tab = (SwingScilabTab) requestedObject.getValue();
-                tab.disablePaint();
-                DockingManager.close(tab);
-                DockingManager.unregisterDockable((Dockable) tab);
-                ClosingOperationsManager.unregisterClosingOperation(tab);
-                ClosingOperationsManager.removeDependency(tab);
-                ClosingOperationsManager.checkTabForClosing(tab);
-                tab.close();
-                break;
+                if (SwingUtilities.isEventDispatchThread()) {
+                    final SwingScilabTab tab = (SwingScilabTab) requestedObject.getValue();
+                    tab.disablePaint();
+                    DockingManager.close(tab);
+                    DockingManager.unregisterDockable((Dockable) tab);
+                    ClosingOperationsManager.unregisterClosingOperation(tab);
+                    ClosingOperationsManager.removeDependency(tab);
+                    ClosingOperationsManager.checkTabForClosing(tab);
+                    tab.close();
+                } else {
+                    try {
+                        SwingUtilities.invokeAndWait(new Runnable() {
+
+                            @Override
+                            public void run() {
+                                final SwingScilabTab tab = (SwingScilabTab) requestedObject.getValue();
+                                tab.disablePaint();
+                                DockingManager.close(tab);
+                                DockingManager.unregisterDockable((Dockable) tab);
+                                ClosingOperationsManager.unregisterClosingOperation(tab);
+                                ClosingOperationsManager.removeDependency(tab);
+                                ClosingOperationsManager.checkTabForClosing(tab);
+                                tab.close();
+                            }
+
+                        });
+                    } catch (InterruptedException e) {
+                        // TODO Auto-generated catch block
+                        e.printStackTrace();
+                    } catch (InvocationTargetException e) {
+                        // TODO Auto-generated catch block
+                        e.printStackTrace();
+                    }
+                }
+                    break;
             case Progressbar:
             case Waitbar:
                 SwingScilabWaitBar bar = (SwingScilabWaitBar) requestedObject.getValue();