KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > jboss4 > nodes > JBWebModuleNode


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.jboss4.nodes;
21
22 import java.awt.Image JavaDoc;
23 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
24 import javax.swing.Action JavaDoc;
25 import org.netbeans.modules.j2ee.deployment.plugins.api.UISupport;
26 import org.netbeans.modules.j2ee.deployment.plugins.api.UISupport.ServerIcon;
27 import org.netbeans.modules.j2ee.jboss4.JBDeploymentManager;
28 import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginUtils;
29 import org.netbeans.modules.j2ee.jboss4.nodes.actions.OpenURLAction;
30 import org.netbeans.modules.j2ee.jboss4.nodes.actions.OpenURLActionCookie;
31 import org.netbeans.modules.j2ee.jboss4.nodes.actions.UndeployModuleAction;
32 import org.netbeans.modules.j2ee.jboss4.nodes.actions.UndeployModuleCookieImpl;
33 import org.openide.nodes.AbstractNode;
34 import org.openide.util.Lookup;
35 import org.openide.util.actions.SystemAction;
36
37 /**
38  * Node which describes Web Module.
39  *
40  * @author Michal Mocnak
41  */

42 public class JBWebModuleNode extends AbstractNode {
43
44     final boolean isRemoteManagementSupported;
45     final boolean isJB4x;
46
47     public JBWebModuleNode(String JavaDoc fileName, Lookup lookup, String JavaDoc url) {
48         super(new JBServletsChildren(fileName, lookup));
49         setDisplayName(fileName.substring(0, fileName.indexOf('.')));
50         isRemoteManagementSupported = Util.isRemoteManagementSupported(lookup);
51         isJB4x = JBPluginUtils.isGoodJBServerLocation4x((JBDeploymentManager)lookup.lookup(JBDeploymentManager.class));
52         if (isRemoteManagementSupported && isJB4x) {
53             // we cannot find out the .war name w/o the management support, thus we cannot enable the Undeploy action
54
getCookieSet().add(new UndeployModuleCookieImpl(fileName, ModuleType.WAR, lookup));
55         }
56         
57         if(url != null)
58             getCookieSet().add(new OpenURLActionCookieImpl(url));
59     }
60     
61     public Action JavaDoc[] getActions(boolean context){
62         if (getParentNode() instanceof JBEarApplicationNode) {
63             return new SystemAction[] {
64                 SystemAction.get(OpenURLAction.class)
65             };
66         }
67         else {
68             if (isRemoteManagementSupported && isJB4x) {
69                 return new SystemAction[] {
70                     SystemAction.get(OpenURLAction.class),
71                     SystemAction.get(UndeployModuleAction.class)
72                 };
73             }
74             else {
75                 // we cannot find out the .war name w/o the management support, thus we cannot enable the Undeploy action
76
return new SystemAction[] {
77                     SystemAction.get(OpenURLAction.class),
78                 };
79             }
80         }
81     }
82     
83     public Image JavaDoc getIcon(int type) {
84         return UISupport.getIcon(ServerIcon.WAR_ARCHIVE);
85     }
86
87     public Image JavaDoc getOpenedIcon(int type) {
88         return getIcon(type);
89     }
90     
91     private static class OpenURLActionCookieImpl implements OpenURLActionCookie {
92         
93         private String JavaDoc url;
94         
95         public OpenURLActionCookieImpl(String JavaDoc url) {
96             this.url = url;
97         }
98         
99         public String JavaDoc getWebURL() {
100             return url;
101         }
102     }
103 }
104
Popular Tags