# HG changeset patch # User Matthias Bläsing # Date 1331416814 -3600 # Branch dbfixes # Node ID f8ef84e8d2e2fee870e3a4d6fc550a472c458cbc # Parent 7b4f7df167e725aa2ee0df146b41980ff45a29c4 Provide DisplayName of every database node for clipboard (future work: implement richer functionality in subclasses (copy connections for example) diff --git a/db/src/org/netbeans/api/db/explorer/node/BaseNode.java b/db/src/org/netbeans/api/db/explorer/node/BaseNode.java --- a/db/src/org/netbeans/api/db/explorer/node/BaseNode.java +++ b/db/src/org/netbeans/api/db/explorer/node/BaseNode.java @@ -39,9 +39,11 @@ * * Portions Copyrighted 2009 Sun Microsystems, Inc. */ - package org.netbeans.api.db.explorer.node; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import java.io.IOException; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -61,11 +63,12 @@ import org.openide.nodes.Sheet; import org.openide.util.NbBundle; import org.openide.util.RequestProcessor; +import org.openide.util.datatransfer.ExTransferable; /** - * This is the base class for all database explorer nodes. It takes care of setting - * up its Lookup and registering the child factory. - * + * This is the base class for all database explorer nodes. It takes care of + * setting up its Lookup and registering the child factory. + * * @author Rob Englander */ public abstract class BaseNode extends AbstractNode { @@ -121,22 +124,18 @@ protected static final String PKPARTDESC = "PKPartDescription"; // NOI18N protected static final String INDEXPART = "IndexPart"; // NOI18N protected static final String INDEXPARTDESC = "IndexPartDescription"; // NOI18N - private final NodeDataLookup dataLookup; private final ActionRegistry actionRegistry; private final NodeRegistry nodeRegistry; private final ChildNodeFactory childNodeFactory; private final NodeProvider nodeProvider; - private final List props = new CopyOnWriteArrayList(); private final HashMap propMap = new HashMap(); - public boolean isRemoved = false; - /** * Constructor for nodes without children. - * + * * @param dataLookup the data lookup for this node */ public BaseNode(NodeDataLookup dataLookup, String layerEntry, NodeProvider provider) { @@ -145,8 +144,9 @@ /** * Constructor for nodes with children. - * - * @param childFactory the child factory used to create children of this node + * + * @param childFactory the child factory used to create children of this + * node * @param dataLookup the data lookup for this node */ public BaseNode(ChildNodeFactory childFactory, NodeDataLookup dataLookup, String layerEntry, NodeProvider provider) { @@ -155,7 +155,7 @@ /** * Private constructor used by the public constructors. - * + * * @param children the children of this node * @param factory the child factory to use * @param lookup the associated lookup @@ -169,10 +169,11 @@ nodeRegistry = NodeRegistry.create(layerEntry, dataLookup); nodeProvider = provider; } - + /** - * Initialize the node. This method is called before the creation process - * completes so that the sub class can perform any initialization it requires. + * Initialize the node. This method is called before the creation process + * completes so that the sub class can perform any initialization it + * requires. */ protected abstract void initialize(); @@ -187,7 +188,7 @@ /** * Set up the node - * + * * @param dataLookup the data lookup * @param layerEntry the name of the layer entry folder * @param factory the associated child node factory, or null if this node @@ -197,15 +198,15 @@ // put the node registry and this node into the lookup dataLookup.add(nodeRegistry); dataLookup.add(this); - + // listen for changes to the node registry nodeRegistry.addChangeListener( - new ChangeListener() { - public void stateChanged(ChangeEvent evt) { - update(); - } - } - ); + new ChangeListener() { + + public void stateChanged(ChangeEvent evt) { + update(); + } + }); initialize(); updateProperties(); @@ -220,21 +221,21 @@ nodeProvider.removeNode(this); if (refreshProvider) { RequestProcessor.getDefault().post( - new Runnable() { - public void run() { - Node parent = getParentNode(); - if (parent instanceof BaseNode) { - ((BaseNode)parent).refresh(); + new Runnable() { + + public void run() { + Node parent = getParentNode(); + if (parent instanceof BaseNode) { + ((BaseNode) parent).refresh(); + } } - } - } - ); + }); } } /** * Get the list of child nodes. - * + * * @return the list of child nodes. */ public Collection getChildNodesSync() { @@ -251,7 +252,7 @@ /** * Updates the node. */ - public void update() { + public void update() { updateProperties(); if (childNodeFactory != null) { @@ -275,7 +276,7 @@ for (Property prop : props) { getSheet().get(Sheet.PROPERTIES).remove(prop.getName()); } - + props.clear(); propMap.clear(); } @@ -286,13 +287,13 @@ } protected void addProperty(String name, String desc, Class clazz, boolean writeable, Object value) { - String propName = NbBundle.getMessage (BaseNode.class, name); + String propName = NbBundle.getMessage(BaseNode.class, name); String propDesc; if (desc == null) { propDesc = propName; } else { - propDesc = NbBundle.getMessage (BaseNode.class, desc); + propDesc = NbBundle.getMessage(BaseNode.class, desc); } PropertySupport ps = new NodePropertySupport(this, name, clazz, propName, propDesc, writeable); props.add(ps); @@ -322,7 +323,7 @@ /** * Gets the actions associated with this node. - * + * * @param context true if this is for a context menu, false otherwise * @return an array of Actions */ @@ -331,28 +332,30 @@ if (context) { return super.getActions(true); } - + // get the actions from the registry Collection actions = actionRegistry.getActions(); - return actions.toArray (new Action[actions.size ()]); + return actions.toArray(new Action[actions.size()]); } - + /** * Get the icon base for the current state of the node. + * * @return the icon base */ public abstract String getIconBase(); /** * Get the name for the current state of the node. + * * @return the name */ @Override public abstract String getName(); - + /** * Destroy the node. - * + * */ @Override public void destroy() { @@ -360,6 +363,7 @@ /** * Determine if this node can be destroyed. + * * @return true if it can, false otherwise */ @Override @@ -379,7 +383,19 @@ @Override public boolean canCopy() { - return false; + return true; } + @Override + public Transferable clipboardCopy() throws IOException { + Transferable deflt = super.clipboardCopy(); + ExTransferable added = ExTransferable.create(deflt); + added.put(new ExTransferable.Single(DataFlavor.stringFlavor) { + @Override + protected Object getData() { + return getDisplayName(); + } + }); + return added; + } }