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.mapper.xpatheditor;
21:
22: import java.util.ArrayList;
23: import java.util.Enumeration;
24: import org.netbeans.modules.soa.ui.nodes.NodeFactory;
25: import org.openide.loaders.DataFolder;
26: import org.openide.loaders.XMLDataObject;
27: import org.openide.nodes.Children;
28: import org.openide.nodes.Node;
29: import org.openide.util.Lookup;
30:
31: /**
32: *
33: * @author nk160297
34: */
35: public class CategoryChildren extends Children.Keys {
36:
37: private Lookup myLookup;
38:
39: public CategoryChildren(DataFolder paletteFolder, Lookup lookup) {
40: myLookup = lookup;
41: setKeys(new Object[] { paletteFolder });
42: }
43:
44: protected Node[] createNodes(Object key) {
45: assert key instanceof DataFolder;
46: //
47: NodeFactory factory = (NodeFactory) myLookup
48: .lookup(NodeFactory.class);
49: assert factory != null;
50: //
51: DataFolder df = (DataFolder) key;
52: Enumeration childEnum = df.children();
53: //
54: ArrayList<Node> nodesList = new ArrayList<Node>();
55: //
56: while (childEnum.hasMoreElements()) {
57: Object next = childEnum.nextElement();
58: if (next instanceof DataFolder) {
59: Node newNode = factory.createNode(
60: PaletteTreeNodeFactory.NodeType.CATEGORY, next,
61: myLookup);
62: nodesList.add(newNode);
63: } else if (next instanceof XMLDataObject) {
64: Node newNode = factory.createNode(
65: PaletteTreeNodeFactory.NodeType.ITEM, next,
66: myLookup);
67: if (newNode != null) {
68: nodesList.add(newNode);
69: }
70: }
71: }
72: //
73: Node[] nodesArr = nodesList.toArray(new Node[nodesList.size()]);
74: return nodesArr;
75: }
76:
77: }
|