KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > oc4j > nodes > actions > ShowAdminToolAction


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.oc4j.nodes.actions;
21
22 import java.net.MalformedURLException JavaDoc;
23 import java.net.URL JavaDoc;
24 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
25 import org.netbeans.modules.j2ee.oc4j.nodes.OC4JInstanceNode;
26 import org.netbeans.modules.j2ee.oc4j.util.OC4JPluginProperties;
27 import org.openide.ErrorManager;
28 import org.openide.nodes.Node;
29 import org.openide.util.HelpCtx;
30 import org.openide.util.NbBundle;
31 import org.openide.util.actions.CookieAction;
32 import org.openide.awt.HtmlBrowser.URLDisplayer;
33
34 /**
35  * Action that can always be invoked and work procedurally.
36  * This action will display the URL for the given admin server node in the runtime explorer
37  */

38 public class ShowAdminToolAction extends CookieAction {
39     
40     protected Class JavaDoc[] cookieClasses() {
41         return new Class JavaDoc[] {/* SourceCookie.class */};
42     }
43     
44     protected int mode() {
45         return MODE_EXACTLY_ONE;
46         // return MODE_ALL;
47
}
48     
49     protected void performAction(Node[] nodes) {
50         if( (nodes == null) || (nodes.length < 1) )
51             return;
52         
53         for (int i = 0; i < nodes.length; i++) {
54             Object JavaDoc node = nodes[i].getLookup().lookup(OC4JInstanceNode.class);
55             if (node instanceof OC4JInstanceNode) {
56                 try {
57                     URL JavaDoc url = new URL JavaDoc(((OC4JInstanceNode) node).getAdminURL());
58                     URLDisplayer.getDefault().showURL(url);
59                 } catch (MalformedURLException JavaDoc ex) {
60                     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
61                 }
62             }
63         }
64     }
65     
66     public String JavaDoc getName() {
67         return NbBundle.getMessage(ShowAdminToolAction.class, "LBL_ShowAdminGUIAction");
68     }
69     
70     public HelpCtx getHelpCtx() {
71         return null; // HelpCtx.DEFAULT_HELP;
72
// If you will provide context help then use:
73
// return new HelpCtx(RefreshAction.class);
74
}
75     
76     protected boolean enable(Node[] nodes) {
77         for (Node node : nodes) {
78             OC4JInstanceNode iNode = node.getLookup().lookup(OC4JInstanceNode.class);
79             if(iNode != null) {
80                 InstanceProperties prop = iNode.getDeploymentManager().getInstanceProperties();
81                 String JavaDoc port = prop.getProperty(InstanceProperties.HTTP_PORT_NUMBER);
82                 String JavaDoc host = prop.getProperty(OC4JPluginProperties.PROPERTY_HOST);
83                 return OC4JPluginProperties.isRunning(host, port);
84             }
85         }
86         return false;
87     }
88     
89     protected boolean asynchronous() {
90         return false;
91     }
92 }
Popular Tags