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.awt.Image;
23: import org.netbeans.modules.xslt.mapper.methoid.Constants;
24: import org.openide.filesystems.FileObject;
25: import org.openide.filesystems.Repository;
26: import org.openide.loaders.XMLDataObject;
27: import org.openide.nodes.AbstractNode;
28: import org.openide.nodes.Children;
29: import org.openide.util.Lookup;
30:
31: /**
32: * A node for palette category.
33: *
34: * @author nk160297
35: */
36: public class ItemNode extends AbstractNode {
37:
38: private XMLDataObject myItem;
39:
40: public ItemNode(XMLDataObject paletteItem, Children children,
41: Lookup lookup) {
42: super (children, lookup);
43: myItem = paletteItem;
44: }
45:
46: public static boolean isLiteral(XMLDataObject paletteItem) {
47: FileObject itemFo = paletteItem.getPrimaryFile();
48: String metainfoRef = (String) itemFo
49: .getAttribute(Constants.METAINFO_REF);
50: if (metainfoRef != null && metainfoRef.length() != 0) {
51: FileObject metainfoFo = Repository.getDefault()
52: .getDefaultFileSystem().findResource(metainfoRef);
53: if (metainfoFo != null) {
54: Object literalObj = metainfoFo
55: .getAttribute(Constants.LITERAL_FLAG);
56: if (literalObj != null && literalObj instanceof Boolean) {
57: boolean isLiteral = ((Boolean) literalObj)
58: .booleanValue();
59: return isLiteral;
60: }
61: }
62: }
63: return false;
64: }
65:
66: public XpathPaletteItemInfo getItemInfo() {
67: FileObject itemFo = myItem.getPrimaryFile();
68: String metainfoRef = (String) itemFo
69: .getAttribute(Constants.METAINFO_REF);
70: if (metainfoRef != null && metainfoRef.length() != 0) {
71: FileObject metainfoFo = Repository.getDefault()
72: .getDefaultFileSystem().findResource(metainfoRef);
73: if (metainfoFo != null) {
74: return new XpathPaletteItemInfo(metainfoFo);
75: }
76: }
77: return null;
78: }
79:
80: public String getName() {
81: return myItem.getNodeDelegate().getName();
82: }
83:
84: public String getHtmlDisplayName() {
85: return getName();
86: }
87:
88: public Image getIcon(int type) {
89: return myItem.getNodeDelegate().getIcon(type);
90: }
91:
92: public Image getOpenedIcon(int type) {
93: return getIcon(type);
94: }
95:
96: }
|