KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > debug > actions > AddJspWatchAction


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 package org.netbeans.modules.web.debug.actions;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Dialog JavaDoc;
24 import java.awt.Toolkit JavaDoc;
25 import java.awt.event.ActionEvent JavaDoc;
26 import java.lang.ref.WeakReference JavaDoc;
27 import java.util.LinkedList JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.ResourceBundle JavaDoc;
30 import javax.swing.AbstractAction JavaDoc;
31 import javax.swing.Action JavaDoc;
32 import javax.swing.JLabel JavaDoc;
33 import javax.swing.JPanel JavaDoc;
34 import javax.swing.JTextField JavaDoc;
35 import javax.swing.SwingUtilities JavaDoc;
36 import javax.swing.border.CompoundBorder JavaDoc;
37 import javax.swing.border.EmptyBorder JavaDoc;
38 import org.netbeans.api.debugger.DebuggerManager;
39 import org.netbeans.api.debugger.Watch;
40 import org.netbeans.modules.web.debug.util.Utils;
41
42 import org.openide.DialogDisplayer;
43 import org.openide.util.HelpCtx;
44 import org.openide.util.NbBundle;
45 import org.openide.util.actions.CallableSystemAction;
46
47
48 /**
49  * AddJspWatch action.
50  *
51  * @author Martin Grebac
52  */

53 public class AddJspWatchAction extends CallableSystemAction {
54
55     private static String JavaDoc watchHistory = ""; // NOI18N
56

57 // public AddWatchAction () {
58
// putValue (
59
// Action.NAME,
60
// NbBundle.getMessage (
61
// AddWatchAction.class,
62
// "CTL_New_Watch"
63
// )
64
// );
65
// putValue (
66
// Action.SMALL_ICON,
67
// Utils.getIcon (
68
// "org/netbeans/modules/debugger/resources/actions/NewWatch" // NOI18N
69
// )
70
// );
71
// }
72

73     protected boolean asynchronous () {
74         return false;
75     }
76
77     public String JavaDoc getName () {
78         return NbBundle.getMessage (
79             AddJspWatchAction.class, "CTL_New_Watch"
80         );
81     }
82     
83     public HelpCtx getHelpCtx () {
84         return new HelpCtx (AddJspWatchAction.class);
85
86     }
87
88     /** The action's icon location.
89     * @return the action's icon location
90     */

91     protected String JavaDoc iconResource () {
92         return "org/netbeans/modules/debugger/resources/actions/NewWatch.gif"; // NOI18N
93
}
94
95     
96     public void performAction () {
97         ResourceBundle JavaDoc bundle = NbBundle.getBundle (AddJspWatchAction.class);
98
99         JPanel JavaDoc panel = new JPanel JavaDoc();
100         panel.getAccessibleContext ().setAccessibleDescription (bundle.getString ("ACSD_WatchPanel")); // NOI18N
101
JTextField JavaDoc textField;
102         JLabel JavaDoc textLabel = new JLabel JavaDoc (bundle.getString ("CTL_Watch_Name")); // NOI18N
103
textLabel.setBorder (new EmptyBorder JavaDoc (0, 0, 0, 10));
104         panel.setLayout (new BorderLayout JavaDoc ());
105         panel.setBorder (new EmptyBorder JavaDoc (11, 12, 1, 11));
106         panel.add ("West", textLabel); // NOI18N
107
panel.add ("Center", textField = new JTextField JavaDoc (25)); // NOI18N
108
textField.getAccessibleContext ().setAccessibleDescription (bundle.getString ("ACSD_CTL_Watch_Name")); // NOI18N
109
textField.setBorder (
110             new CompoundBorder JavaDoc (textField.getBorder (),
111             new EmptyBorder JavaDoc (2, 0, 2, 0))
112         );
113         textLabel.setDisplayedMnemonic (
114             bundle.getString ("CTL_Watch_Name_Mnemonic").charAt (0) // NOI18N
115
);
116
117
118         String JavaDoc t = null;//Utils.getELIdentifier();
119
// Utils.getEM().log("Watch: ELIdentifier = " + t);
120

121         boolean isScriptlet = Utils.isScriptlet();
122         Utils.getEM().log("Watch: isScriptlet: " + isScriptlet);
123         
124         if ((t == null) && (isScriptlet)) {
125             t = Utils.getJavaIdentifier();
126             Utils.getEM().log("Watch: javaIdentifier = " + t);
127         }
128         
129         if (t != null) {
130             textField.setText(t);
131         } else {
132             textField.setText(watchHistory);
133         }
134         textField.selectAll ();
135         textLabel.setLabelFor (textField);
136         textField.requestFocus ();
137
138         org.openide.DialogDescriptor dd = new org.openide.DialogDescriptor (
139             panel,
140             bundle.getString ("CTL_Watch_Title") // NOI18N
141
);
142         dd.setHelpCtx (new HelpCtx ("debug.add.watch"));
143         Dialog JavaDoc dialog = DialogDisplayer.getDefault ().createDialog (dd);
144         dialog.setVisible(true);
145         dialog.dispose ();
146
147         if (dd.getValue() != org.openide.DialogDescriptor.OK_OPTION) return;
148         String JavaDoc watch = textField.getText();
149         if ((watch == null) || (watch.trim ().length () == 0)) {
150             return;
151         }
152         
153         String JavaDoc s = watch;
154         int i = s.indexOf (';');
155         while (i > 0) {
156             String JavaDoc ss = s.substring (0, i).trim ();
157             if (ss.length () > 0)
158                 DebuggerManager.getDebuggerManager ().createWatch (ss);
159             s = s.substring (i + 1);
160             i = s.indexOf (';');
161         }
162         s = s.trim ();
163         if (s.length () > 0)
164             DebuggerManager.getDebuggerManager ().createWatch (s);
165         
166         watchHistory = watch;
167         
168         // open watches view
169
// new WatchesAction ().actionPerformed (null); TODO
170
}
171 }
172
173 // // if EL expression
174
// if ((watch.startsWith("$")) && (watch.endsWith("}"))) {
175
// watch = org.openide.util.Utilities.replaceString(watch, "\"", "\\\"");
176
// watch = "pageContext.getExpressionEvaluator().evaluate(\"" + watch +
177
// "\", java.lang.String.class, (javax.servlet.jsp.PageContext)pageContext, null)";
178
// Utils.getEM().log("Watch: watch = " + watch);
179
// }
180
//
181
// w.setVariableName(watch);
182
// if (w instanceof JPDAWatch) {
183
// Utils.getEM().log("it is jpda watch");
184
// //((JPDAWatch)w).setDescription(var);
185
// }
186
Popular Tags