KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > debug > watchesfiltering > JspWatchesActionsProvider


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.watchesfiltering;
21
22 import org.netbeans.spi.viewmodel.*;
23 import org.netbeans.api.debugger.DebuggerManager;
24 import org.netbeans.api.debugger.Watch;
25 import org.openide.util.NbBundle;
26 import org.openide.util.HelpCtx;
27 import org.openide.DialogDisplayer;
28
29 import javax.swing.*;
30 import java.awt.event.ActionEvent JavaDoc;
31 import java.awt.Dialog JavaDoc;
32 import java.util.*;
33
34 /**
35  * Provides actions for JspElWatch nodes.
36  *
37  * @author Maros Sandor
38  */

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