KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > j2ee > runtime > 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.sun.ide.j2ee.runtime.actions;
21
22
23 import java.net.MalformedURLException JavaDoc;
24 import java.net.URL JavaDoc;
25 import java.util.MissingResourceException JavaDoc;
26 import org.openide.ErrorManager;
27 import org.openide.nodes.Node;
28 import org.openide.util.HelpCtx;
29 import org.openide.util.NbBundle;
30 import org.openide.util.actions.CookieAction;
31 import org.openide.awt.HtmlBrowser.URLDisplayer;
32
33 import org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.nodes.ManagerNode;
34 import org.netbeans.modules.j2ee.sun.ide.j2ee.ui.Util;
35
36 /** Action that can always be invoked and work procedurally.
37  * This action will display the URL for the given admin server node in the runtime explorer
38  * @author ludo
39  */

40 public class ShowAdminToolAction extends CookieAction {
41     
42     protected Class JavaDoc[] cookieClasses() {
43         return new Class JavaDoc[] {/* SourceCookie.class */};
44     }
45     
46     protected int mode() {
47         return MODE_EXACTLY_ONE;
48         // return MODE_ALL;
49
}
50     
51     protected void performAction(Node[] nodes) {
52         if( (nodes != null) && (nodes.length == 1) ) {
53             if(nodes[0].getLookup().lookup(ManagerNode.class) != null){
54                 ManagerNode node = (ManagerNode)nodes[0].getCookie(ManagerNode.class);
55                 try {
56                     if (node.getDeploymentManager().isRunning()) {
57                         URLDisplayer.getDefault().showURL(new URL JavaDoc(node.getAdminURL()));
58                     } else {
59                         Util.showInformation(
60                                 NbBundle.getMessage(ShowAdminToolAction.class,
61                                 "MESS_START_INSTANCE"));
62                     }
63                 } catch (MissingResourceException JavaDoc ex) {
64                     // this should not happen... If it does, we should find out.
65
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
66                             ex);
67                 } catch (MalformedURLException JavaDoc ex) {
68                     // this should not happen... If it does, we should find out.
69
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
70                             ex);
71                 } catch (Exception JavaDoc e){
72                     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
73                             e);
74                }
75             }
76         }
77     }
78     
79     
80     
81     
82     public String JavaDoc getName() {
83         return NbBundle.getMessage(ShowAdminToolAction.class, "LBL_ShowAdminGUIAction");
84     }
85     
86     protected String JavaDoc iconResource() {
87         return "org/netbeans/modules/j2ee/sun/ide/resources/AddInstanceActionIcon.gif";
88     }
89     
90     public HelpCtx getHelpCtx() {
91         return null; // HelpCtx.DEFAULT_HELP;
92
// If you will provide context help then use:
93
// return new HelpCtx(RefreshAction.class);
94
}
95     
96     protected boolean enable(Node[] nodes) {
97         return (nodes != null) && (nodes.length == 1); // true;
98
}
99     
100     protected boolean asynchronous() {
101         return false;
102     }
103     
104     
105 }
106
Popular Tags