This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 97813
Collapse All | Expand All

(-)a/db/src/org/netbeans/api/db/explorer/node/BaseNode.java (-43 / +59 lines)
Lines 39-47 Link Here
39
 * 
39
 * 
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.api.db.explorer.node;
42
package org.netbeans.api.db.explorer.node;
44
43
44
import java.awt.datatransfer.DataFlavor;
45
import java.awt.datatransfer.Transferable;
46
import java.io.IOException;
45
import java.util.Collection;
47
import java.util.Collection;
46
import java.util.Collections;
48
import java.util.Collections;
47
import java.util.HashMap;
49
import java.util.HashMap;
Lines 61-71 Link Here
61
import org.openide.nodes.Sheet;
63
import org.openide.nodes.Sheet;
62
import org.openide.util.NbBundle;
64
import org.openide.util.NbBundle;
63
import org.openide.util.RequestProcessor;
65
import org.openide.util.RequestProcessor;
66
import org.openide.util.datatransfer.ExTransferable;
64
67
65
/**
68
/**
66
 * This is the base class for all database explorer nodes.  It takes care of setting
69
 * This is the base class for all database explorer nodes. It takes care of
67
 * up its Lookup and registering the child factory.
70
 * setting up its Lookup and registering the child factory.
68
 * 
71
 *
69
 * @author Rob Englander
72
 * @author Rob Englander
70
 */
73
 */
71
public abstract class BaseNode extends AbstractNode {
74
public abstract class BaseNode extends AbstractNode {
Lines 121-142 Link Here
121
    protected static final String PKPARTDESC = "PKPartDescription"; // NOI18N
124
    protected static final String PKPARTDESC = "PKPartDescription"; // NOI18N
122
    protected static final String INDEXPART = "IndexPart"; // NOI18N
125
    protected static final String INDEXPART = "IndexPart"; // NOI18N
123
    protected static final String INDEXPARTDESC = "IndexPartDescription"; // NOI18N
126
    protected static final String INDEXPARTDESC = "IndexPartDescription"; // NOI18N
124
125
    private final NodeDataLookup dataLookup;
127
    private final NodeDataLookup dataLookup;
126
    private final ActionRegistry actionRegistry;
128
    private final ActionRegistry actionRegistry;
127
    private final NodeRegistry nodeRegistry;
129
    private final NodeRegistry nodeRegistry;
128
    private final ChildNodeFactory childNodeFactory;
130
    private final ChildNodeFactory childNodeFactory;
129
    private final NodeProvider nodeProvider;
131
    private final NodeProvider nodeProvider;
130
131
    private final List<Property> props = new CopyOnWriteArrayList<Property>();
132
    private final List<Property> props = new CopyOnWriteArrayList<Property>();
132
    private final HashMap<String, Object> propMap = new HashMap<String, Object>();
133
    private final HashMap<String, Object> propMap = new HashMap<String, Object>();
133
134
    public boolean isRemoved = false;
134
    public boolean isRemoved = false;
135
135
136
137
    /**
136
    /**
138
     * Constructor for nodes without children.
137
     * Constructor for nodes without children.
139
     * 
138
     *
140
     * @param dataLookup the data lookup for this node
139
     * @param dataLookup the data lookup for this node
141
     */
140
     */
142
    public BaseNode(NodeDataLookup dataLookup, String layerEntry, NodeProvider provider) {
141
    public BaseNode(NodeDataLookup dataLookup, String layerEntry, NodeProvider provider) {
Lines 145-152 Link Here
145
144
146
    /**
145
    /**
147
     * Constructor for nodes with children.
146
     * Constructor for nodes with children.
148
     * 
147
     *
149
     * @param childFactory the child factory used to create children of this node
148
     * @param childFactory the child factory used to create children of this
149
     * node
150
     * @param dataLookup the data lookup for this node
150
     * @param dataLookup the data lookup for this node
151
     */
151
     */
152
    public BaseNode(ChildNodeFactory childFactory, NodeDataLookup dataLookup, String layerEntry, NodeProvider provider) {
152
    public BaseNode(ChildNodeFactory childFactory, NodeDataLookup dataLookup, String layerEntry, NodeProvider provider) {
Lines 155-161 Link Here
155
155
156
    /**
156
    /**
157
     * Private constructor used by the public constructors.
157
     * Private constructor used by the public constructors.
158
     * 
158
     *
159
     * @param children the children of this node
159
     * @param children the children of this node
160
     * @param factory the child factory to use
160
     * @param factory the child factory to use
161
     * @param lookup the associated lookup
161
     * @param lookup the associated lookup
Lines 169-178 Link Here
169
        nodeRegistry = NodeRegistry.create(layerEntry, dataLookup);
169
        nodeRegistry = NodeRegistry.create(layerEntry, dataLookup);
170
        nodeProvider = provider;
170
        nodeProvider = provider;
171
    }
171
    }
172
    
172
173
    /**
173
    /**
174
     * Initialize the node.  This method is called before the creation process
174
     * Initialize the node. This method is called before the creation process
175
     * completes so that the sub class can perform any initialization it requires.
175
     * completes so that the sub class can perform any initialization it
176
     * requires.
176
     */
177
     */
177
    protected abstract void initialize();
178
    protected abstract void initialize();
178
179
Lines 187-193 Link Here
187
188
188
    /**
189
    /**
189
     * Set up the node
190
     * Set up the node
190
     * 
191
     *
191
     * @param dataLookup the data lookup
192
     * @param dataLookup the data lookup
192
     * @param layerEntry the name of the layer entry folder
193
     * @param layerEntry the name of the layer entry folder
193
     * @param factory the associated child node factory, or null if this node
194
     * @param factory the associated child node factory, or null if this node
Lines 197-211 Link Here
197
        // put the node registry and this node into the lookup
198
        // put the node registry and this node into the lookup
198
        dataLookup.add(nodeRegistry);
199
        dataLookup.add(nodeRegistry);
199
        dataLookup.add(this);
200
        dataLookup.add(this);
200
        
201
201
        // listen for changes to the node registry
202
        // listen for changes to the node registry
202
        nodeRegistry.addChangeListener(
203
        nodeRegistry.addChangeListener(
203
            new ChangeListener() {
204
                new ChangeListener() {
204
                public void stateChanged(ChangeEvent evt) {
205
205
                    update();
206
                    public void stateChanged(ChangeEvent evt) {
206
                }
207
                        update();
207
            }
208
                    }
208
        );
209
                });
209
210
210
        initialize();
211
        initialize();
211
        updateProperties();
212
        updateProperties();
Lines 220-240 Link Here
220
        nodeProvider.removeNode(this);
221
        nodeProvider.removeNode(this);
221
        if (refreshProvider) {
222
        if (refreshProvider) {
222
            RequestProcessor.getDefault().post(
223
            RequestProcessor.getDefault().post(
223
                new Runnable() {
224
                    new Runnable() {
224
                    public void run() {
225
225
                        Node parent = getParentNode();
226
                        public void run() {
226
                        if (parent instanceof BaseNode) {
227
                            Node parent = getParentNode();
227
                            ((BaseNode)parent).refresh();
228
                            if (parent instanceof BaseNode) {
229
                                ((BaseNode) parent).refresh();
230
                            }
228
                        }
231
                        }
229
                    }
232
                    });
230
                }
231
            );
232
        }
233
        }
233
    }
234
    }
234
235
235
    /**
236
    /**
236
     * Get the list of child nodes.
237
     * Get the list of child nodes.
237
     * 
238
     *
238
     * @return the list of child nodes.
239
     * @return the list of child nodes.
239
     */
240
     */
240
    public Collection<? extends Node> getChildNodesSync() {
241
    public Collection<? extends Node> getChildNodesSync() {
Lines 251-257 Link Here
251
    /**
252
    /**
252
     * Updates the node.
253
     * Updates the node.
253
     */
254
     */
254
    public void update() { 
255
    public void update() {
255
        updateProperties();
256
        updateProperties();
256
257
257
        if (childNodeFactory != null) {
258
        if (childNodeFactory != null) {
Lines 275-281 Link Here
275
        for (Property prop : props) {
276
        for (Property prop : props) {
276
            getSheet().get(Sheet.PROPERTIES).remove(prop.getName());
277
            getSheet().get(Sheet.PROPERTIES).remove(prop.getName());
277
        }
278
        }
278
        
279
279
        props.clear();
280
        props.clear();
280
        propMap.clear();
281
        propMap.clear();
281
    }
282
    }
Lines 286-298 Link Here
286
    }
287
    }
287
288
288
    protected void addProperty(String name, String desc, Class clazz, boolean writeable, Object value) {
289
    protected void addProperty(String name, String desc, Class clazz, boolean writeable, Object value) {
289
        String propName = NbBundle.getMessage (BaseNode.class, name);
290
        String propName = NbBundle.getMessage(BaseNode.class, name);
290
291
291
        String propDesc;
292
        String propDesc;
292
        if (desc == null) {
293
        if (desc == null) {
293
            propDesc = propName;
294
            propDesc = propName;
294
        } else {
295
        } else {
295
            propDesc = NbBundle.getMessage (BaseNode.class, desc);
296
            propDesc = NbBundle.getMessage(BaseNode.class, desc);
296
        }
297
        }
297
        PropertySupport ps = new NodePropertySupport(this, name, clazz, propName, propDesc, writeable);
298
        PropertySupport ps = new NodePropertySupport(this, name, clazz, propName, propDesc, writeable);
298
        props.add(ps);
299
        props.add(ps);
Lines 322-328 Link Here
322
323
323
    /**
324
    /**
324
     * Gets the actions associated with this node.
325
     * Gets the actions associated with this node.
325
     * 
326
     *
326
     * @param context true if this is for a context menu, false otherwise
327
     * @param context true if this is for a context menu, false otherwise
327
     * @return an array of Actions
328
     * @return an array of Actions
328
     */
329
     */
Lines 331-358 Link Here
331
        if (context) {
332
        if (context) {
332
            return super.getActions(true);
333
            return super.getActions(true);
333
        }
334
        }
334
        
335
335
        // get the actions from the registry
336
        // get the actions from the registry
336
        Collection<Action> actions = actionRegistry.getActions();
337
        Collection<Action> actions = actionRegistry.getActions();
337
        return actions.toArray (new Action[actions.size ()]);
338
        return actions.toArray(new Action[actions.size()]);
338
    }
339
    }
339
    
340
340
    /**
341
    /**
341
     * Get the icon base for the current state of the node.
342
     * Get the icon base for the current state of the node.
343
     *
342
     * @return the icon base
344
     * @return the icon base
343
     */
345
     */
344
    public abstract String getIconBase();
346
    public abstract String getIconBase();
345
347
346
    /**
348
    /**
347
     * Get the name for the current state of the node.
349
     * Get the name for the current state of the node.
350
     *
348
     * @return the name
351
     * @return the name
349
     */
352
     */
350
    @Override
353
    @Override
351
    public abstract String getName();
354
    public abstract String getName();
352
    
355
353
    /**
356
    /**
354
     * Destroy the node.
357
     * Destroy the node.
355
     * 
358
     *
356
     */
359
     */
357
    @Override
360
    @Override
358
    public void destroy() {
361
    public void destroy() {
Lines 360-365 Link Here
360
363
361
    /**
364
    /**
362
     * Determine if this node can be destroyed.
365
     * Determine if this node can be destroyed.
366
     *
363
     * @return true if it can, false otherwise
367
     * @return true if it can, false otherwise
364
     */
368
     */
365
    @Override
369
    @Override
Lines 379-385 Link Here
379
383
380
    @Override
384
    @Override
381
    public boolean canCopy() {
385
    public boolean canCopy() {
382
        return false;
386
        return true;
383
    }
387
    }
384
388
389
    @Override
390
    public Transferable clipboardCopy() throws IOException {
391
        Transferable deflt = super.clipboardCopy();
392
        ExTransferable added = ExTransferable.create(deflt);
393
        added.put(new ExTransferable.Single(DataFlavor.stringFlavor) {
394
            @Override
395
            protected Object getData() {
396
                return getDisplayName();
397
            }
398
        });
399
        return added;
400
    }
385
}
401
}

Return to bug 97813