Bug 11133 fixed: Avoid exception at desktop restoration when a window has no children 98/7198/1
Calixte DENIZET [Mon, 21 May 2012 09:38:24 +0000 (11:38 +0200)]
Change-Id: I35b7833d8aa86802e58c755ac15fb4850e16a268

scilab/modules/gui/src/java/org/scilab/modules/gui/tabfactory/ScilabTabFactory.java
scilab/modules/gui/src/java/org/scilab/modules/gui/utils/ClosingOperationsManager.java
scilab/modules/gui/src/java/org/scilab/modules/gui/utils/WindowsConfigurationManager.java

index 499ef78..9104e79 100644 (file)
@@ -184,7 +184,9 @@ public class ScilabTabFactory extends DockableFactory.Stub {
     }
 
     public void addToCache(SwingScilabTab tab) {
-        cache.put(tab.getPersistentId(), tab);
+        if (tab != null) {
+            cache.put(tab.getPersistentId(), tab);
+        }
     }
 
     /**
index aa79e34..377b86a 100644 (file)
@@ -63,8 +63,10 @@ public class ClosingOperationsManager {
      *            the closing operation
      */
     public static void registerClosingOperation(SwingScilabTab tab,
-            ClosingOperation op) {
-        closingOps.put(tab, op);
+                                                ClosingOperation op) {
+        if (tab != null) {
+            closingOps.put(tab, op);
+        }
     }
 
     /**
@@ -76,7 +78,9 @@ public class ClosingOperationsManager {
      *            the closing operation
      */
     public static void registerClosingOperation(Tab tab, ClosingOperation op) {
-        registerClosingOperation((SwingScilabTab) tab.getAsSimpleTab(), op);
+        if (tab != null) {
+            registerClosingOperation((SwingScilabTab) tab.getAsSimpleTab(), op);
+        }
     }
 
     /**
@@ -280,12 +284,14 @@ public class ClosingOperationsManager {
      *            the child tab
      */
     public static void addDependency(SwingScilabTab parent, SwingScilabTab child) {
-        List<SwingScilabTab> children = deps.get(parent);
-        if (children == null) {
-            children = new ArrayList<SwingScilabTab>();
-            deps.put(parent, children);
+        if (parent != null && child != null) {
+            List<SwingScilabTab> children = deps.get(parent);
+            if (children == null) {
+                children = new ArrayList<SwingScilabTab>();
+                deps.put(parent, children);
+            }
+            children.add(child);
         }
-        children.add(child);
     }
 
     /**
@@ -297,7 +303,9 @@ public class ClosingOperationsManager {
      *            the child tab
      */
     public static void addDependency(Tab parent, Tab child) {
-        addDependency((SwingScilabTab) parent.getAsSimpleTab(), (SwingScilabTab) child.getAsSimpleTab());
+        if (parent != null && child != null) {
+            addDependency((SwingScilabTab) parent.getAsSimpleTab(), (SwingScilabTab) child.getAsSimpleTab());
+        }
     }
 
     /**
@@ -309,7 +317,9 @@ public class ClosingOperationsManager {
      *            the child tab
      */
     public static void addDependency(SwingScilabTab parent, Tab child) {
-        addDependency(parent, (SwingScilabTab) child.getAsSimpleTab());
+        if (parent != null && child != null) {
+            addDependency(parent, (SwingScilabTab) child.getAsSimpleTab());
+        }
     }
 
     /**
@@ -321,7 +331,9 @@ public class ClosingOperationsManager {
      *            the child tab
      */
     public static void addDependency(Tab parent, SwingScilabTab child) {
-        addDependency((SwingScilabTab) parent.getAsSimpleTab(), child);
+        if (parent != null && child != null) {
+            addDependency((SwingScilabTab) parent.getAsSimpleTab(), child);
+        }
     }
 
     /**
@@ -331,7 +343,9 @@ public class ClosingOperationsManager {
      *            the child tab
      */
     public static void addDependencyWithRoot(SwingScilabTab child) {
-        addDependency(root, child);
+        if (child != null) {
+            addDependency(root, child);
+        }
     }
 
     /**
@@ -341,7 +355,9 @@ public class ClosingOperationsManager {
      *            the child tab
      */
     public static void addDependencyWithRoot(Tab child) {
-        addDependency(root, (SwingScilabTab) child.getAsSimpleTab());
+        if (child != null) {
+            addDependency(root, (SwingScilabTab) child.getAsSimpleTab());
+        }
     }
 
     /**
@@ -638,10 +654,10 @@ public class ClosingOperationsManager {
             }
         }
         switch (apps.size()) {
-            case 0:
-                return null;
-            case 1:
-                return String.format(EXIT_CONFIRM, apps.get(0));
+        case 0:
+            return null;
+        case 1:
+            return String.format(EXIT_CONFIRM, apps.get(0));
         }
 
         String str = apps.remove(0);
@@ -662,7 +678,7 @@ public class ClosingOperationsManager {
      *            the list
      */
     private static final void collectTabsToClose(SwingScilabTab tab,
-            List<SwingScilabTab> list) {
+                                                 List<SwingScilabTab> list) {
         List<SwingScilabTab> children = deps.get(tab);
         if (children != null) {
             for (SwingScilabTab t : children) {
index 60664ac..40ffba9 100644 (file)
@@ -180,11 +180,11 @@ public class WindowsConfigurationManager {
 
         Element root = doc.getDocumentElement();
         Element win = createNode(root, "Window", new Object[] {"uuid", window.getUUID(),
-                                 "x", (int) window.getLocation().getX(),
-                                 "y", (int) window.getLocation().getY(),
-                                 "width", (int) window.getSize().getWidth(),
-                                 "height", (int) window.getSize().getHeight()
-                                                              });
+                                                               "x", (int) window.getLocation().getX(),
+                                                               "y", (int) window.getLocation().getY(),
+                                                               "width", (int) window.getSize().getWidth(),
+                                                               "height", (int) window.getSize().getHeight()
+            });
         LayoutNode layoutNode = window.getDockingPort().exportLayout();
         LayoutNodeSerializer serializer = new LayoutNodeSerializer();
         win.appendChild(serializer.serialize(doc, layoutNode));
@@ -333,37 +333,37 @@ public class WindowsConfigurationManager {
 
             if (requestFocus) {
                 SwingUtilities.invokeLater(new Runnable() {
-                    @Override
-                    public void run() {
-                        final Thread t = new Thread(new Runnable() {
-                            @Override
-                            public void run() {
-                                synchronized (currentlyRestored) {
-                                    while (currentlyRestored.size() > 0) {
-                                        try {
-                                            currentlyRestored.wait();
-                                        } catch (InterruptedException e) {
-                                            e.printStackTrace();
+                        @Override
+                        public void run() {
+                            final Thread t = new Thread(new Runnable() {
+                                    @Override
+                                    public void run() {
+                                        synchronized (currentlyRestored) {
+                                            while (currentlyRestored.size() > 0) {
+                                                try {
+                                                    currentlyRestored.wait();
+                                                } catch (InterruptedException e) {
+                                                    e.printStackTrace();
+                                                }
+                                            }
                                         }
+
+                                        // Be sure that te main tab or one of its subcomponent
+                                        // will have the focus on start-up
+                                        Component owner = null;
+                                        while (owner == null && !mainTab.isAncestorOf(owner)) {
+                                            mainTab.requestFocus();
+                                            Thread.yield();
+
+                                            owner = window.getFocusOwner();
+                                        }
+                                        ActiveDockableTracker.requestDockableActivation(mainTab);
+                                        window.toFront();
                                     }
-                                }
-
-                                // Be sure that te main tab or one of its subcomponent
-                                // will have the focus on start-up
-                                Component owner = null;
-                                while (owner == null && !mainTab.isAncestorOf(owner)) {
-                                    mainTab.requestFocus();
-                                    Thread.yield();
-
-                                    owner = window.getFocusOwner();
-                                }
-                                ActiveDockableTracker.requestDockableActivation(mainTab);
-                                window.toFront();
-                            }
-                        });
-                        t.start();
-                    }
-                });
+                                });
+                            t.start();
+                        }
+                    });
             }
         }
 
@@ -663,6 +663,11 @@ public class WindowsConfigurationManager {
         }
 
         Element dp = (Element) win.getFirstChild();
+        if (dp == null) {
+            win.getParentNode().removeChild(win);
+            return;
+        }
+
         Element e = validateDockingPortNode(winuuid, dp);
         if (e == null) {
             win.removeChild(dp);
@@ -807,7 +812,7 @@ public class WindowsConfigurationManager {
                                             "factory", factory.getClassName(uuid),
                                             "width", (int) dim.getWidth(),
                                             "height", (int) dim.getHeight()
-                                           });
+            });
         writeDocument();
     }