1 19 20 package org.netbeans.modules.websvc.core.wseditor.support; 21 22 import java.util.Collection ; 23 import java.util.Set ; 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 task = new Runnable () { 40 public void run() { 41 cookie.openWSAttributesEditor(); 42 } 43 }; 44 RequestProcessor.getDefault().post(task, 10); 45 } 46 } 47 } 48 49 public String 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 <WSEditorProvider> services = results.allInstances(); 67 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 <WSEditorProvider> providers = registry.getEditorProviders(); 81 if(providers.size() == 0){ 82 return false; 83 } 84 Node node = activatedNodes[0]; 85 for(WSEditorProvider provider : providers){ 86 if(provider.enable(node)){ 88 return true; 89 } 90 } 91 } 92 return false; 93 94 } 95 } 96 97 | Popular Tags |