KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > scripting > php > dbginterface > 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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.scripting.php.dbginterface.models;
21
22 import java.awt.Dialog JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.util.ResourceBundle JavaDoc;
25 import javax.swing.AbstractAction JavaDoc;
26 import javax.swing.Action JavaDoc;
27 import javax.swing.JComponent JavaDoc;
28 import javax.swing.KeyStroke JavaDoc;
29 import org.netbeans.api.debugger.DebuggerManager;
30 import org.netbeans.modules.scripting.php.dbginterface.api.VariableNode;
31 import org.netbeans.modules.scripting.php.dbginterface.ui.WatchPanel;
32 import org.netbeans.spi.viewmodel.ModelListener;
33 import org.netbeans.spi.viewmodel.Models;
34 import org.netbeans.spi.viewmodel.NodeActionsProvider;
35 import org.netbeans.spi.viewmodel.TreeModel;
36 import org.netbeans.spi.viewmodel.UnknownTypeException;
37 import org.openide.DialogDisplayer;
38 import org.openide.util.HelpCtx;
39 import org.openide.util.NbBundle;
40
41
42 /**
43  * @author Jan Jancura
44  */

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