1 19 24 25 package org.netbeans.modules.j2ee.sun.ide.sunresources.resourceactions; 26 27 import java.text.MessageFormat ; 28 import javax.swing.SwingUtilities ; 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 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 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); }else{ 60 String message = MessageFormat.format(NbBundle.getMessage(RegisterAction.class, "Err_InvalidXML"), new Object []{nodes[0].getName()}); showError(message); 62 } 63 }catch(Exception 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 getName() { 80 return NbBundle.getMessage(RegisterAction.class, "LBL_RegisterAction"); } 82 83 protected String iconResource() { 84 return "org/netbeans/modules/j2ee/sun/ide/resources/AddInstanceActionIcon.gif"; } 86 87 public HelpCtx getHelpCtx() { 88 return null; } 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 msg){ 104 SwingUtilities.invokeLater(new Runnable () { 105 public void run() { 106 NotifyDescriptor d = new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE); 107 DialogDisplayer.getDefault().notify(d); 108 } 109 }); 110 } 111 118 119 } 120 | Popular Tags |