KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > core > wseditor > support > WSEditAttributesAction


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.core.wseditor.support;
21
22 import java.util.Collection JavaDoc;
23 import java.util.Set JavaDoc;
24 import org.netbeans.modules.websvc.core.wseditor.spi.WSEditorProvider;
25 import org.netbeans.modules.websvc.core.wseditor.spi.WSEditorProviderRegistry;
26 import org.openide.nodes.Node;
27 import org.openide.util.HelpCtx;
28 import org.openide.util.Lookup;
29 import org.openide.util.NbBundle;
30 import org.openide.util.RequestProcessor;
31 import org.openide.util.actions.NodeAction;
32
33 public final class WSEditAttributesAction extends NodeAction {
34     
35     protected void performAction(Node[] activatedNodes) {
36         if (activatedNodes.length == 1) {
37             final EditWSAttributesCookie cookie = activatedNodes[0].getLookup().lookup(EditWSAttributesCookie.class);
38             if (cookie!=null) {
39                 Runnable JavaDoc task = new Runnable JavaDoc() {
40                     public void run() {
41                         cookie.openWSAttributesEditor();
42                     }
43                 };
44                 RequestProcessor.getDefault().post(task, 10);
45             }
46         }
47     }
48     
49     public String JavaDoc getName() {
50         return NbBundle.getMessage(WSEditAttributesAction.class, "CTL_WSEditAttributesAction");
51     }
52     
53     public HelpCtx getHelpCtx() {
54         return HelpCtx.DEFAULT_HELP;
55     }
56     
57     protected boolean asynchronous() {
58         return false;
59     }
60     
61     private WSEditorProviderRegistry populateWSEditorProviderRegistry(){
62         WSEditorProviderRegistry registry = WSEditorProviderRegistry.getDefault();
63         if(registry.getEditorProviders().isEmpty()){
64             Lookup.Result results = Lookup.getDefault().
65                     lookup(new Lookup.Template(WSEditorProvider.class));
66             Collection JavaDoc<WSEditorProvider> services = results.allInstances();
67             //System.out.println("###number of providers: " + services.size());
68
for(WSEditorProvider provider : services){
69                 registry.register(provider);
70             }
71         }
72         return registry;
73     }
74     
75     protected boolean enable(Node[] activatedNodes) {
76         
77         if(activatedNodes.length == 1){
78             WSEditorProviderRegistry registry =
79                     populateWSEditorProviderRegistry();
80             Set JavaDoc<WSEditorProvider> providers = registry.getEditorProviders();
81             if(providers.size() == 0){
82                 return false;
83             }
84             Node node = activatedNodes[0];
85             for(WSEditorProvider provider : providers){
86                 //look for the first one that is enabled and return true
87
if(provider.enable(node)){
88                     return true;
89                 }
90             }
91         }
92         return false;
93         
94     }
95 }
96
97
Popular Tags