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: package org.netbeans.modules.xslt.mapper.xpatheditor;
20:
21: import org.netbeans.modules.soa.ui.nodes.NodeFactory;
22: import org.netbeans.modules.soa.ui.ExtendedLookup;
23: import org.netbeans.modules.soa.ui.nodes.NodeFactory.TextNode;
24: import org.netbeans.modules.xslt.mapper.xpatheditor.PaletteTreeNodeFactory.NodeType;
25: import org.openide.filesystems.FileObject;
26: import org.openide.loaders.DataFolder;
27: import org.openide.loaders.XMLDataObject;
28: import org.openide.nodes.Children;
29: import org.openide.nodes.Node;
30: import org.openide.util.Lookup;
31:
32: /**
33: * Constructs a palette tree for the expression editor.
34: *
35: * @author nk160297
36: */
37: public class PaletteTreeNodeFactory implements NodeFactory<NodeType> {
38:
39: public static enum NodeType {
40: ROOT, CATEGORY, ITEM;
41: }
42:
43: public PaletteTreeNodeFactory() {
44: }
45:
46: public Node createNode(NodeType nodeType, Object ref,
47: Children children, Lookup lookup) {
48: switch (nodeType) {
49: case ROOT:
50: assert ref instanceof String;
51: return new TextNode(children, (String) ref);
52: case CATEGORY:
53: assert ref instanceof DataFolder;
54: return new CategoryNode((DataFolder) ref, children, lookup);
55: case ITEM:
56: assert ref instanceof XMLDataObject;
57: if (ItemNode.isLiteral((XMLDataObject) ref)) {
58: // Skip all literals
59: return null;
60: } else {
61: return new ItemNode((XMLDataObject) ref, children,
62: lookup);
63: }
64: default:
65: return null;
66: }
67: }
68:
69: public Node createNode(NodeType nodeType, Object ref, Lookup lookup) {
70: //
71: Children children = null;
72: Node newNode = null;
73: //
74: NodeFactory nodeFactory = (NodeFactory) lookup
75: .lookup(NodeFactory.class);
76: if (!(nodeFactory instanceof PaletteTreeNodeFactory)) {
77: lookup = new ExtendedLookup(lookup, this );
78: }
79: //
80: switch (nodeType) {
81: case ROOT:
82: assert ref instanceof FileObject; // Root palette folder
83: DataFolder paletteFolder = DataFolder
84: .findFolder((FileObject) ref);
85: children = new CategoryChildren(paletteFolder, lookup);
86: newNode = createNode(nodeType, "Root", children, lookup); // NOI18N
87: return newNode;
88: case CATEGORY:
89: assert ref instanceof DataFolder;
90: children = new CategoryChildren((DataFolder) ref, lookup);
91: newNode = createNode(nodeType, ref, children, lookup); // NOI18N
92: return newNode;
93: default:
94: newNode = createNode(nodeType, ref, Children.LEAF, lookup);
95: return newNode;
96: }
97: }
98:
99: }
|