KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > metainf > AddService


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.apisupport.project.metainf;
20
21 import java.lang.ref.WeakReference JavaDoc;
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 JavaDoc actionInstance;
30     
31     protected void performAction(Node[] activatedNodes) {
32         // TODO implement action body
33
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 JavaDoc[] { NotifyDescriptor.OK_OPTION, NotifyDescriptor.CANCEL_OPTION },
44                     null
45                 );
46                 Object JavaDoc res = DialogDisplayer.getDefault().notify(dd);
47                 
48                 if (res == NotifyDescriptor.OK_OPTION) {
49                     String JavaDoc 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 JavaDoc getName() {
63         return org.openide.util.NbBundle.getMessage(AddService.class, "MSG_Add_New_Service");
64     }
65
66     protected Class JavaDoc[] cookieClasses() {
67         return new Class JavaDoc[] {
68             ServiceNodeHandler.ServiceNode.class
69         };
70     }
71     
72     protected void initialize() {
73         super.initialize();
74         // see org.openide.util.actions.SystemAction.iconResource() javadoc for more details
75
putValue("noIconInMenu", Boolean.TRUE); // NOI18N
76
}
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 JavaDoc(action);
91         }
92         return action;
93     }
94
95 }
96
97
Popular Tags