~ubuntu-branches/ubuntu/trusty/netbeans/trusty

« back to all changes in this revision

Viewing changes to debuggercore/src/org/netbeans/modules/debugger/ui/models/WatchesActionsProvider.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
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]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
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.
 
29
 *
 
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.
 
40
 */
 
41
 
 
42
package org.netbeans.modules.debugger.ui.models;
 
43
 
 
44
import java.awt.Dialog;
 
45
import java.awt.event.ActionEvent;
 
46
import java.util.*;
 
47
import javax.swing.*;
 
48
import javax.swing.KeyStroke;
 
49
 
 
50
import org.netbeans.api.debugger.DebuggerManager;
 
51
 
 
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;
 
63
 
 
64
 
 
65
/**
 
66
 * @author   Jan Jancura
 
67
 */
 
68
public class WatchesActionsProvider implements NodeActionsProvider {
 
69
    
 
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);
 
74
            }
 
75
    };
 
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 ();
 
80
            }
 
81
    };
 
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) {
 
86
                return true;
 
87
            }
 
88
            public void perform (Object[] nodes) {
 
89
                int i, k = nodes.length;
 
90
                for (i = 0; i < k; i++)
 
91
                    ((Watch) nodes [i]).remove ();
 
92
            }
 
93
        },
 
94
        Models.MULTISELECTION_TYPE_ANY
 
95
    );
 
96
    static { 
 
97
        DELETE_ACTION.putValue (
 
98
            Action.ACCELERATOR_KEY,
 
99
            KeyStroke.getKeyStroke ("DELETE")
 
100
        );
 
101
    };
 
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) {
 
106
                return true;
 
107
            }
 
108
            public void perform (Object[] nodes) {
 
109
                customize ((Watch) nodes [0]);
 
110
            }
 
111
        },
 
112
        Models.MULTISELECTION_TYPE_EXACTLY_ONE
 
113
    );
 
114
    
 
115
    public Action[] getActions (Object node) throws UnknownTypeException {
 
116
        if (node == TreeModel.ROOT) 
 
117
            return new Action [] {
 
118
                NEW_WATCH_ACTION,
 
119
                null,
 
120
                DELETE_ALL_ACTION
 
121
            };
 
122
        if (node instanceof Watch)
 
123
            return new Action [] {
 
124
                NEW_WATCH_ACTION,
 
125
                null,
 
126
                DELETE_ACTION,
 
127
                DELETE_ALL_ACTION,
 
128
                null,
 
129
                CUSTOMIZE_ACTION
 
130
            };
 
131
        throw new UnknownTypeException (node);
 
132
    }
 
133
    
 
134
    public void performDefaultAction (Object node) throws UnknownTypeException {
 
135
        if (node == TreeModel.ROOT) 
 
136
            return;
 
137
        if (node instanceof Watch) {
 
138
            customize ((Watch) node);
 
139
            return;
 
140
        }
 
141
        throw new UnknownTypeException (node);
 
142
    }
 
143
 
 
144
    public void addModelListener (ModelListener l) {
 
145
    }
 
146
 
 
147
    public void removeModelListener (ModelListener l) {
 
148
    }
 
149
 
 
150
    private static void customize (Watch w) {
 
151
 
 
152
        WatchPanel wp = new WatchPanel(w.getExpression());
 
153
        JComponent panel = wp.getPanel();
 
154
 
 
155
        org.openide.DialogDescriptor dd = new org.openide.DialogDescriptor(
 
156
            panel,
 
157
            NbBundle.getMessage(WatchesActionsProvider.class, "CTL_WatchDialog_Title", // NOI18N 
 
158
                                           w.getExpression())
 
159
        );
 
160
        dd.setHelpCtx(new HelpCtx("debug.add.watch"));
 
161
        Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
 
162
        dialog.setVisible(true);
 
163
        dialog.dispose();
 
164
 
 
165
        if (dd.getValue() != org.openide.DialogDescriptor.OK_OPTION) return;
 
166
        w.setExpression(wp.getExpression());
 
167
    }
 
168
}