KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 package org.netbeans.modules.websvc.jaxrpc.nodes;
21
22 import java.awt.Image JavaDoc;
23 import java.beans.BeanInfo JavaDoc;
24 import javax.swing.Action JavaDoc;
25 import javax.swing.Icon JavaDoc;
26 import javax.swing.ImageIcon JavaDoc;
27 import org.openide.filesystems.Repository;
28
29 import org.openide.nodes.CookieSet;
30 import org.openide.nodes.Children;
31 import org.openide.nodes.Node;
32 import org.openide.nodes.AbstractNode;
33 import org.openide.filesystems.FileObject;
34 import org.openide.loaders.DataFolder;
35 import org.openide.loaders.DataObjectNotFoundException;
36 import org.openide.util.Lookup;
37 import org.openide.util.NbBundle;
38 import org.openide.util.Utilities;
39 import org.openide.util.lookup.Lookups;
40 import org.openide.util.actions.SystemAction;
41 import org.openide.util.actions.NodeAction;
42
43 /** This is the root node for the graph of web services for which this module
44  * has been client-enabled (e.g. services this module is using.)
45  *
46  * @author Peter Williams
47  */

48 public final class ClientRootNode extends AbstractNode {
49
50     private static final Image JavaDoc WEB_SERVICES_BADGE = Utilities.loadImage( "org/netbeans/modules/websvc/core/client/resources/webServiceBadge.gif" ); // NOI18N
51
private static Icon JavaDoc folderIconCache;
52     private static Icon JavaDoc openedFolderIconCache;
53     private FileObject wsdlFolder;
54
55     public ClientRootNode(FileObject wsdlFolder) throws DataObjectNotFoundException {
56         super((wsdlFolder != null) ? new ClientViewChildren(wsdlFolder) : Children.LEAF, createLookup(wsdlFolder));
57         this.wsdlFolder = wsdlFolder;
58         initialize();
59     }
60
61     private void initialize() {
62         // !PW add cookies to registered lookup -- see createLookup() below
63
setName("WebServiceReferences"); // NOI18N
64
setDisplayName(NbBundle.getBundle(ClientRootNode.class).getString("LBL_WebServiceReferences"));
65     }
66
67     public Image JavaDoc getIcon(int type) {
68         return computeIcon(false, type);
69     }
70         
71     public Image JavaDoc getOpenedIcon(int type) {
72         return computeIcon(true, type);
73     }
74     
75     public Action JavaDoc[] getActions(boolean context) {
76         return new Action JavaDoc[] {
77             org.netbeans.spi.project.ui.support.CommonProjectActions.newFileAction(),
78             null,
79 // org.openide.util.actions.SystemAction.get( org.netbeans.modules.websvc.jaxrpc.actions.RefreshClientsAction.class ),
80
org.openide.util.actions.SystemAction.get( org.openide.actions.FindAction.class ),
81             null,
82             org.openide.util.actions.SystemAction.get( org.openide.actions.PasteAction.class ),
83             null,
84             org.openide.util.actions.SystemAction.get( org.openide.actions.ToolsAction.class )
85         };
86     }
87
88     /**
89      * Returns Icon of folder on active platform
90      * @param opened should the icon represent opened folder
91      * @return the folder icon
92      */

93     static synchronized Icon JavaDoc getFolderIcon (boolean opened) {
94         if (openedFolderIconCache == null) {
95             Node n = DataFolder.findFolder(Repository.getDefault().getDefaultFileSystem().getRoot()).getNodeDelegate();
96             openedFolderIconCache = new ImageIcon JavaDoc(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
97             folderIconCache = new ImageIcon JavaDoc(n.getIcon(BeanInfo.ICON_COLOR_16x16));
98         }
99         if (opened) {
100             return openedFolderIconCache;
101         }
102         else {
103             return folderIconCache;
104         }
105     }
106
107     private Image JavaDoc computeIcon( boolean opened, int type ) {
108         Icon JavaDoc icon = getFolderIcon(opened);
109         Image JavaDoc image = ((ImageIcon JavaDoc)icon).getImage();
110         image = Utilities.mergeImages(image, WEB_SERVICES_BADGE, 7, 7 );
111         return image;
112     }
113
114     private static Lookup createLookup(FileObject wsdlFolder) {
115         // !PW FIXME -- from source -- Remove DataFolder when paste, find and refresh are reimplemented
116
// !PW FIXME implement pathing and add PathFinder to lookup.
117
if(wsdlFolder != null) {
118             DataFolder dataFolder = DataFolder.findFolder(wsdlFolder);
119             return Lookups.fixed(new Object JavaDoc[]{ dataFolder /*, new PathFinder( group ) */ });
120         } else {
121             return Lookups.fixed(new Object JavaDoc[]{ /* new PathFinder( group ) */ });
122         }
123     }
124 }
125
Popular Tags