KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > core > jaxws > nodes > JaxWsClientRootNode


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.core.jaxws.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.netbeans.api.project.FileOwnerQuery;
28 import org.netbeans.api.project.Project;
29 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
30 import org.netbeans.spi.project.ui.support.CommonProjectActions;
31 import org.openide.actions.FindAction;
32 import org.openide.actions.PasteAction;
33 import org.openide.actions.ToolsAction;
34 import org.openide.filesystems.FileObject;
35 import org.openide.filesystems.Repository;
36 import org.openide.loaders.DataFolder;
37 import org.openide.nodes.AbstractNode;
38 import org.openide.nodes.Node;
39 import org.openide.util.HelpCtx;
40 import org.openide.util.Lookup;
41 import org.openide.util.NbBundle;
42 import org.openide.util.Utilities;
43 import org.openide.util.actions.SystemAction;
44 import org.openide.util.lookup.Lookups;
45
46 public class JaxWsClientRootNode extends AbstractNode {
47
48  
49     private static final Image JavaDoc WEB_SERVICES_BADGE = Utilities.loadImage( "org/netbeans/modules/websvc/core/webservices/ui/resources/webservicegroup.png", true ); // NOI18N
50
private final DataFolder srcFolder;
51     
52     public JaxWsClientRootNode(JaxWsModel jaxWsModel, FileObject srcRoot) {
53         super(new JaxWsClientRootChildren(jaxWsModel,srcRoot), createLookup(srcRoot));
54         setDisplayName(NbBundle.getBundle(JaxWsClientRootNode.class).getString("LBL_ServiceReferences"));
55         if(srcRoot.isFolder()) {
56             srcFolder = DataFolder.findFolder(srcRoot);
57         } else {
58             srcFolder = null;
59         }
60     }
61     
62     public Image JavaDoc getIcon( int type ) {
63         return computeIcon( false, type );
64     }
65     
66     public Image JavaDoc getOpenedIcon( int type ) {
67         return computeIcon( true, type );
68     }
69     
70     /**
71      * Returns Icon of folder on active platform
72      * @param opened should the icon represent opened folder
73      * @return the folder icon
74      */

75     static synchronized Icon JavaDoc getFolderIcon (boolean opened) {
76         if (JaxWsRootNode.openedFolderIconCache == null) {
77             Node n = DataFolder.findFolder(Repository.getDefault().getDefaultFileSystem().getRoot()).getNodeDelegate();
78             JaxWsRootNode.openedFolderIconCache = new ImageIcon JavaDoc(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
79             JaxWsRootNode.folderIconCache = new ImageIcon JavaDoc(n.getIcon(BeanInfo.ICON_COLOR_16x16));
80         }
81         if (opened) {
82             return JaxWsRootNode.openedFolderIconCache;
83         }
84         else {
85             return JaxWsRootNode.folderIconCache;
86         }
87     }
88
89     private Image JavaDoc computeIcon( boolean opened, int type ) {
90         Icon JavaDoc icon = getFolderIcon(opened);
91         Image JavaDoc image = ((ImageIcon JavaDoc)icon).getImage();
92         image = Utilities.mergeImages(image, WEB_SERVICES_BADGE, 7, 7 );
93         return image;
94     }
95
96     public Action JavaDoc[] getActions(boolean context) {
97         return new Action JavaDoc[]{
98             CommonProjectActions.newFileAction(),
99             null,
100             SystemAction.get(FindAction.class),
101             null,
102             SystemAction.get(PasteAction.class),
103             null,
104             SystemAction.get(ToolsAction.class)
105         };
106     }
107     
108     public HelpCtx getHelpCtx() {
109         return HelpCtx.DEFAULT_HELP;
110     }
111     
112     private static Lookup createLookup(final FileObject srcRoot) {
113         Project owner = FileOwnerQuery.getOwner(srcRoot);
114         return (owner != null) ? Lookups.fixed(new Object JavaDoc[]{ owner }) : null;
115     }
116     
117 }
118
Popular Tags