KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > ui > actions > AddWatchAction


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.debugger.ui.actions;
21
22 import java.awt.Dialog JavaDoc;
23 import java.util.ResourceBundle JavaDoc;
24 import javax.swing.*;
25 import org.netbeans.api.debugger.DebuggerManager;
26 import org.netbeans.modules.debugger.ui.WatchPanel;
27 import org.netbeans.modules.debugger.ui.views.View;
28
29 import org.openide.DialogDisplayer;
30 import org.openide.util.HelpCtx;
31 import org.openide.util.NbBundle;
32 import org.openide.util.actions.CallableSystemAction;
33
34
35 /**
36  * DebuggerManager Window action.
37  *
38  * @author Jan Jancura
39  */

40 public class AddWatchAction extends CallableSystemAction {
41
42     private static String JavaDoc watchHistory = ""; // NOI18N
43

44     
45 // public AddWatchAction () {
46
// putValue (
47
// Action.NAME,
48
// NbBundle.getMessage (
49
// AddWatchAction.class,
50
// "CTL_New_Watch"
51
// )
52
// );
53
// putValue (
54
// Action.SMALL_ICON,
55
// Utils.getIcon (
56
// "org/netbeans/modules/debugger/resources/actions/NewWatch" // NOI18N
57
// )
58
// );
59
// }
60

61     protected boolean asynchronous () {
62         return false;
63     }
64
65     public String JavaDoc getName () {
66         return NbBundle.getMessage (
67             AddWatchAction.class,
68             "CTL_New_Watch"
69         );
70     }
71     
72     public HelpCtx getHelpCtx () {
73         return new HelpCtx (AddWatchAction.class);
74
75     }
76
77     /** The action's icon location.
78     * @return the action's icon location
79     */

80     protected String JavaDoc iconResource () {
81         return "org/netbeans/modules/debugger/resources/actions/NewWatch.gif"; // NOI18N
82
}
83
84     
85     public void performAction () {
86         ResourceBundle JavaDoc bundle = NbBundle.getBundle (AddWatchAction.class);
87
88         WatchPanel wp = new WatchPanel (watchHistory);
89         JComponent panel = wp.getPanel ();
90
91         // <RAVE>
92
// Add help ID for 'Add Watch' dialog
93
// org.openide.DialogDescriptor dd = new org.openide.DialogDescriptor (
94
// panel,
95
// bundle.getString ("CTL_WatchDialog_Title") // NOI18N
96
// );
97
// ====
98
org.openide.DialogDescriptor dd = new org.openide.DialogDescriptor (
99             panel,
100             bundle.getString ("CTL_WatchDialog_Title"), // NOI18N
101
true,
102             org.openide.DialogDescriptor.OK_CANCEL_OPTION,
103             null,
104             org.openide.DialogDescriptor.DEFAULT_ALIGN,
105             new org.openide.util.HelpCtx("debug.add.watch"),
106             null
107         );
108         // </RAVE>
109
Dialog JavaDoc dialog = DialogDisplayer.getDefault ().createDialog (dd);
110         dialog.setVisible (true);
111         dialog.dispose ();
112
113         if (dd.getValue() != org.openide.DialogDescriptor.OK_OPTION) return;
114         String JavaDoc watch = wp.getExpression ();
115         if ( (watch == null) ||
116              (watch.trim ().length () == 0)
117         ) return;
118         
119         String JavaDoc s = watch;
120         int i = s.indexOf (';');
121         while (i > 0) {
122             String JavaDoc ss = s.substring (0, i).trim ();
123             if (ss.length () > 0)
124                 DebuggerManager.getDebuggerManager ().createWatch (ss);
125             s = s.substring (i + 1);
126             i = s.indexOf (';');
127         }
128         s = s.trim ();
129         if (s.length () > 0)
130             DebuggerManager.getDebuggerManager ().createWatch (s);
131         
132         watchHistory = watch;
133         
134         // open watches view
135
ViewActions.openComponent ("watchesView", false).requestVisible();
136     }
137 }
138
Popular Tags