KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > websphere6 > ui > nodes > actions > ShowAdminConsoleAction


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 package org.netbeans.modules.j2ee.websphere6.ui.nodes.actions;
20
21 import java.io.IOException JavaDoc;
22 import java.net.Socket JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.net.UnknownHostException JavaDoc;
25 import org.netbeans.modules.j2ee.websphere6.WSDeploymentManager;
26 import org.netbeans.modules.j2ee.websphere6.ui.nodes.WSManagerNode;
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  *
36  * @author Kirill Sorokin
37  */

38 public class ShowAdminConsoleAction extends CookieAction {
39     protected void performAction(Node[] nodes) {
40         if( (nodes == null) || (nodes.length < 1)) {
41             return;
42         }
43         
44         for (int i = 0; i < nodes.length; i++) {
45             Object JavaDoc node = nodes[i].getLookup().lookup(WSManagerNode.class);
46             if (node instanceof WSManagerNode) {
47                 try{
48                     URL JavaDoc url = new URL JavaDoc(
49                             ((WSManagerNode) node).getAdminConsoleURL());
50                     
51                     URLDisplayer.getDefault().showURL(url);
52                 } catch (Exception JavaDoc e){
53                     return;//nothing much to do
54
}
55             }
56         }
57     }
58     
59     public String JavaDoc getName() {
60         return NbBundle.getMessage(ShowAdminConsoleAction.class, "LBL_ShowAdminConsole");
61     }
62     
63     protected int mode() {
64         return MODE_EXACTLY_ONE;
65     }
66     
67     public HelpCtx getHelpCtx() {
68         return null;
69     }
70     
71     protected Class JavaDoc[] cookieClasses() {
72         return new Class JavaDoc[]{};
73     }
74     
75     protected boolean enable(Node[] nodes) {
76         if (nodes == null || nodes.length < 1) {
77             return false;
78         }
79         
80         boolean running = true;
81         
82         for (int i = 0; i < nodes.length; i++) {
83             Object JavaDoc node = nodes[i].getLookup().lookup(WSManagerNode.class);
84             if (!(node instanceof WSManagerNode)) {
85                 running = false;
86                 break;
87             }
88             
89             WSDeploymentManager dm =
90                     ((WSManagerNode) node).getDeploymentManager();
91             
92             // try to get an open socket to the target host/port
93
try {
94                 new Socket JavaDoc(dm.getHost(), new Integer JavaDoc(dm.getPort()).intValue());
95                 
96                 running = true;
97             } catch (UnknownHostException JavaDoc e) {
98                 ErrorManager.getDefault().notify(ErrorManager.ERROR, e);
99             } catch (IOException JavaDoc e) {
100                 running = false;
101             }
102         }
103         
104         return running;
105     }
106     
107     protected boolean asynchronous() {
108         return false;
109     }
110 }
Popular Tags