EditVar: start editvar in EDT 05/10305/2
Calixte DENIZET [Fri, 25 Jan 2013 13:38:13 +0000 (14:38 +0100)]
Change-Id: I2fc39d397839fe660b540ffeca2155808bd99812

scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/variableeditor/ScilabVariableEditor.java

index b735c83..2c9fe6a 100644 (file)
@@ -121,30 +121,38 @@ public final class ScilabVariableEditor extends SwingScilabWindow implements Var
      */
     public static ScilabVariableEditor getVariableEditor(final String type, final Object[][] data, final String variableName) {
         if (instance == null) {
-            instance = new ScilabVariableEditor(type, data, variableName);
-            instance.setVisible(true);
+            try {
+                SwingUtilities.invokeAndWait(new Runnable() {
+                        public void run() {
+                            instance = new ScilabVariableEditor(type, data, variableName);
+                            instance.setVisible(true);
+                        }
+                    });
+            } catch (Exception e) {
+                System.err.println(e);
+            }
         } else {
-            SwingScilabWindow window = (SwingScilabWindow) SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, editorTab);
-            window.setVisible(true);
-            window.toFront();
-            final JTable table = editorTab.getCurrentTable();
             SwingUtilities.invokeLater(new Runnable() {
-                public void run() {
-                    int r = -1;
-                    int c = -1;
-
-                    if (table != null) {
-                        r = table.getSelectedRow();
-                        c = table.getSelectedColumn();
-                    }
-                    boolean b = map.containsKey(variableName);
-                    instance.updateData(variableName, type, data);
-                    if (b && r != -1 && c != -1) {
-                        table.setRowSelectionInterval(r, r);
-                        table.setColumnSelectionInterval(c, c);
+                    public void run() {
+                        SwingScilabWindow window = (SwingScilabWindow) SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, editorTab);
+                        window.setVisible(true);
+                        window.toFront();
+                        final JTable table = editorTab.getCurrentTable();
+                        int r = -1;
+                        int c = -1;
+
+                        if (table != null) {
+                            r = table.getSelectedRow();
+                            c = table.getSelectedColumn();
+                        }
+                        boolean b = map.containsKey(variableName);
+                        instance.updateData(variableName, type, data);
+                        if (b && r != -1 && c != -1) {
+                            table.setRowSelectionInterval(r, r);
+                            table.setColumnSelectionInterval(c, c);
+                        }
                     }
-                }
-            });
+                });
         }
 
         editorTab.setName(Messages.gettext("Variable Editor") + " - " + variableName + "  (" + type + ")");