1) Fixed issue #779: PHPEclipse reports error with a correct try/catch block
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / view / bookmark / SchemaNode.java
index 4b6f3c3..5181d2e 100644 (file)
@@ -1,6 +1,9 @@
 package com.quantum.view.bookmark;
 
 import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 
 import com.quantum.model.Bookmark;
 import com.quantum.model.NotConnectedException;
@@ -37,14 +40,35 @@ public class SchemaNode extends TreeNode implements SchemaHolder {
     }
 
     protected void initializeChildren() {
+       boolean firstTimeInitialization = this.children.isEmpty();
+       boolean changed = false;
+        Map temp = new HashMap();
+        for (Iterator i = this.children.iterator(); i.hasNext();) {
+                       GroupNode element = (GroupNode) i.next();
+                       temp.put(element.getType(), element);
+               }
         this.children.clear();
+        
         Bookmark bookmark = getBookmark();
         try {
             String[] types = bookmark.getDatabase().getEntityTypes();
             for (int i = 0, length = (types == null) ? 0 : types.length;
                 i < length;
                 i++) {
-                this.children.add(new GroupNode(this, this.schema, types[i]));
+               GroupNode node = (GroupNode) temp.remove(types[i]);
+               if (node == null) {
+                       this.children.add(new GroupNode(this, this.schema, types[i]));
+                       changed = true;
+               } else {
+                       this.children.add(node);
+               }
+            }
+            for (Iterator i = temp.values().iterator(); i.hasNext();) {
+                               ((GroupNode) i.next()).dispose();
+                               changed = true;
+                       }
+            if (!firstTimeInitialization && changed) {
+               firePropertyChange("children", null, null);
             }
         } catch (NotConnectedException e) {
         } catch (SQLException e) {
@@ -69,9 +93,7 @@ public class SchemaNode extends TreeNode implements SchemaHolder {
      * @see com.quantum.view.bookmark.TreeNode#getImageName()
      */
     protected String getImageName() {
-        return this.schema.isDefault() 
-                       ? "user.gif" 
-                       :  this.schema.exists() 
+        return this.schema.exists() 
                                ? "schema.gif" 
                                : "missingschema.gif";
     }