KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > sunresources > resourceactions > RegisterAction


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  * RegisterAction.java
21  *
22  * Created on February 2, 2005, 12:01 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.ide.sunresources.resourceactions;
26
27 import java.text.MessageFormat JavaDoc;
28 import javax.swing.SwingUtilities JavaDoc;
29
30 import org.openide.nodes.Node;
31 import org.openide.util.HelpCtx;
32 import org.openide.util.NbBundle;
33 import org.openide.ErrorManager;
34 import org.openide.DialogDisplayer;
35 import org.openide.NotifyDescriptor;
36 import org.openide.util.actions.NodeAction;
37
38 import org.openide.loaders.DataObject;
39 import org.openide.filesystems.FileObject;
40 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
41
42 import org.netbeans.modules.j2ee.sun.sunresources.beans.WizardConstants;
43 import org.netbeans.modules.j2ee.sun.ide.sunresources.beans.ListServerInstances;
44 import org.netbeans.modules.j2ee.sun.ide.sunresources.beans.ResourceUtils;
45 import org.netbeans.modules.j2ee.sun.ide.sunresources.resourcesloader.SunResourceDataObject;
46 /**
47  *
48  * @author Nitya Doraisamy
49  */

50 public class RegisterAction extends NodeAction implements WizardConstants{
51
52     protected void performAction(Node[] nodes) {
53         try{
54             SunResourceDataObject dobj = (SunResourceDataObject)nodes[0].getCookie(SunResourceDataObject.class);
55             String JavaDoc resourceType = dobj.getResourceType();
56             if(resourceType != null){
57                 InstanceProperties target = getTargetServer(nodes[0]);
58                 new ListServerInstances(NbBundle.getMessage(RegisterAction.class, ("Reg_" + resourceType)), dobj, resourceType, target); //NOI18N
59
}else{
60                 String JavaDoc message = MessageFormat.format(NbBundle.getMessage(RegisterAction.class, "Err_InvalidXML"), new Object JavaDoc[]{nodes[0].getName()}); //NOI18N
61
showError(message);
62             }
63         }catch(Exception JavaDoc ex){
64             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
65         }
66     }
67     
68     protected boolean enable(Node[] nodes) {
69        if( (nodes != null) && (nodes.length == 1) )
70             return true;
71         else
72             return false;
73     }
74     
75     protected boolean asynchronous() {
76         return false;
77     }
78     
79     public String JavaDoc getName() {
80         return NbBundle.getMessage(RegisterAction.class, "LBL_RegisterAction"); //NOI18N
81
}
82     
83     protected String JavaDoc iconResource() {
84         return "org/netbeans/modules/j2ee/sun/ide/resources/AddInstanceActionIcon.gif"; //NOI18N
85
}
86     
87     public HelpCtx getHelpCtx() {
88         return null; // HelpCtx.DEFAULT_HELP;
89
// If you will provide context help then use:
90
// return new HelpCtx(RegisterAction.class);
91
}
92     
93     private InstanceProperties getTargetServer(Node node){
94         InstanceProperties serverName = null;
95         DataObject dob = (DataObject) node.getCookie(DataObject.class);
96         if(dob!=null){
97             FileObject fo = dob.getPrimaryFile();
98             serverName = ResourceUtils.getTargetServer(fo);
99         }
100         return serverName;
101     }
102     
103     public static void showError(final String JavaDoc msg){
104         SwingUtilities.invokeLater(new Runnable JavaDoc() {
105             public void run() {
106                 NotifyDescriptor d = new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE);
107                 DialogDisplayer.getDefault().notify(d);
108             }
109         });
110     }
111     /** Perform extra initialization of this action's singleton.
112      * PLEASE do not use constructors for this purpose!
113      * protected void initialize() {
114      * super.initialize();
115      * putProperty(Action.SHORT_DESCRIPTION, NbBundle.getMessage(RegisterAction.class, "HINT_Action"));
116      * }
117      */

118     
119 }
120
Popular Tags