1 19 20 package org.netbeans.modules.j2ee.ejbjar.project.ui; 21 22 import java.awt.Image ; 23 import javax.swing.Action ; 24 import org.netbeans.api.java.classpath.ClassPath; 25 import org.netbeans.api.project.Project; 26 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 27 import org.netbeans.modules.j2ee.spi.ejbjar.EjbNodesFactory; 28 import org.netbeans.spi.project.ui.support.CommonProjectActions; 29 import org.openide.filesystems.FileObject; 30 import org.openide.filesystems.Repository; 31 import org.openide.loaders.DataFolder; 32 import org.openide.loaders.DataObjectNotFoundException; 33 import org.openide.nodes.*; 34 import org.openide.util.HelpCtx; 35 import org.openide.util.NbBundle; 36 import org.openide.util.Utilities; 37 import org.openide.util.lookup.Lookups; 38 39 42 public class EjbContainerNode extends AbstractNode { 43 public static final String NAME = "EJBS"; 45 private static final String EJB_BADGE = "org/netbeans/modules/j2ee/ejbjar/project/ui/enterpriseBeansBadge.png"; 47 public EjbContainerNode(EjbJar model, ClassPath srcPath, FileObject ddFile, Project p, EjbNodesFactory nodesFactory) { 48 super(new EjbContainerChildren(model, srcPath, ddFile, nodesFactory), Lookups.singleton(p)); 49 setName(EjbNodesFactory.CONTAINER_NODE_NAME); 50 setDisplayName(NbBundle.getMessage(EjbContainerNode.class, "LBL_node")); 51 setShortDescription(NbBundle.getMessage(EjbContainerNode.class, "HINT_node")); 52 } 53 54 public Action [] getActions(boolean context) { 55 return new Action [] { 56 CommonProjectActions.newFileAction() 57 }; 58 } 59 60 public HelpCtx getHelpCtx() { 61 return HelpCtx.DEFAULT_HELP; 62 } 65 66 public Image getIcon(int type) { 67 return computeIcon(false, type); 68 } 69 70 public Image getOpenedIcon(int type) { 71 return computeIcon(true, type); 72 } 73 74 private Image computeIcon(boolean opened, int type) { 75 Image image; 76 Node iconDelegate = getIconDelegate(); 77 if (opened) { 78 image = iconDelegate != null ? iconDelegate.getOpenedIcon(type) : super.getOpenedIcon(type); 79 } else { 80 image = iconDelegate != null ? iconDelegate.getIcon(type) : super.getIcon(type); 81 } 82 Image badge = Utilities.loadImage(EJB_BADGE); 83 return Utilities.mergeImages(image, badge, 7, 7); 84 } 85 86 private Node getIconDelegate() { 87 try { 88 return DataFolder.find(Repository.getDefault().getDefaultFileSystem().getRoot()).getNodeDelegate(); 89 } 90 catch (DataObjectNotFoundException donfe) { 91 return null; 92 } 93 } 94 } 95 | Popular Tags |