KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > core > webservices > action > InvokeOperationAction


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.websvc.core.webservices.action;
20
21 import org.netbeans.modules.websvc.core.InvokeOperationCookie;
22 import org.netbeans.modules.websvc.core.WebServiceActionProvider;
23 import org.netbeans.modules.websvc.core.webservices.ui.panels.ClientExplorerPanel;
24 import org.openide.DialogDescriptor;
25 import org.openide.DialogDisplayer;
26 import org.openide.NotifyDescriptor;
27 import org.openide.cookies.EditorCookie;
28 import org.openide.filesystems.FileObject;
29 import org.openide.loaders.DataObject;
30 import org.openide.nodes.Node;
31
32 import org.openide.util.HelpCtx;
33 import org.openide.util.NbBundle;
34
35
36 import org.openide.util.actions.NodeAction;
37
38
39 /**
40  *
41  * @author Peter Williams
42  */

43 public class InvokeOperationAction extends NodeAction {
44     public String JavaDoc getName() {
45         return NbBundle.getMessage(InvokeOperationAction.class, "LBL_CallWebServiceOperation"); // NOI18N
46
}
47
48     public HelpCtx getHelpCtx() {
49         // If you will provide context help then use:
50
return HelpCtx.DEFAULT_HELP;
51     }
52
53     protected boolean asynchronous() {
54         return false;
55     }
56
57     protected boolean enable(Node[] activatedNodes) {
58         boolean result = false;
59         if (activatedNodes != null && activatedNodes.length == 1 && activatedNodes[0] != null) {
60             if (InvokeOperationCookie.TARGET_SOURCE_UNKNOWN != getTargetSourceType(activatedNodes[0]))
61                 return true;
62         }
63         return result;
64     }
65
66     protected void performAction(Node[] activatedNodes) {
67         if(activatedNodes != null && activatedNodes[0] != null) {
68             FileObject currentFO = getCurrentFileObject(activatedNodes[0]);
69             if(currentFO != null) {
70                 // !PW I wrote this code before I knew about NodeOperation. Anyway, this
71
// behaves a bit nicer in that the root node is hidden and the tree opens
72
// up expanded. Both improve usability for this use case I think.
73
ClientExplorerPanel serviceExplorer = new ClientExplorerPanel(currentFO);
74                 DialogDescriptor descriptor = new DialogDescriptor(serviceExplorer,
75                         NbBundle.getMessage(InvokeOperationAction.class,"TTL_SelectOperation"));
76                 serviceExplorer.setDescriptor(descriptor);
77                 // !PW FIXME put help context here when known to get a displayed help button on the panel.
78
// descriptor.setHelpCtx(new HelpCtx("HelpCtx_J2eePlatformInstallRootQuery"));
79
if(DialogDisplayer.getDefault().notify(descriptor).equals(NotifyDescriptor.OK_OPTION)) {
80                     // !PW FIXME refactor this as a method implemented in a cookie
81
// on the method node.
82
InvokeOperationCookie invokeCookie = WebServiceActionProvider.getInvokeOperationAction(currentFO);
83                     if (invokeCookie!=null)
84                         invokeCookie.invokeOperation(getTargetSourceType(activatedNodes[0]), activatedNodes[0], serviceExplorer.getSelectedMethod());
85                 }
86             }
87         }
88     }
89     
90     private FileObject getCurrentFileObject(Node n) {
91         FileObject result = null;
92         DataObject dobj = (DataObject) n.getCookie(DataObject.class);
93         if(dobj != null) {
94             result = dobj.getPrimaryFile();
95         }
96         return result;
97     }
98     
99     private int getTargetSourceType(Node node) {
100         EditorCookie cookie = (EditorCookie)node.getCookie(EditorCookie.class);
101         if (cookie!=null && "text/x-jsp".equals(cookie.getDocument().getProperty("mimeType"))) { //NOI18N
102
return InvokeOperationCookie.TARGET_SOURCE_JSP;
103         } else if (cookie!=null && "text/x-java".equals(cookie.getDocument().getProperty("mimeType"))) { //NOI18N
104
return InvokeOperationCookie.TARGET_SOURCE_JAVA;
105         }
106         return InvokeOperationCookie.TARGET_SOURCE_UNKNOWN;
107     }
108     
109 }
110
Popular Tags