2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.debugger.ui.models;
44
import java.awt.Dialog;
45
import java.awt.event.ActionEvent;
48
import javax.swing.KeyStroke;
50
import org.netbeans.api.debugger.DebuggerManager;
52
import org.netbeans.api.debugger.Watch;
53
import org.netbeans.modules.debugger.ui.actions.AddWatchAction;
54
import org.netbeans.modules.debugger.ui.WatchPanel;
55
import org.netbeans.spi.viewmodel.Models;
56
import org.netbeans.spi.viewmodel.TreeModel;
57
import org.netbeans.spi.viewmodel.NodeActionsProvider;
58
import org.netbeans.spi.viewmodel.ModelListener;
59
import org.netbeans.spi.viewmodel.UnknownTypeException;
60
import org.openide.DialogDisplayer;
61
import org.openide.util.NbBundle;
62
import org.openide.util.HelpCtx;
68
public class WatchesActionsProvider implements NodeActionsProvider {
70
private static final Action NEW_WATCH_ACTION = new AbstractAction
71
(NbBundle.getBundle(WatchesActionsProvider.class).getString("CTL_WatchAction_AddNew")) {
72
public void actionPerformed (ActionEvent e) {
73
((AddWatchAction) AddWatchAction.findObject(AddWatchAction.class, true)).actionPerformed(null);
76
private static final Action DELETE_ALL_ACTION = new AbstractAction
77
(NbBundle.getBundle(WatchesActionsProvider.class).getString("CTL_WatchAction_DeleteAll")) {
78
public void actionPerformed (ActionEvent e) {
79
DebuggerManager.getDebuggerManager ().removeAllWatches ();
82
private static final Action DELETE_ACTION = Models.createAction (
83
NbBundle.getBundle(WatchesActionsProvider.class).getString("CTL_WatchAction_Delete"),
84
new Models.ActionPerformer () {
85
public boolean isEnabled (Object node) {
88
public void perform (Object[] nodes) {
89
int i, k = nodes.length;
90
for (i = 0; i < k; i++)
91
((Watch) nodes [i]).remove ();
94
Models.MULTISELECTION_TYPE_ANY
97
DELETE_ACTION.putValue (
98
Action.ACCELERATOR_KEY,
99
KeyStroke.getKeyStroke ("DELETE")
102
private static final Action CUSTOMIZE_ACTION = Models.createAction (
103
NbBundle.getBundle(WatchesActionsProvider.class).getString("CTL_WatchAction_Customize"),
104
new Models.ActionPerformer () {
105
public boolean isEnabled (Object node) {
108
public void perform (Object[] nodes) {
109
customize ((Watch) nodes [0]);
112
Models.MULTISELECTION_TYPE_EXACTLY_ONE
115
public Action[] getActions (Object node) throws UnknownTypeException {
116
if (node == TreeModel.ROOT)
117
return new Action [] {
122
if (node instanceof Watch)
123
return new Action [] {
131
throw new UnknownTypeException (node);
134
public void performDefaultAction (Object node) throws UnknownTypeException {
135
if (node == TreeModel.ROOT)
137
if (node instanceof Watch) {
138
customize ((Watch) node);
141
throw new UnknownTypeException (node);
144
public void addModelListener (ModelListener l) {
147
public void removeModelListener (ModelListener l) {
150
private static void customize (Watch w) {
152
WatchPanel wp = new WatchPanel(w.getExpression());
153
JComponent panel = wp.getPanel();
155
org.openide.DialogDescriptor dd = new org.openide.DialogDescriptor(
157
NbBundle.getMessage(WatchesActionsProvider.class, "CTL_WatchDialog_Title", // NOI18N
160
dd.setHelpCtx(new HelpCtx("debug.add.watch"));
161
Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
162
dialog.setVisible(true);
165
if (dd.getValue() != org.openide.DialogDescriptor.OK_OPTION) return;
166
w.setExpression(wp.getExpression());