1 19 20 21 package org.netbeans.modules.j2ee.deployment.impl.ui.actions; 22 23 import org.netbeans.modules.j2ee.deployment.impl.ServerException; 24 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance; 25 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; 26 import org.netbeans.modules.j2ee.deployment.impl.ui.ProgressUI; 27 import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings; 28 import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler; 29 import org.openide.DialogDisplayer; 30 import org.openide.NotifyDescriptor; 31 import org.openide.nodes.Node; 32 import org.openide.util.HelpCtx; 33 import org.openide.util.NbBundle; 34 import org.openide.util.RequestProcessor; 35 import org.openide.util.actions.NodeAction; 36 37 42 public class ProfileAction extends NodeAction { 43 44 public String getName() { 45 return NbBundle.getMessage(DebugAction.class, "LBL_Profile"); 46 } 47 48 protected void performAction(Node[] nodes) { 49 performActionImpl(nodes); 50 } 51 52 protected boolean enable(Node[] nodes) { 53 return enableImpl(nodes); 54 } 55 56 public HelpCtx getHelpCtx() { 57 return HelpCtx.DEFAULT_HELP; 58 } 59 60 protected boolean asynchronous() { 61 return false; 62 } 63 64 66 private static void performActionImpl(Node[] nodes) { 67 if (nodes.length != 1) { 68 return; 69 } 70 final ServerInstance si = (ServerInstance)nodes[0].getCookie(ServerInstance.class); 71 if (si != null) { 72 Profiler profiler = ServerRegistry.getProfiler(); 73 if (profiler == null) { 74 return; 75 } 76 final ProfilerServerSettings settings = profiler.getSettings(si.getUrl()); 77 if (settings == null) { 78 return; 79 } 80 RequestProcessor.getDefault().post(new Runnable () { 81 public void run() { 82 String title = NbBundle.getMessage(DebugAction.class, "LBL_Profiling", si.getDisplayName()); 83 ProgressUI progressUI = new ProgressUI(title, false); 84 try { 85 progressUI.start(); 86 si.startProfile(settings, false, progressUI); 87 } catch (ServerException ex) { 88 String msg = ex.getLocalizedMessage(); 89 NotifyDescriptor desc = new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE); 90 DialogDisplayer.getDefault().notify(desc); 91 } finally { 92 progressUI.finish(); 93 } 94 } 95 }); 96 } 97 } 98 99 private static boolean enableImpl(Node[] nodes) { 100 if (nodes.length != 1) { 101 return false; 102 } 103 ServerInstance si = (ServerInstance)nodes[0].getCookie(ServerInstance.class); 104 if (si == null || si.getServerState() != ServerInstance.STATE_STOPPED 105 || !si.isProfileSupported()) { 106 return false; 107 } 108 return true; 109 } 110 } 111 | Popular Tags |