1 19 package org.netbeans.modules.websvc.jaxrpc.nodes; 20 21 import java.beans.BeanInfo ; 22 import javax.swing.Icon ; 23 import javax.swing.ImageIcon ; 24 import org.openide.filesystems.Repository; 25 import org.openide.nodes.AbstractNode; 26 import java.awt.Image ; 27 import org.openide.util.HelpCtx; 28 import org.openide.util.NbBundle; 29 import javax.swing.Action ; 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 WEB_SERVICES_BADGE = Utilities.loadImage( "org/netbeans/modules/websvc/core/webservices/ui/resources/webservicegroup.png", true ); private static Icon folderIconCache; 41 private static Icon 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 getIcon( int type ) { 49 return computeIcon( false, type ); 50 } 51 52 public Image getOpenedIcon( int type ) { 53 return computeIcon( true, type ); 54 } 55 56 61 static synchronized Icon getFolderIcon (boolean opened) { 62 if (openedFolderIconCache == null) { 63 Node n = DataFolder.findFolder(Repository.getDefault().getDefaultFileSystem().getRoot()).getNodeDelegate(); 64 openedFolderIconCache = new ImageIcon (n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16)); 65 folderIconCache = new ImageIcon (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 computeIcon( boolean opened, int type ) { 76 Icon icon = getFolderIcon(opened); 77 Image image = ((ImageIcon )icon).getImage(); 78 image = Utilities.mergeImages(image, WEB_SERVICES_BADGE, 7, 7 ); 79 return image; 80 } 81 82 public Action [] getActions(boolean context) { 83 return new Action []{ 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 if(srcFolder != null) { 98 DataFolder dataFolder = DataFolder.findFolder(srcFolder); 99 return Lookups.fixed(new Object []{ dataFolder }); 100 } else { 101 return Lookups.fixed(new Object []{ }); 102 } 103 } 104 105 public HelpCtx getHelpCtx() { 106 return HelpCtx.DEFAULT_HELP; 107 } 108 109 } 110 | Popular Tags |