KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.swing.Action JavaDoc;
22 import javax.swing.JMenu JavaDoc;
23 import javax.swing.JMenuItem JavaDoc;
24 import javax.swing.JPopupMenu JavaDoc;
25 import org.netbeans.modules.websvc.core.WebServiceActionProvider;
26 import org.openide.loaders.DataObject;
27 import org.openide.nodes.Node;
28 import org.openide.util.HelpCtx;
29 import org.openide.util.Lookup;
30 import org.openide.util.NbBundle;
31 import org.openide.util.actions.Presenter;
32 import org.openide.util.actions.NodeAction;
33 import org.openide.util.actions.SystemAction;
34
35
36 public class WebServiceActionGroup extends NodeAction implements Presenter.Popup
37 {
38     public String JavaDoc getName() {
39         return NbBundle.getMessage(WebServiceActionGroup.class, "LBL_WebServiceActionGroup");
40     }
41     
42     /** List of system actions to be displayed within this one's toolbar or submenu. */
43     private static final SystemAction[] grouped() {
44         return new SystemAction[] {
45             SystemAction.get(AddOperationEditorAction.class),
46         };
47     }
48     
49     public JMenuItem JavaDoc getPopupPresenter() {
50         Node[] activatedNodes = getActivatedNodes();
51         if (activatedNodes.length == 1 &&
52             hasWebService()){
53             return new LazyMenu();
54         }
55         JMenuItem JavaDoc i = super.getPopupPresenter();
56         i.setVisible(false);
57         return i;
58     }
59     
60     public HelpCtx getHelpCtx() {
61         return HelpCtx.DEFAULT_HELP;
62         // If you will provide context help then use:
63
// return new HelpCtx(PromoteBusinessMethodAction.class);
64
}
65     
66     protected boolean enable(org.openide.nodes.Node[] activatedNodes) {
67         return true;
68     }
69     
70     protected void performAction(org.openide.nodes.Node[] activatedNodes) {
71          assert false : "Should never be called: ";
72     }
73     
74     /**
75      * See if there is a webservices.xml. If this DD exists, it indicates
76      * that a web service exists in the project.
77      */

78     private boolean hasWebService() {
79         Node[] activatedNodes = getActivatedNodes();
80         DataObject dobj = (DataObject)activatedNodes[0].getLookup().lookup(DataObject.class);
81         if(dobj != null) {
82             /*
83             JAXWSSupport jaxWsSupport = JAXWSSupport.getJAXWSSupport(dobj.getPrimaryFile());
84             if (jaxWsSupport!=null && jaxWsSupport.getServices().size()>0) return true;
85             */

86             return (WebServiceActionProvider.getAddOperationAction(dobj.getPrimaryFile()) != null);
87             /*
88             WebServicesSupport wsSupport = WebServicesSupport.getWebServicesSupport(dobj.getPrimaryFile());
89             if(wsSupport != null) {
90                 return (wsSupport.getWebservicesDD() != null);
91             }*/

92         }
93         return false;
94     }
95
96     public Action JavaDoc createContextAwareInstance(Lookup actionContext) {
97         boolean enable = enable(actionContext.lookup(new Lookup.Template<Node>(Node.class)).allInstances().<Node>toArray(new Node[0]));
98         return enable ? this : null;
99     }
100     
101     /**
102      * Avoids constructing submenu until it will be needed.
103      */

104     private final class LazyMenu extends JMenu JavaDoc {
105         
106         public LazyMenu() {
107             super(WebServiceActionGroup.this.getName());
108         }
109         
110         public JPopupMenu JavaDoc getPopupMenu() {
111             if (getItemCount() == 0) {
112                 SystemAction[] grouped = grouped();
113                 for (int i = 0; i < grouped.length; i++) {
114                     SystemAction action = grouped[i];
115                     if (action == null) {
116                         addSeparator();
117                     } else if (action instanceof Presenter.Popup) {
118                         add(((Presenter.Popup)action).getPopupPresenter());
119                     } else {
120                         assert false : "Action had no popup presenter: " + action;
121                     }
122                 }
123             }
124             return super.getPopupMenu();
125         }
126  
127     }
128 }
129
Popular Tags