KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > 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.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
28 import org.netbeans.api.debugger.DebuggerManager;
29
30 import org.netbeans.api.debugger.Watch;
31 import org.netbeans.modules.debugger.ui.actions.AddWatchAction;
32 import org.netbeans.modules.debugger.ui.WatchPanel;
33 import org.netbeans.spi.viewmodel.Models;
34 import org.netbeans.spi.viewmodel.TreeModel;
35 import org.netbeans.spi.viewmodel.NodeActionsProvider;
36 import org.netbeans.spi.viewmodel.ModelListener;
37 import org.netbeans.spi.viewmodel.UnknownTypeException;
38 import org.openide.DialogDisplayer;
39 import org.openide.util.NbBundle;
40 import org.openide.util.HelpCtx;
41
42
43 /**
44  * @author Jan Jancura
45  */

46 public class WatchesActionsProvider implements NodeActionsProvider {
47     
48     private static final Action NEW_WATCH_ACTION = new AbstractAction
49         (NbBundle.getBundle(WatchesActionsProvider.class).getString("CTL_WatchAction_AddNew")) {
50             public void actionPerformed (ActionEvent JavaDoc e) {
51                 ((AddWatchAction) AddWatchAction.findObject(AddWatchAction.class, true)).actionPerformed(null);
52             }
53     };
54     private static final Action DELETE_ALL_ACTION = new AbstractAction
55         (NbBundle.getBundle(WatchesActionsProvider.class).getString("CTL_WatchAction_DeleteAll")) {
56             public void actionPerformed (ActionEvent JavaDoc e) {
57                 DebuggerManager.getDebuggerManager ().removeAllWatches ();
58             }
59     };
60     private static final Action DELETE_ACTION = Models.createAction (
61         NbBundle.getBundle(WatchesActionsProvider.class).getString("CTL_WatchAction_Delete"),
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                     ((Watch) nodes [i]).remove ();
70             }
71         },
72         Models.MULTISELECTION_TYPE_ANY
73     );
74     static {
75         DELETE_ACTION.putValue (
76             Action.ACCELERATOR_KEY,
77             KeyStroke.getKeyStroke ("DELETE")
78         );
79     };
80     private static final Action CUSTOMIZE_ACTION = Models.createAction (
81         NbBundle.getBundle(WatchesActionsProvider.class).getString("CTL_WatchAction_Customize"),
82         new Models.ActionPerformer () {
83             public boolean isEnabled (Object JavaDoc node) {
84                 return true;
85             }
86             public void perform (Object JavaDoc[] nodes) {
87                 customize ((Watch) nodes [0]);
88             }
89         },
90         Models.MULTISELECTION_TYPE_EXACTLY_ONE
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 Watch)
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 Watch) {
116             customize ((Watch) node);
117             return;
118         }
119         throw new UnknownTypeException (node);
120     }
121
122     public void addModelListener (ModelListener l) {
123     }
124
125     public void removeModelListener (ModelListener l) {
126     }
127
128     private static void customize (Watch w) {
129
130         WatchPanel wp = new WatchPanel(w.getExpression());
131         JComponent panel = wp.getPanel();
132
133         org.openide.DialogDescriptor dd = new org.openide.DialogDescriptor(
134             panel,
135             NbBundle.getMessage(WatchesActionsProvider.class, "CTL_WatchDialog_Title", // NOI18N
136
w.getExpression())
137         );
138         dd.setHelpCtx(new HelpCtx("debug.add.watch"));
139         Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog(dd);
140         dialog.setVisible(true);
141         dialog.dispose();
142
143         if (dd.getValue() != org.openide.DialogDescriptor.OK_OPTION) return;
144         w.setExpression(wp.getExpression());
145     }
146 }
147
Popular Tags