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 java.awt.Toolkit;
24: import java.net.URL;
25: import java.util.ResourceBundle;
26: import org.netbeans.modules.xslt.mapper.methoid.Constants;
27: import org.openide.filesystems.FileObject;
28: import org.openide.filesystems.Repository;
29: import org.openide.loaders.DataFolder;
30: import org.openide.nodes.AbstractNode;
31: import org.openide.nodes.Children;
32: import org.openide.util.Lookup;
33:
34: /**
35: * A node for palette category.
36: *
37: * @author nk160297
38: */
39: public class CategoryNode extends AbstractNode {
40:
41: private DataFolder myFolder;
42: private Image myImage;
43:
44: public CategoryNode(DataFolder paletteFolder, Children children,
45: Lookup lookup) {
46: super (children, lookup);
47: myFolder = paletteFolder;
48: //
49: String metainfoRef = (String) myFolder.getPrimaryFile()
50: .getAttribute(Constants.METAINFO_REF);
51: if (metainfoRef != null && metainfoRef.length() != 0) {
52: FileObject metainfoFo = Repository.getDefault()
53: .getDefaultFileSystem().findResource(metainfoRef);
54: if (metainfoFo != null) {
55: String bundleRef = (String) metainfoFo
56: .getAttribute(Constants.BUNDLE_CLASS);
57: ResourceBundle bundle = ResourceBundle
58: .getBundle(bundleRef);
59: String iconRefName = (String) metainfoFo
60: .getAttribute(Constants.CATEGORY_ICON);
61: String iconName = bundle.getString(iconRefName);
62: URL iconUrl = this .getClass().getResource(iconName);
63: myImage = Toolkit.getDefaultToolkit().getImage(iconUrl);
64: //
65: String name = (String) metainfoFo.getName();
66: setName(name);
67: setDisplayName(name);
68: }
69: }
70:
71: }
72:
73: public String getHtmlDisplayName() {
74: return getName();
75: }
76:
77: public Image getIcon(int type) {
78: return myImage != null ? myImage : super .getIcon(type);
79: }
80:
81: public Image getOpenedIcon(int type) {
82: return getIcon(type);
83: }
84: }
|