1 19 20 package org.netbeans.modules.websvc.jaxrpc.nodes; 21 22 import java.awt.Image ; 23 import java.beans.BeanInfo ; 24 import javax.swing.Action ; 25 import javax.swing.Icon ; 26 import javax.swing.ImageIcon ; 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 48 public final class ClientRootNode extends AbstractNode { 49 50 private static final Image WEB_SERVICES_BADGE = Utilities.loadImage( "org/netbeans/modules/websvc/core/client/resources/webServiceBadge.gif" ); private static Icon folderIconCache; 52 private static Icon 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 setName("WebServiceReferences"); setDisplayName(NbBundle.getBundle(ClientRootNode.class).getString("LBL_WebServiceReferences")); 65 } 66 67 public Image getIcon(int type) { 68 return computeIcon(false, type); 69 } 70 71 public Image getOpenedIcon(int type) { 72 return computeIcon(true, type); 73 } 74 75 public Action [] getActions(boolean context) { 76 return new Action [] { 77 org.netbeans.spi.project.ui.support.CommonProjectActions.newFileAction(), 78 null, 79 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 93 static synchronized Icon getFolderIcon (boolean opened) { 94 if (openedFolderIconCache == null) { 95 Node n = DataFolder.findFolder(Repository.getDefault().getDefaultFileSystem().getRoot()).getNodeDelegate(); 96 openedFolderIconCache = new ImageIcon (n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16)); 97 folderIconCache = new ImageIcon (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 computeIcon( boolean opened, int type ) { 108 Icon icon = getFolderIcon(opened); 109 Image image = ((ImageIcon )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 if(wsdlFolder != null) { 118 DataFolder dataFolder = DataFolder.findFolder(wsdlFolder); 119 return Lookups.fixed(new Object []{ dataFolder }); 120 } else { 121 return Lookups.fixed(new Object []{ }); 122 } 123 } 124 } 125 | Popular Tags |