1 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 43 public class InvokeOperationAction extends NodeAction { 44 public String getName() { 45 return NbBundle.getMessage(InvokeOperationAction.class, "LBL_CallWebServiceOperation"); } 47 48 public HelpCtx getHelpCtx() { 49 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 ClientExplorerPanel serviceExplorer = new ClientExplorerPanel(currentFO); 74 DialogDescriptor descriptor = new DialogDescriptor(serviceExplorer, 75 NbBundle.getMessage(InvokeOperationAction.class,"TTL_SelectOperation")); 76 serviceExplorer.setDescriptor(descriptor); 77 if(DialogDisplayer.getDefault().notify(descriptor).equals(NotifyDescriptor.OK_OPTION)) { 80 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"))) { return InvokeOperationCookie.TARGET_SOURCE_JSP; 103 } else if (cookie!=null && "text/x-java".equals(cookie.getDocument().getProperty("mimeType"))) { return InvokeOperationCookie.TARGET_SOURCE_JAVA; 105 } 106 return InvokeOperationCookie.TARGET_SOURCE_UNKNOWN; 107 } 108 109 } 110 | Popular Tags |