KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > deployment > impl > ui > actions > ProfileAction


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
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 /**
38  * Profile server action starts the server in the profile mode.
39  *
40  * @author sherold
41  */

42 public class ProfileAction extends NodeAction {
43     
44     public String JavaDoc 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     // private helper methods -------------------------------------------------
65

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 JavaDoc() {
81                 public void run() {
82                     String JavaDoc 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 JavaDoc 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