1 19 package org.netbeans.modules.apisupport.project.metainf; 20 21 import java.lang.ref.WeakReference ; 22 import org.openide.DialogDisplayer; 23 import org.openide.NotifyDescriptor; 24 import org.openide.nodes.Node; 25 import org.openide.util.HelpCtx; 26 import org.openide.util.actions.CookieAction; 27 28 public final class AddService extends CookieAction { 29 private static WeakReference actionInstance; 30 31 protected void performAction(Node[] activatedNodes) { 32 if (activatedNodes.length > 0) { 34 ServiceNodeHandler.ServiceNode node = (ServiceNodeHandler.ServiceNode) activatedNodes[0].getLookup().lookup(ServiceNodeHandler.ServiceNode.class); 35 if ( node != null) { 36 AddServiceDialog panel = new AddServiceDialog(node.getProject()); 37 38 NotifyDescriptor dd = new NotifyDescriptor( 39 panel, 40 org.openide.util.NbBundle.getMessage(AddService.class, "LBL_Add_Service_Class"), 41 0, 42 NotifyDescriptor.PLAIN_MESSAGE, 43 new Object [] { NotifyDescriptor.OK_OPTION, NotifyDescriptor.CANCEL_OPTION }, 44 null 45 ); 46 Object res = DialogDisplayer.getDefault().notify(dd); 47 48 if (res == NotifyDescriptor.OK_OPTION) { 49 String classServiceName = panel.getClassName(); 50 if (classServiceName != null) { 51 node.addService(node.getName(),classServiceName); 52 } 53 } 54 } 55 } 56 } 57 58 protected int mode() { 59 return CookieAction.MODE_EXACTLY_ONE; 60 } 61 62 public String getName() { 63 return org.openide.util.NbBundle.getMessage(AddService.class, "MSG_Add_New_Service"); 64 } 65 66 protected Class [] cookieClasses() { 67 return new Class [] { 68 ServiceNodeHandler.ServiceNode.class 69 }; 70 } 71 72 protected void initialize() { 73 super.initialize(); 74 putValue("noIconInMenu", Boolean.TRUE); } 77 78 public HelpCtx getHelpCtx() { 79 return HelpCtx.DEFAULT_HELP; 80 } 81 82 protected boolean asynchronous() { 83 return false; 84 } 85 86 public static AddService getInstance() { 87 AddService action = (actionInstance != null ) ? (AddService)actionInstance.get() : null; 88 if (action == null) { 89 action = new AddService(); 90 actionInstance = new WeakReference (action); 91 } 92 return action; 93 } 94 95 } 96 97 | Popular Tags |