KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > registry > actions > TestWebServiceMethodAction


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.websvc.registry.actions;
21
22 import org.netbeans.modules.websvc.api.registry.WebServiceMethod;
23 import org.openide.nodes.Node;
24 import org.openide.util.HelpCtx;
25 import org.openide.util.NbBundle;
26 import org.openide.util.actions.NodeAction;
27
28 import org.netbeans.modules.websvc.registry.nodes.*;
29 import org.netbeans.modules.websvc.registry.ui.TestWebServiceMethodDlg;
30 import org.netbeans.modules.websvc.registry.model.WebServiceData;
31 import org.netbeans.modules.websvc.registry.nodes.WebServicesCookie;
32
33 import com.sun.xml.rpc.processor.model.java.JavaMethod;
34
35 import javax.swing.SwingUtilities JavaDoc;
36
37
38 /**
39  *
40  * @author david
41  */

42 public class TestWebServiceMethodAction extends NodeAction {
43     
44     protected boolean enable(Node[] activatedNodes) {
45         // !PW this does not handle multiple selection (or rather, it does, but
46
// only acts on the first node, ignoring the remainder. See also performAction()
47
// which is written the same way.
48
if(activatedNodes != null && activatedNodes.length > 0 &&
49             activatedNodes[0].getCookie(WebServiceMethod.class) != null) {
50             return true;
51         } else {
52             return false;
53         }
54     }
55     
56     public boolean asynchronous() {
57         return false;
58     }
59     
60     public HelpCtx getHelpCtx() {
61         return HelpCtx.DEFAULT_HELP;
62     }
63     
64     public String JavaDoc getName() {
65         return NbBundle.getMessage(TestWebServiceMethodAction.class, "TEST_METHOD");
66     }
67     
68     protected void performAction(Node[] activatedNodes) {
69         if(null != activatedNodes && activatedNodes.length > 0) {
70             WebServiceMethod methodCookie = (WebServiceMethod) activatedNodes[0].getCookie(WebServiceMethod.class);
71             
72             // !PW The node logic below relies on the fact that the tree of filternodes
73
// is a continuous wrapper of the webservice node structure from the service
74
// node, downward.
75

76             /** First get the method name
77              */

78             String JavaDoc methodName = activatedNodes[0].getName();
79             final JavaMethod currentMethod = (JavaMethod)methodCookie.getJavaMethod();
80             
81             /** Now the parent node is a port node with the port information.
82              */

83             Node portNodeWrapper = activatedNodes[0].getParentNode();
84             final String JavaDoc portName = (String JavaDoc) portNodeWrapper.getName();
85             
86             /** The port node's parent is the web service node with the WebServiceData.
87              */

88             Node webServiceNodeWrapper = portNodeWrapper.getParentNode();
89             WebServicesCookie serviceCookie = (WebServicesCookie) webServiceNodeWrapper.getCookie(WebServicesCookie.class);
90             final WebServiceData wsData = serviceCookie.getWebServiceData();
91             
92             if(null != wsData) {
93                 SwingUtilities.invokeLater(new Runnable JavaDoc() {
94                     public void run() {
95                         TestWebServiceMethodDlg dlg = new TestWebServiceMethodDlg(wsData, currentMethod, portName);
96                         dlg.displayDialog();
97                     }
98                 });
99             }
100         }
101     }
102 }
103
Popular Tags