KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.File JavaDoc;
22 import java.util.ResourceBundle JavaDoc;
23
24 import org.openide.nodes.Node;
25 import org.openide.util.HelpCtx;
26 import org.openide.util.RequestProcessor;
27 import org.openide.util.actions.CookieAction;
28
29 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
30
31 import org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.nodes.ManagerNode;
32 import org.netbeans.modules.j2ee.sun.ide.j2ee.DeploymentManagerProperties;
33 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface;
34
35 import org.netbeans.modules.j2ee.sun.ide.avk.AVKSupport;
36
37 /**
38  *
39  * @author ludo
40  */

41 public class InstrumentAVKAction extends CookieAction {
42     boolean instrumented = false;
43     protected static final ResourceBundle JavaDoc bundle = ResourceBundle.getBundle("org.netbeans.modules.j2ee.sun.ide.avk.actions.Bundle");// NOI18N
44
private RequestProcessor processor = new RequestProcessor("instrument"); //NOI18N
45
protected Class JavaDoc[] cookieClasses() {
46         return new Class JavaDoc[] {/* SourceCookie.class */};
47     }
48     
49     protected int mode() {
50         return MODE_EXACTLY_ONE;
51     }
52     
53     protected void performAction(Node[] nodes) {
54         if(nodes[0].getLookup().lookup(ManagerNode.class) != null){
55             try{
56                 final ManagerNode node = (ManagerNode)nodes[0].getLookup().lookup(ManagerNode.class);
57                 processor.post(new Runnable JavaDoc() {
58                     public void run() {
59                         SunDeploymentManagerInterface sdm = node.getDeploymentManager();
60                         AVKSupport support = new AVKSupport(sdm);
61                         support.setAVK(true);
62                     }
63                 });
64             } catch (Exception JavaDoc e){
65                 //nothing to do, the NetBeasn node system is wierd sometimes...
66
}
67         }
68     }
69     
70     public String JavaDoc getName() {
71         return bundle.getString("LBL_Instrument"); //NOI18N
72
}
73     
74     protected String JavaDoc iconResource() {
75         return "org/netbeans/modules/j2ee/sun/ide/resources/AddInstanceActionIcon.gif"; //NOI18N
76
}
77     
78     public HelpCtx getHelpCtx() {
79         return null;
80     }
81     
82     protected boolean enable(Node[] nodes) {
83         if( (nodes == null) || (nodes.length < 1) )
84              return false;
85
86         if(nodes[0].getLookup().lookup(ManagerNode.class) != null){
87              try{
88                  ManagerNode node = (ManagerNode)nodes[0].getLookup().lookup(ManagerNode.class);
89                  SunDeploymentManagerInterface sdm = node.getDeploymentManager();
90                  DeploymentManagerProperties dmProps = new DeploymentManagerProperties((DeploymentManager JavaDoc) sdm);
91                  instrumented = dmProps.getAVKOn();
92                  return (sdm.isLocal() && !instrumented);
93              } catch (Exception JavaDoc e){
94                  //nothing to do, the NetBeasn node system is wierd sometimes...
95
}
96         }
97         return false;
98     }
99     
100     protected boolean asynchronous() {
101         return false;
102     }
103 }
104
Popular Tags