1 19 20 package org.netbeans.modules.j2ee.earproject.ui; 21 22 import java.awt.Image ; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 import javax.swing.Action ; 26 import org.netbeans.api.project.FileOwnerQuery; 27 import org.netbeans.api.project.Project; 28 import org.netbeans.modules.j2ee.earproject.ProjectPropertyProvider; 29 import org.netbeans.modules.j2ee.earproject.ui.actions.OpenModuleProjectAction; 30 import org.netbeans.modules.j2ee.earproject.ui.customizer.EarProjectProperties; 31 import org.netbeans.modules.j2ee.earproject.ui.customizer.VisualClassPathItem; 32 import org.openide.filesystems.FileObject; 33 import org.openide.nodes.AbstractNode; 34 import org.openide.nodes.Children; 35 import org.openide.nodes.Node; 36 import org.openide.util.HelpCtx; 37 import org.openide.util.NbBundle; 38 import org.openide.util.Utilities; 39 import org.openide.util.actions.SystemAction; 40 41 48 public final class ModuleNode extends AbstractNode implements Node.Cookie { 49 50 51 static final String MODULE_NODE_NAME = "module.node"; 53 private static Action [] actions; 54 55 private final FileObject projectDirectory; 56 private final VisualClassPathItem key; 57 58 public ModuleNode(final VisualClassPathItem key, final FileObject projectDirectory) { 59 super(Children.LEAF); 60 this.key = key; 61 this.projectDirectory = projectDirectory; 62 setName(ModuleNode.MODULE_NODE_NAME); 63 setDisplayName(key.getCompletePathInArchive()); 64 setShortDescription(NbBundle.getMessage(ModuleNode.class, "HINT_ModuleNode")); 65 } 66 67 public Action [] getActions(boolean context) { 69 if (null == actions) { 70 actions = new Action [] { 71 SystemAction.get(OpenModuleProjectAction.class), 72 SystemAction.get(RemoveAction.class) 73 }; 74 getCookieSet().add(this); 75 } 76 return actions; 77 } 78 79 public Action getPreferredAction() { 80 return SystemAction.get(OpenModuleProjectAction.class); 81 } 82 83 public Image getIcon(int type) { 84 if (key.toString().endsWith("war")) { return Utilities.loadImage("org/netbeans/modules/j2ee/earproject/ui/resources/WebModuleNode.gif"); } else if (key.getRaw().indexOf("j2ee-module-car") > 0) { return Utilities.loadImage("org/netbeans/modules/j2ee/earproject/ui/resources/CarModuleNodeIcon.gif"); } else { 91 return Utilities.loadImage("org/netbeans/modules/j2ee/earproject/ui/resources/EjbModuleNodeIcon.gif"); } 93 } 94 95 public Image getOpenedIcon(int type){ 96 return getIcon( type); 97 } 98 99 public HelpCtx getHelpCtx() { 100 return HelpCtx.DEFAULT_HELP; 101 } 102 103 void removeFromJarContent() { 104 List <VisualClassPathItem> newList = new ArrayList <VisualClassPathItem>(); 105 Project p = FileOwnerQuery.getOwner(projectDirectory); 106 ProjectPropertyProvider ppp = 107 (ProjectPropertyProvider) p.getLookup().lookup(ProjectPropertyProvider.class); 108 EarProjectProperties epp = ppp.getProjectProperties(); 109 newList.addAll(epp.getJarContentAdditional()); 110 newList.remove(key); 111 epp.put(EarProjectProperties.JAR_CONTENT_ADDITIONAL, newList); 112 epp.store(); 113 } 114 115 public VisualClassPathItem getVCPI() { 116 return key; 117 } 118 119 public boolean canCopy() { 121 return false; 122 } 123 124 } 125 | Popular Tags |