[hg] main-silver: #222113: Tables are not deleted from DB tree a...

  • From: Jaroslav Havlin < >
  • To:
  • Subject: [hg] main-silver: #222113: Tables are not deleted from DB tree a...
  • Date: Thu, 15 Nov 2012 16:37:32 -0800

changeset 8e023b9f7ddb in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/8e023b9f7ddb
description:
        #222113: Tables are not deleted from DB tree after deletion

diffstat:

 db/src/org/netbeans/api/db/explorer/node/ChildNodeFactory.java   |    3 +-
 db/src/org/netbeans/modules/db/explorer/node/BaseFilterNode.java |  132 
++++++++++
 db/src/org/netbeans/modules/db/explorer/node/ColumnNode.java     |    5 +-
 db/src/org/netbeans/modules/db/explorer/node/IndexNode.java      |   18 +-
 db/src/org/netbeans/modules/db/explorer/node/TableNode.java      |   29 +--
 5 files changed, 137 insertions(+), 50 deletions(-)

diffs (288 lines):

diff --git a/db/src/org/netbeans/api/db/explorer/node/ChildNodeFactory.java 
b/db/src/org/netbeans/api/db/explorer/node/ChildNodeFactory.java
--- a/db/src/org/netbeans/api/db/explorer/node/ChildNodeFactory.java
+++ b/db/src/org/netbeans/api/db/explorer/node/ChildNodeFactory.java
@@ -44,6 +44,7 @@
 
 import java.util.Collection;
 import java.util.List;
+import org.netbeans.modules.db.explorer.node.BaseFilterNode;
 import org.netbeans.modules.db.explorer.node.NodeRegistry;
 import org.openide.nodes.ChildFactory;
 import org.openide.nodes.Node;
@@ -95,7 +96,7 @@
             return new Node[] {  };
         }
         else {
-            return new Node[]{childNode.cloneNode()}; // clone - see #221817
+            return new Node[]{new BaseFilterNode(childNode)}; // clone - 
#221817
         }
     }
 
diff --git a/db/src/org/netbeans/modules/db/explorer/node/BaseFilterNode.java 
b/db/src/org/netbeans/modules/db/explorer/node/BaseFilterNode.java
new file mode 100644
--- /dev/null
+++ b/db/src/org/netbeans/modules/db/explorer/node/BaseFilterNode.java
@@ -0,0 +1,132 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2012 Sun Microsystems, Inc.
+ */
+package org.netbeans.modules.db.explorer.node;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.WeakHashMap;
+import org.netbeans.modules.db.explorer.action.RefreshAction;
+import org.openide.nodes.FilterNode;
+import org.openide.nodes.Node;
+import org.openide.util.RequestProcessor;
+import org.openide.util.actions.SystemAction;
+
+/**
+ * Extension of FilterNode. It can refresh its parent node (or some other
+ * ancestor) after it is destroyed, if the delegate wishes to do it (the
+ * delegate sets attribute {@link #REFRESH_ANCESTOR_DISTANCE}). See bug 
#222113.
+ *
+ * @author jhavlin
+ */
+public class BaseFilterNode extends FilterNode {
+
+    /**
+     * Distance of ancestor to refresh. If the original node (delegate) 
needs to
+     * refresh its parent (ancestor at distance 1) or some other ancestor 
after
+     * it is destroyed, it has to set attribute with this key to distance of
+     * ancestor to refresh. (1 for parent, 2 for grandparent, ...). See
+     * {@link Node#setValue(java.lang.String, java.lang.Object)}.
+     */
+    public static final String REFRESH_ANCESTOR_DISTANCE =
+            "BaseFilterNode.refreshAncestorDistance";                   
//NOI18N
+    /** */
+    private static RequestProcessor RP =
+            new RequestProcessor(BaseFilterNode.class);
+
+    private static final Map<Node, Object> NODES_TO_REFRESH =
+            new WeakHashMap<Node, Object>();
+
+    public BaseFilterNode(Node original) {
+        super(original);
+    }
+
+    /**
+     * Destroy the original node and check if it wishes to refresh some of 
its
+     * ancestors.
+     */
+    @Override
+    public void destroy() throws IOException {
+        super.destroy();
+        Object ancestorDist = 
getOriginal().getValue(REFRESH_ANCESTOR_DISTANCE);
+        int ancestorDistInt = (ancestorDist instanceof Integer)
+                ? (Integer) ancestorDist : 0;
+        if (ancestorDistInt > 0) {
+            int currentDist = 0;
+            Node ancestor = this;
+            while (currentDist < ancestorDistInt) {
+                if (ancestor.getParentNode() != null) {
+                    ancestor = ancestor.getParentNode();
+                    currentDist++;
+                } else {
+                    break;
+                }
+            }
+            if (currentDist > 0) {
+                scheduleRefresh(ancestor);
+            }
+        }
+    }
+
+    /**
+     * Schedule refreshing of a node. Do not schedule refreshing if it is
+     * already scheduled. See bug #216907
+     */
+    private static void scheduleRefresh(final Node node) {
+        synchronized (NODES_TO_REFRESH) {
+            if (NODES_TO_REFRESH.containsKey(node)) {
+                return;
+            } else {
+                NODES_TO_REFRESH.put(node, new Object());
+            }
+        }
+        RP.post(new Runnable() {
+            @Override
+            public void run() {
+                SystemAction.get(RefreshAction.class).performAction(
+                        new Node[]{node});
+                synchronized (NODES_TO_REFRESH) {
+                    NODES_TO_REFRESH.remove(node);
+                }
+            }
+        }, 250);
+    }
+}
diff --git a/db/src/org/netbeans/modules/db/explorer/node/ColumnNode.java 
b/db/src/org/netbeans/modules/db/explorer/node/ColumnNode.java
--- a/db/src/org/netbeans/modules/db/explorer/node/ColumnNode.java
+++ b/db/src/org/netbeans/modules/db/explorer/node/ColumnNode.java
@@ -54,7 +54,6 @@
 import org.netbeans.modules.db.explorer.DatabaseConnection;
 import org.netbeans.modules.db.explorer.DatabaseConnector;
 import org.netbeans.modules.db.explorer.DatabaseMetaDataTransferAccessor;
-import org.netbeans.modules.db.explorer.action.RefreshAction;
 import org.netbeans.modules.db.metadata.model.api.Action;
 import org.netbeans.modules.db.metadata.model.api.Column;
 import org.netbeans.modules.db.metadata.model.api.Index;
@@ -67,11 +66,9 @@
 import org.netbeans.modules.db.metadata.model.api.Table;
 import org.netbeans.modules.db.metadata.model.api.Tuple;
 import org.netbeans.modules.db.metadata.model.api.PrimaryKey;
-import org.openide.nodes.Node;
 import org.openide.nodes.PropertySupport;
 import org.openide.util.HelpCtx;
 import org.openide.util.NbBundle;
-import org.openide.util.actions.SystemAction;
 import org.openide.util.datatransfer.ExTransferable;
 
 /**
@@ -324,7 +321,7 @@
             LOG.log(Level.INFO, e.getMessage(), e);
         }
 
-        SystemAction.get(RefreshAction.class).performAction(new 
Node[]{getParentNode()});
+        setValue(BaseFilterNode.REFRESH_ANCESTOR_DISTANCE, new Integer(1));
     }
 
     @Override
diff --git a/db/src/org/netbeans/modules/db/explorer/node/IndexNode.java 
b/db/src/org/netbeans/modules/db/explorer/node/IndexNode.java
--- a/db/src/org/netbeans/modules/db/explorer/node/IndexNode.java
+++ b/db/src/org/netbeans/modules/db/explorer/node/IndexNode.java
@@ -51,7 +51,6 @@
 import org.netbeans.lib.ddl.impl.Specification;
 import org.netbeans.modules.db.explorer.DatabaseConnection;
 import org.netbeans.modules.db.explorer.DatabaseConnector;
-import org.netbeans.modules.db.explorer.action.RefreshAction;
 import org.netbeans.modules.db.metadata.model.api.Action;
 import org.netbeans.modules.db.metadata.model.api.Index;
 import org.netbeans.modules.db.metadata.model.api.Metadata;
@@ -60,12 +59,10 @@
 import org.netbeans.modules.db.metadata.model.api.MetadataModelException;
 import org.openide.DialogDisplayer;
 import org.openide.NotifyDescriptor;
-import org.openide.nodes.Node;
 import org.openide.nodes.PropertySupport;
 import org.openide.util.Exceptions;
 import org.openide.util.HelpCtx;
 import org.openide.util.NbBundle;
-import org.openide.util.actions.SystemAction;
 
 /**
  *
@@ -162,20 +159,7 @@
         try {
             Specification spec = connector.getDatabaseSpecification();
             DDLHelper.deleteIndex(spec, schemaName, tablename, getName());
-            
-            // go up as many as 2 nodes to find a parent to refresh
-            Node refreshNode = getParentNode();
-            if (refreshNode == null) {
-                refreshNode = this;
-            } else {
-                Node parent = refreshNode.getParentNode();
-                if (parent != null) {
-                    refreshNode = parent;
-                }
-            }
-
-            SystemAction.get(RefreshAction.class).performAction(new Node[] { 
refreshNode } );
-            
+            setValue(BaseFilterNode.REFRESH_ANCESTOR_DISTANCE, new 
Integer(2));
         } catch (DDLException e) {
             Logger.getLogger(IndexNode.class.getName()).log(Level.INFO, e + 
" while deleting index " + getName());
             DialogDisplayer.getDefault().notify(new 
NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE));
diff --git a/db/src/org/netbeans/modules/db/explorer/node/TableNode.java 
b/db/src/org/netbeans/modules/db/explorer/node/TableNode.java
--- a/db/src/org/netbeans/modules/db/explorer/node/TableNode.java
+++ b/db/src/org/netbeans/modules/db/explorer/node/TableNode.java
@@ -58,7 +58,6 @@
 import org.netbeans.modules.db.explorer.DatabaseConnection;
 import org.netbeans.modules.db.explorer.DatabaseConnector;
 import org.netbeans.modules.db.explorer.DatabaseMetaDataTransferAccessor;
-import org.netbeans.modules.db.explorer.action.RefreshAction;
 import org.netbeans.modules.db.metadata.model.api.Action;
 import org.netbeans.modules.db.metadata.model.api.Metadata;
 import org.netbeans.modules.db.metadata.model.api.MetadataElementHandle;
@@ -72,8 +71,6 @@
 import org.openide.util.Exceptions;
 import org.openide.util.HelpCtx;
 import org.openide.util.NbBundle;
-import org.openide.util.RequestProcessor;
-import org.openide.util.actions.SystemAction;
 import org.openide.util.datatransfer.ExTransferable;
 
 /**
@@ -181,31 +178,7 @@
             Exceptions.printStackTrace(e);
         }
 
-        scheduleRefresh(getParentNode());
-    }
-
-    /**
-     * Schedule refreshing of a node. Do not schedule refreshing if it is
-     * already scheduled. See bug #216907
-     */
-    private static void scheduleRefresh(final Node node) {
-        synchronized (NODES_TO_REFRESH) {
-            if (NODES_TO_REFRESH.containsKey(node)) {
-                return;
-            } else {
-                NODES_TO_REFRESH.put(node, new Object());
-            }
-        }
-        RequestProcessor.getDefault().post(new Runnable() {
-            @Override
-            public void run() {
-                SystemAction.get(RefreshAction.class).performAction(
-                        new Node[]{node});
-                synchronized (NODES_TO_REFRESH) {
-                    NODES_TO_REFRESH.remove(node);
-                }
-            }
-        }, 250);
+        setValue(BaseFilterNode.REFRESH_ANCESTOR_DISTANCE, new Integer(1));
     }
 
     @Override

[hg] main-silver: #222113: Tables are not deleted from DB tree a...

Jaroslav Havlin 11/16/2012

Project Features

About this Project

DB was started in November 2009, is owned by Antonin Nebuzelsky, and has 113 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close