KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > ui > models > WatchesActionsProvider


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.jpda.ui.models;
21
22 import java.awt.Dialog JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.util.*;
25 import javax.swing.*;
26 import javax.swing.KeyStroke JavaDoc;
27 import org.netbeans.api.debugger.DebuggerManager;
28
29 import org.netbeans.api.debugger.jpda.JPDAWatch;
30 import org.netbeans.spi.viewmodel.Models;
31 import org.netbeans.spi.viewmodel.TreeModel;
32 import org.netbeans.spi.viewmodel.NodeActionsProvider;
33 import org.netbeans.spi.viewmodel.ModelListener;
34 import org.netbeans.spi.viewmodel.UnknownTypeException;
35 import org.netbeans.modules.debugger.jpda.ui.WatchPanel;
36 import org.openide.util.NbBundle;
37 import org.openide.util.HelpCtx;
38 import org.openide.DialogDisplayer;
39
40
41 /**
42  * @author Jan Jancura
43  */

44 public class WatchesActionsProvider implements NodeActionsProvider {
45     
46     
47     private static final Action NEW_WATCH_ACTION = new AbstractAction
48         (NbBundle.getBundle(WatchesActionsProvider.class).getString("CTL_WatchAction_AddNew")) {
49             public void actionPerformed (ActionEvent JavaDoc e) {
50                 newWatch ();
51             }
52     };
53     private static final Action DELETE_ALL_ACTION = new AbstractAction
54         (NbBundle.getBundle(WatchesActionsProvider.class).getString("CTL_WatchAction_DeleteAll")) {
55             public void actionPerformed (ActionEvent JavaDoc e) {
56                 DebuggerManager.getDebuggerManager ().removeAllWatches ();
57             }
58     };
59     private static final Action DELETE_ACTION = Models.createAction (
60         NbBundle.getBundle(WatchesActionsProvider.class).getString("CTL_WatchAction_Delete"),
61         new Models.ActionPerformer () {
62             public boolean isEnabled (Object JavaDoc node) {
63                 return true;
64             }
65             public void perform (Object JavaDoc[] nodes) {
66                 int i, k = nodes.length;
67                 for (i = 0; i < k; i++)
68                     ((JPDAWatch) nodes [i]).remove ();
69             }
70         },
71         Models.MULTISELECTION_TYPE_ANY
72     );
73     static {
74         DELETE_ACTION.putValue (
75             Action.ACCELERATOR_KEY,
76             KeyStroke.getKeyStroke ("DELETE")
77         );
78     };
79     private static final Action CUSTOMIZE_ACTION = Models.createAction (
80         NbBundle.getBundle(WatchesActionsProvider.class).getString("CTL_WatchAction_Customize"),
81         new Models.ActionPerformer () {
82             public boolean isEnabled (Object JavaDoc node) {
83                 return true;
84             }
85             public void perform (Object JavaDoc[] nodes) {
86                 customize ((JPDAWatch) nodes [0]);
87             }
88         },
89         Models.MULTISELECTION_TYPE_EXACTLY_ONE
90     );
91     
92     
93     public Action[] getActions (Object JavaDoc node) throws UnknownTypeException {
94         if (node == TreeModel.ROOT)
95             return new Action [] {
96                 NEW_WATCH_ACTION,
97                 null,
98                 DELETE_ALL_ACTION
99             };
100         if (node instanceof JPDAWatch)
101             return new Action [] {
102                 NEW_WATCH_ACTION,
103                 null,
104                 DELETE_ACTION,
105                 DELETE_ALL_ACTION,
106                 null,
107                 CUSTOMIZE_ACTION
108             };
109         throw new UnknownTypeException (node);
110     }
111     
112     public void performDefaultAction (Object JavaDoc node) throws UnknownTypeException {
113         if (node == TreeModel.ROOT)
114             return;
115         if (node instanceof JPDAWatch) {
116             return;
117         }
118         throw new UnknownTypeException (node);
119     }
120
121     public void addModelListener (ModelListener l) {
122     }
123
124     public void removeModelListener (ModelListener l) {
125     }
126
127     private static void customize (JPDAWatch w) {
128         WatchPanel wp = new WatchPanel (w.getExpression ());
129         JComponent panel = wp.getPanel ();
130
131         ResourceBundle bundle = NbBundle.getBundle (WatchesActionsProvider.class);
132         org.openide.DialogDescriptor dd = new org.openide.DialogDescriptor (
133             panel,
134             java.text.MessageFormat.format(bundle.getString("CTL_Edit_Watch_Dialog_Title"), // NOI18N
135
new Object JavaDoc [] { w.getExpression() })
136         );
137         dd.setHelpCtx (new HelpCtx ("debug.customize.watch"));
138         Dialog JavaDoc dialog = DialogDisplayer.getDefault ().createDialog (dd);
139         dialog.setVisible (true);
140         dialog.dispose ();
141
142         if (dd.getValue () != org.openide.DialogDescriptor.OK_OPTION) return;
143         if (panel.getClientProperty("WatchCanceled") != null) return ; //NOI18N
144
w.setExpression (wp.getExpression ());
145     }
146
147     private static void newWatch () {
148         WatchPanel wp = new WatchPanel ("");
149         JComponent panel = wp.getPanel ();
150
151         ResourceBundle bundle = NbBundle.getBundle (WatchesActionsProvider.class);
152         org.openide.DialogDescriptor dd = new org.openide.DialogDescriptor (
153             panel,
154             bundle.getString ("CTL_New_Watch_Dialog_Title") // NOI18N
155
);
156         dd.setHelpCtx (new HelpCtx ("debug.new.watch"));
157         Dialog JavaDoc dialog = DialogDisplayer.getDefault ().createDialog (dd);
158         dialog.setVisible (true);
159         dialog.dispose ();
160
161         if (dd.getValue () != org.openide.DialogDescriptor.OK_OPTION) return;
162         if (panel.getClientProperty("WatchCanceled") != null) return ; //NOI18N
163
DebuggerManager.getDebuggerManager ().createWatch (wp.getExpression ());
164     }
165 }
166
Popular Tags