01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * When distributing Covered Code, include this CDDL Header Notice in each file
10: * and include the License file at http://www.netbeans.org/cddl.txt.
11: * If applicable, add the following below the CDDL Header, with the fields
12: * enclosed by brackets [] replaced by your own identifying information:
13: * "Portions Copyrighted [year] [name of copyright owner]"
14: *
15: * The Original Software is NetBeans. The Initial Developer of the Original
16: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17: * Microsystems, Inc. All Rights Reserved.
18: */
19:
20: package org.netbeans.modules.xslt.tmap.nodes;
21:
22: import java.util.Collection;
23: import java.util.Collections;
24: import org.netbeans.modules.xslt.tmap.model.api.TMapComponent;
25: import org.openide.nodes.Children;
26: import org.openide.nodes.Node;
27: import org.openide.util.Lookup;
28:
29: /**
30: *
31: * @author Vitaly Bychkov
32: * @version 1.0
33: */
34: public abstract class TMapComponentNodeChildren<T extends TMapComponent>
35: extends Children.Keys implements ReloadableChildren {
36:
37: private Lookup myLookup;
38: private T myComponent;
39:
40: public TMapComponentNodeChildren(T component, Lookup lookup) {
41: myLookup = lookup;
42: myComponent = component;
43: }
44:
45: public Lookup getLookup() {
46: return myLookup;
47: }
48:
49: public T getReference() {
50: return myComponent;
51: }
52:
53: public abstract Collection getNodeKeys();
54:
55: protected Node[] createNodes(Object key) {
56: if (key != null && key instanceof TMapComponent) {
57: NavigatorNodeFactory factory = NavigatorNodeFactory
58: .getInstance();
59: Node childNode = factory.createNode((TMapComponent) key,
60: getLookup());
61: if (childNode != null) {
62: return new Node[] { childNode };
63: }
64: }
65:
66: return new Node[0];
67: }
68:
69: @Override
70: protected void addNotify() {
71: reload();
72: }
73:
74: @Override
75: protected void removeNotify() {
76: setKeys(Collections.EMPTY_SET);
77: }
78:
79: public void reload() {
80: setKeys(getNodeKeys());
81: }
82: }
|