KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > earproject > ui > ModuleNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.earproject.ui;
21
22 import java.awt.Image JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25 import javax.swing.Action JavaDoc;
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 /**
42  * Represents one node in the <em>J2EE Modules</em> node in the EAR project's
43  * logical view.
44  *
45  * @author vkraemer
46  * @author Ludovic Champenois
47  */

48 public final class ModuleNode extends AbstractNode implements Node.Cookie {
49     
50     /** Package-private for unit tests <strong>only</strong>. */
51     static final String JavaDoc MODULE_NODE_NAME = "module.node"; // NOI18N
52

53     private static Action JavaDoc[] 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     // Create the popup menu:
68
public Action JavaDoc[] getActions(boolean context) {
69         if (null == actions) {
70             actions = new Action JavaDoc[] {
71                 SystemAction.get(OpenModuleProjectAction.class),
72                 SystemAction.get(RemoveAction.class)
73             };
74             getCookieSet().add(this);
75         }
76         return actions;
77     }
78     
79     public Action JavaDoc getPreferredAction() {
80         return SystemAction.get(OpenModuleProjectAction.class);
81     }
82     
83     public Image JavaDoc getIcon(int type) {
84         // XXX the "algorithm" based on the ant property name - in the case of
85
// application client; is little odd. Also the rest is rather unclear.
86
if (key.toString().endsWith("war")) { // NOI18N
87
return Utilities.loadImage("org/netbeans/modules/j2ee/earproject/ui/resources/WebModuleNode.gif");//NOI18N
88
} else if (key.getRaw().indexOf("j2ee-module-car") > 0) { //NOI18N
89
return Utilities.loadImage("org/netbeans/modules/j2ee/earproject/ui/resources/CarModuleNodeIcon.gif");//NOI18N
90
} else {
91             return Utilities.loadImage("org/netbeans/modules/j2ee/earproject/ui/resources/EjbModuleNodeIcon.gif");//NOI18N
92
}
93     }
94     
95     public Image JavaDoc 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 JavaDoc<VisualClassPathItem> newList = new ArrayList JavaDoc<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     // Handle copying and cutting specially:
120
public boolean canCopy() {
121         return false;
122     }
123   
124 }
125
Popular Tags