KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > avk > actions > GenerateReportAction


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.sun.ide.avk.actions;
20
21 import java.net.URL JavaDoc;
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.text.MessageFormat JavaDoc;
25 import java.util.ResourceBundle JavaDoc;
26
27 import org.openide.nodes.Node;
28 import org.openide.util.HelpCtx;
29 import org.openide.ErrorManager;
30 import org.openide.NotifyDescriptor;
31 import org.openide.awt.StatusDisplayer;
32 import org.openide.util.RequestProcessor;
33 import org.openide.util.actions.CookieAction;
34
35 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
36 import org.netbeans.modules.j2ee.sun.ide.j2ee.ui.Util;
37 import org.netbeans.modules.j2ee.sun.ide.j2ee.LogViewerSupport;
38 import org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.nodes.ManagerNode;
39 import org.netbeans.modules.j2ee.sun.ide.j2ee.DeploymentManagerProperties;
40 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface;
41
42 import org.openide.awt.HtmlBrowser.URLDisplayer;
43
44 import org.netbeans.modules.j2ee.sun.ide.avk.AVKSupport;
45
46 /**
47  *
48  * @author ludo
49  */

50 public class GenerateReportAction extends CookieAction {
51        
52     protected static final ResourceBundle JavaDoc bundle = ResourceBundle.getBundle("org.netbeans.modules.j2ee.sun.ide.avk.actions.Bundle");// NOI18N
53
private static RequestProcessor uninstrumentProc = new RequestProcessor("uninstrument"); //NOI18N
54

55     protected Class JavaDoc[] cookieClasses() {
56         return new Class JavaDoc[] {/* SourceCookie.class */};
57     }
58     
59     protected int mode() {
60         return MODE_EXACTLY_ONE;
61     }
62     
63     protected void performAction(Node[] nodes) {
64         if(nodes[0].getLookup().lookup(ManagerNode.class) != null){
65             try{
66                 ManagerNode node = (ManagerNode)nodes[0].getLookup().lookup(ManagerNode.class);
67                 SunDeploymentManagerInterface sdm = node.getDeploymentManager();
68                 final AVKSupport support = new AVKSupport(sdm);
69                 final DeploymentManagerProperties dmProps = new DeploymentManagerProperties((DeploymentManager JavaDoc) sdm);
70                 final SunDeploymentManagerInterface currentDm = sdm;
71                 uninstrumentProc.post(new Runnable JavaDoc() {
72                     public void run() {
73                         boolean generate = true;
74                         try{
75                             if(currentDm.isRunning()){
76                                 Object JavaDoc val = Util.showWarning(bundle.getString("Msg_StopServer")); //NOI18N
77
if(val == NotifyDescriptor.OK_OPTION){
78                                     StatusDisplayer.getDefault().setStatusText(bundle.getString("MSG_Stopping")); //NOI18N
79
support.stopServer(dmProps, currentDm);
80                                     support.setAVK(false);
81                                 }else{
82                                     generate=false;
83                                 }
84                             }else{
85                                 support.setAVK(false);
86                             }
87                         }catch(Exception JavaDoc ex){
88                             Util.showError(bundle.getString("Err_StopServer")); //NOI18N
89
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
90                             return;
91                         }
92                         if(generate){
93                             dmProps.setAVKOn(false);
94                             support.generateReport();
95                             dmProps.getInstanceProperties().refreshServerInstance();
96                         }
97                     }
98                 });
99             } catch (Exception JavaDoc e){
100                 //nothing to do, the NetBeasn node system is wierd sometimes...
101
}
102         }
103     }
104     
105     public String JavaDoc getName() {
106         return bundle.getString("LBL_Generate"); //NOI18N
107
}
108     
109     protected String JavaDoc iconResource() {
110         return "org/netbeans/modules/j2ee/sun/ide/resources/AddInstanceActionIcon.gif"; //NOI18N
111
}
112     
113     public HelpCtx getHelpCtx() {
114         return new HelpCtx("AVKGenerateReport");
115     }
116     
117     protected boolean enable(Node[] nodes) {
118         if( (nodes == null) || (nodes.length < 1) )
119              return false;
120
121         if(nodes[0].getLookup().lookup(ManagerNode.class) != null){
122              try{
123                  ManagerNode node = (ManagerNode)nodes[0].getLookup().lookup(ManagerNode.class);
124                  SunDeploymentManagerInterface sdm = node.getDeploymentManager();
125                  DeploymentManagerProperties dmProps = new DeploymentManagerProperties((DeploymentManager JavaDoc) sdm);
126                  return (sdm.isLocal() && dmProps.getAVKOn());
127              } catch (Exception JavaDoc e){
128                  //nothing to do, the NetBeasn node system is wierd sometimes...
129
}
130         }
131         return false;
132     }
133     
134     protected boolean asynchronous() {
135         return false;
136     }
137     
138 }
139
Popular Tags