KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbcore > ui > logicalview > entres > CallEjbAction


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.ejbcore.ui.logicalview.entres;
21
22 import java.io.IOException JavaDoc;
23 import javax.lang.model.element.TypeElement;
24 import javax.swing.Action JavaDoc;
25 import org.netbeans.api.java.source.ElementHandle;
26 import org.netbeans.api.project.FileOwnerQuery;
27 import org.netbeans.api.project.Project;
28 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
29 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
30 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
31 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
32 import org.netbeans.modules.j2ee.ejbcore._RetoucheUtil;
33 import org.openide.ErrorManager;
34 import org.openide.filesystems.FileObject;
35 import org.openide.nodes.Node;
36 import org.openide.util.NbBundle;
37 import org.openide.util.HelpCtx;
38 import org.openide.util.Lookup;
39 import org.openide.util.actions.NodeAction;
40
41
42 /**
43  * Provide action for calling another EJB
44  * @author Chris Webster
45  * @author Martin Adamek
46  */

47 public class CallEjbAction extends NodeAction {
48     
49     protected void performAction(Node[] nodes) {
50         try {
51             ElementHandle<TypeElement> elementHandle = _RetoucheUtil.getJavaClassFromNode(nodes[0]);
52             FileObject fileObject = nodes[0].getLookup().lookup(FileObject.class);
53             CallEjbDialog callEjbDialog = new CallEjbDialog();
54             callEjbDialog.open(fileObject, elementHandle.getQualifiedName(), NbBundle.getMessage(CallEjbAction.class, "LBL_CallEjbAction")); //NOI18N
55
} catch (IOException JavaDoc ioe) {
56             ErrorManager.getDefault().notify(ioe);
57         }
58     }
59
60     public String JavaDoc getName() {
61         return NbBundle.getMessage(CallEjbAction.class, "LBL_CallEjbAction");
62     }
63     
64     public HelpCtx getHelpCtx() {
65         return HelpCtx.DEFAULT_HELP;
66         // If you will provide context help then use:
67
// return new HelpCtx(CallEjbAction.class);
68
}
69     
70     protected boolean asynchronous() {
71         return false;
72     }
73     
74     protected boolean enable(Node[] nodes) {
75         if (nodes == null || nodes.length != 1) {
76             return false;
77         }
78         ElementHandle<TypeElement> elementHandle = null;
79         try {
80             elementHandle = _RetoucheUtil.getJavaClassFromNode(nodes[0]);
81         } catch (IOException JavaDoc ioe) {
82             ErrorManager.getDefault().notify(ioe);
83             return false;
84         }
85         if (elementHandle == null) {
86             return false;
87         }
88         FileObject srcFile = nodes[0].getLookup().lookup(FileObject.class);
89         Project project = FileOwnerQuery.getOwner(srcFile);
90         J2eeModuleProvider j2eeModuleProvider = (J2eeModuleProvider) project.getLookup ().lookup (J2eeModuleProvider.class);
91         if (j2eeModuleProvider != null) {
92             String JavaDoc serverInstanceId = j2eeModuleProvider.getServerInstanceID();
93             if (serverInstanceId == null) {
94                 return true;
95             }
96             J2eePlatform platform = Deployment.getDefault().getJ2eePlatform(serverInstanceId);
97             if (platform == null) {
98                 return true;
99             }
100             if (!platform.getSupportedModuleTypes().contains(J2eeModule.EJB)) {
101                 return false;
102             }
103         }
104         try {
105             return !_RetoucheUtil.isInterface(srcFile, elementHandle);
106         } catch (IOException JavaDoc ioe) {
107             ErrorManager.getDefault().notify(ioe);
108         }
109         return false;
110     }
111     
112     /** Perform extra initialization of this action's singleton.
113      * PLEASE do not use constructors for this purpose!
114      * protected void initialize() {
115      * super.initialize();
116      * putProperty(Action.SHORT_DESCRIPTION, NbBundle.getMessage(CallEjbAction.class, "HINT_Action"));
117      * }
118      */

119
120     public Action JavaDoc createContextAwareInstance(Lookup actionContext) {
121         boolean enable = enable(actionContext.lookup(new Lookup.Template<Node>(Node.class)).allInstances().toArray(new Node[0]));
122         return enable ? this : null;
123     }
124     
125 }
126
Popular Tags