KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > jaxrpc > nodes > WebServicesRootNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * 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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.websvc.jaxrpc.nodes;
20
21 import java.beans.BeanInfo JavaDoc;
22 import javax.swing.Icon JavaDoc;
23 import javax.swing.ImageIcon JavaDoc;
24 import org.openide.filesystems.Repository;
25 import org.openide.nodes.AbstractNode;
26 import java.awt.Image JavaDoc;
27 import org.openide.util.HelpCtx;
28 import org.openide.util.NbBundle;
29 import javax.swing.Action JavaDoc;
30 import org.openide.util.Utilities;
31 import org.openide.filesystems.FileObject;
32 import org.openide.loaders.DataFolder;
33 import org.openide.nodes.Children;
34 import org.openide.nodes.Node;
35 import org.openide.util.Lookup;
36 import org.openide.util.lookup.Lookups;
37
38 public class WebServicesRootNode extends AbstractNode {
39     private static Image JavaDoc WEB_SERVICES_BADGE = Utilities.loadImage( "org/netbeans/modules/websvc/core/webservices/ui/resources/webservicegroup.png", true ); // NOI18N
40
private static Icon JavaDoc folderIconCache;
41     private static Icon JavaDoc openedFolderIconCache;
42     
43     public WebServicesRootNode(FileObject srcRoot) {
44         super((srcRoot != null) ? new WebServicesChildren(srcRoot) : Children.LEAF, createLookup(srcRoot));
45         setDisplayName(NbBundle.getBundle(WebServicesRootNode.class).getString("LBL_WebServices"));
46     }
47     
48     public Image JavaDoc getIcon( int type ) {
49         return computeIcon( false, type );
50     }
51     
52     public Image JavaDoc getOpenedIcon( int type ) {
53         return computeIcon( true, type );
54     }
55     
56     /**
57      * Returns Icon of folder on active platform
58      * @param opened should the icon represent opened folder
59      * @return the folder icon
60      */

61     static synchronized Icon JavaDoc getFolderIcon (boolean opened) {
62         if (openedFolderIconCache == null) {
63             Node n = DataFolder.findFolder(Repository.getDefault().getDefaultFileSystem().getRoot()).getNodeDelegate();
64             openedFolderIconCache = new ImageIcon JavaDoc(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
65             folderIconCache = new ImageIcon JavaDoc(n.getIcon(BeanInfo.ICON_COLOR_16x16));
66         }
67         if (opened) {
68             return openedFolderIconCache;
69         }
70         else {
71             return folderIconCache;
72         }
73     }
74
75     private Image JavaDoc computeIcon( boolean opened, int type ) {
76         Icon JavaDoc icon = getFolderIcon(opened);
77         Image JavaDoc image = ((ImageIcon JavaDoc)icon).getImage();
78         image = Utilities.mergeImages(image, WEB_SERVICES_BADGE, 7, 7 );
79         return image;
80     }
81
82     public Action JavaDoc[] getActions(boolean context) {
83         return new Action JavaDoc[]{
84             org.netbeans.spi.project.ui.support.CommonProjectActions.newFileAction(),
85             null,
86             org.openide.util.actions.SystemAction.get(org.openide.actions.FindAction.class),
87             null,
88             org.openide.util.actions.SystemAction.get(org.openide.actions.PasteAction.class),
89             null,
90             org.openide.util.actions.SystemAction.get(org.openide.actions.ToolsAction.class)
91         };
92     }
93     
94     private static Lookup createLookup(FileObject srcFolder) {
95         // !PW FIXME -- from source -- Remove DataFolder when paste, find and refresh are reimplemented
96
// !PW FIXME implement pathing and add PathFinder to lookup.
97
if(srcFolder != null) {
98             DataFolder dataFolder = DataFolder.findFolder(srcFolder);
99             return Lookups.fixed(new Object JavaDoc[]{ dataFolder /*, new PathFinder( group ) */ });
100         } else {
101             return Lookups.fixed(new Object JavaDoc[]{ /* new PathFinder( group ) */ });
102         }
103     }
104
105     public HelpCtx getHelpCtx() {
106         return HelpCtx.DEFAULT_HELP;
107     }
108     
109 }
110
Popular Tags