KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > j2ee > runtime > actions > ViewLogAction


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.j2ee.sun.ide.j2ee.runtime.actions;
20
21 import java.io.File JavaDoc;
22 import org.openide.nodes.Node;
23 import org.openide.util.HelpCtx;
24 import org.openide.util.NbBundle;
25 import org.openide.util.actions.CookieAction;
26
27 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
28
29 import org.netbeans.modules.j2ee.sun.ide.j2ee.LogViewerSupport;
30
31 import org.netbeans.modules.j2ee.sun.ide.j2ee.DeploymentManagerProperties;
32 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface;
33 import org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.nodes.ManagerNode;
34 import org.netbeans.modules.j2ee.sun.ide.j2ee.ui.Util;
35 import org.openide.windows.InputOutput;
36 /** Action to get the log viewer dialog to open
37  *
38  * @author ludo
39  */

40 public class ViewLogAction extends CookieAction {
41     
42     protected Class JavaDoc[] cookieClasses() {
43         return new Class JavaDoc[] {/* SourceCookie.class */};
44     }
45     
46     protected int mode() {
47         return MODE_EXACTLY_ONE;
48         // return MODE_ALL;
49
}
50     
51     protected void performAction(Node[] nodes) {
52         if(nodes[0].getLookup().lookup(ManagerNode.class) != null){
53             ManagerNode node = (ManagerNode)nodes[0].getCookie(ManagerNode.class);
54             SunDeploymentManagerInterface sdm = node.getDeploymentManager();
55             viewLog(sdm,true,true);//entire file and forced
56
}
57         
58         
59         
60     }
61     public static void viewLog(SunDeploymentManagerInterface sdm){
62             viewLog(sdm,false,false);//not the entire file and no forced refresh, just a front view
63

64     }
65     
66     public static InputOutput viewLog(SunDeploymentManagerInterface sdm, boolean entireFile, boolean forced){
67         try{
68             if(sdm.isLocal()==false){
69                 return null;
70             }
71             
72             DeploymentManagerProperties dmProps = new DeploymentManagerProperties((DeploymentManager JavaDoc) sdm);
73             String JavaDoc domainRoot = dmProps.getLocation();
74             if (domainRoot == null) {
75                 return null;
76             }
77             String JavaDoc domain = dmProps.getDomainName();
78             // XXX the dm props has the domain directory....
79
//File f = new File(installRoot+"/domains/"+domain+"/logs/server.log");
80
File JavaDoc f = new File JavaDoc(domainRoot+File.separator+domain+"/logs/server.log");
81             LogViewerSupport p = LogViewerSupport.getLogViewerSupport(f , dmProps.getUrl(),2000,entireFile);
82             return p.showLogViewer(forced);
83         } catch (Exception JavaDoc e){
84             Util.showInformation(e.getLocalizedMessage());
85         }
86         return null;
87     }
88     public String JavaDoc getName() {
89         return NbBundle.getMessage(ViewLogAction.class, "LBL_ViewlogAction");
90     }
91     
92     protected String JavaDoc iconResource() {
93         return "org/netbeans/modules/j2ee/sun/ide/resources/AddInstanceActionIcon.gif";
94     }
95     
96     public HelpCtx getHelpCtx() {
97         return null; // HelpCtx.DEFAULT_HELP;
98
// If you will provide context help then use:
99
// return new HelpCtx(RefreshAction.class);
100
}
101     
102     protected boolean enable(Node[] nodes) {
103         if( (nodes == null) || (nodes.length < 1) ) {
104             return false;
105         }
106         if (nodes.length > 1) {
107             return false;
108         }
109         if(nodes[0].getLookup().lookup(ManagerNode.class) != null){
110             try{
111                 ManagerNode node = (ManagerNode)nodes[0].getLookup().lookup(ManagerNode.class);
112                 
113                 
114                 SunDeploymentManagerInterface sdm = node.getDeploymentManager();
115                 return sdm.isLocal();
116             } catch (Exception JavaDoc e){
117                 //nothing to do, the NetBeasn node system is wierd sometimes...
118
}
119         }
120         return false;
121     }
122     
123     /** Perform special enablement check in addition to the normal one.
124      * protected boolean enable(Node[] nodes) {
125      * if (!super.enable(nodes)) return false;
126      * if (...) ...;
127      * }
128      */

129     
130     /** Perform extra initialization of this action's singleton.
131      * PLEASE do not use constructors for this purpose!
132      * protected void initialize() {
133      * super.initialize();
134      * putProperty(Action.SHORT_DESCRIPTION, NbBundle.getMessage(RefreshAction.class, "HINT_Action"));
135      * }
136      */

137     
138     protected boolean asynchronous() {
139         return false;
140     }
141     
142 }
143
Popular Tags