1 19 20 package org.netbeans.modules.j2ee.earproject.ui; 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.netbeans.modules.j2ee.earproject.ui.actions.AddModuleAction; 28 import org.netbeans.spi.project.support.ant.AntProjectHelper; 29 import org.openide.filesystems.Repository; 30 import org.openide.loaders.DataFolder; 31 import org.openide.nodes.AbstractNode; 32 import org.openide.nodes.Node; 33 import org.openide.util.HelpCtx; 34 import org.openide.util.NbBundle; 35 import org.openide.util.Utilities; 36 import org.openide.util.actions.SystemAction; 37 import org.openide.util.lookup.Lookups; 38 39 45 public final class LogicalViewNode extends AbstractNode { 46 47 static final String J2EE_MODULES_NAME = "j2ee.modules"; private static Image J2EE_MODULES_BADGE = Utilities.loadImage( "org/netbeans/modules/j2ee/earproject/ui/resources/application_16.gif", true ); private static Icon folderIconCache; 50 private static Icon openedFolderIconCache; 51 private final AntProjectHelper model; 52 53 public LogicalViewNode(AntProjectHelper model) { 54 super(new LogicalViewChildren(model), Lookups.fixed( new Object [] { model })); 55 this.model = model; 56 setName(J2EE_MODULES_NAME); 58 setDisplayName(NbBundle.getMessage(LogicalViewNode.class, "LBL_LogicalViewNode")); 59 setShortDescription(NbBundle.getMessage(LogicalViewNode.class, "HINT_LogicalViewNode")); 60 } 61 62 public Image getIcon( int type ) { 63 return computeIcon( false, type ); 64 } 65 66 public Image getOpenedIcon( int type ) { 67 return computeIcon( true, type ); 68 } 69 74 static synchronized Icon getFolderIcon (boolean opened) { 75 if (openedFolderIconCache == null) { 76 Node n = DataFolder.findFolder(Repository.getDefault().getDefaultFileSystem().getRoot()).getNodeDelegate(); 77 openedFolderIconCache = new ImageIcon (n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16)); 78 folderIconCache = new ImageIcon (n.getIcon(BeanInfo.ICON_COLOR_16x16)); 79 } 80 if (opened) { 81 return openedFolderIconCache; 82 } 83 else { 84 return folderIconCache; 85 } 86 } 87 88 private Image computeIcon( boolean opened, int type ) { 89 Icon icon = getFolderIcon(opened); 90 Image image = ((ImageIcon )icon).getImage(); 91 image = Utilities.mergeImages(image, J2EE_MODULES_BADGE, 7, 7 ); 92 return image; 93 } 94 95 public Action [] getActions(boolean context) { 97 return new Action [] { 98 SystemAction.get(AddModuleAction.class), 99 }; 100 } 101 102 public HelpCtx getHelpCtx() { 103 return HelpCtx.DEFAULT_HELP; 104 } 107 108 public boolean canCopy() { 110 return false; 111 } 112 113 } 114 | Popular Tags |