001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.debugger.ui.models;
043:
044: import java.awt.Dialog;
045: import java.awt.event.ActionEvent;
046: import java.util.*;
047: import javax.swing.*;
048: import javax.swing.KeyStroke;
049:
050: import org.netbeans.api.debugger.DebuggerManager;
051:
052: import org.netbeans.api.debugger.Watch;
053: import org.netbeans.modules.debugger.ui.actions.AddWatchAction;
054: import org.netbeans.modules.debugger.ui.WatchPanel;
055: import org.netbeans.spi.viewmodel.Models;
056: import org.netbeans.spi.viewmodel.TreeModel;
057: import org.netbeans.spi.viewmodel.NodeActionsProvider;
058: import org.netbeans.spi.viewmodel.ModelListener;
059: import org.netbeans.spi.viewmodel.UnknownTypeException;
060: import org.openide.DialogDisplayer;
061: import org.openide.util.NbBundle;
062: import org.openide.util.HelpCtx;
063:
064: /**
065: * @author Jan Jancura
066: */
067: public class WatchesActionsProvider implements NodeActionsProvider {
068:
069: private static final Action NEW_WATCH_ACTION = new AbstractAction(
070: NbBundle.getBundle(WatchesActionsProvider.class).getString(
071: "CTL_WatchAction_AddNew")) {
072: public void actionPerformed(ActionEvent e) {
073: ((AddWatchAction) AddWatchAction.findObject(
074: AddWatchAction.class, true)).actionPerformed(null);
075: }
076: };
077: private static final Action DELETE_ALL_ACTION = new AbstractAction(
078: NbBundle.getBundle(WatchesActionsProvider.class).getString(
079: "CTL_WatchAction_DeleteAll")) {
080: public void actionPerformed(ActionEvent e) {
081: DebuggerManager.getDebuggerManager().removeAllWatches();
082: }
083: };
084: private static final Action DELETE_ACTION = Models.createAction(
085: NbBundle.getBundle(WatchesActionsProvider.class).getString(
086: "CTL_WatchAction_Delete"),
087: new Models.ActionPerformer() {
088: public boolean isEnabled(Object node) {
089: return true;
090: }
091:
092: public void perform(Object[] nodes) {
093: int i, k = nodes.length;
094: for (i = 0; i < k; i++)
095: ((Watch) nodes[i]).remove();
096: }
097: }, Models.MULTISELECTION_TYPE_ANY);
098: static {
099: DELETE_ACTION.putValue(Action.ACCELERATOR_KEY, KeyStroke
100: .getKeyStroke("DELETE"));
101: };
102: private static final Action CUSTOMIZE_ACTION = Models.createAction(
103: NbBundle.getBundle(WatchesActionsProvider.class).getString(
104: "CTL_WatchAction_Customize"),
105: new Models.ActionPerformer() {
106: public boolean isEnabled(Object node) {
107: return true;
108: }
109:
110: public void perform(Object[] nodes) {
111: customize((Watch) nodes[0]);
112: }
113: }, Models.MULTISELECTION_TYPE_EXACTLY_ONE);
114:
115: public Action[] getActions(Object node) throws UnknownTypeException {
116: if (node == TreeModel.ROOT)
117: return new Action[] { NEW_WATCH_ACTION, null,
118: DELETE_ALL_ACTION };
119: if (node instanceof Watch)
120: return new Action[] { NEW_WATCH_ACTION, null,
121: DELETE_ACTION, DELETE_ALL_ACTION, null,
122: CUSTOMIZE_ACTION };
123: throw new UnknownTypeException(node);
124: }
125:
126: public void performDefaultAction(Object node)
127: throws UnknownTypeException {
128: if (node == TreeModel.ROOT)
129: return;
130: if (node instanceof Watch) {
131: customize((Watch) node);
132: return;
133: }
134: throw new UnknownTypeException(node);
135: }
136:
137: public void addModelListener(ModelListener l) {
138: }
139:
140: public void removeModelListener(ModelListener l) {
141: }
142:
143: private static void customize(Watch w) {
144:
145: WatchPanel wp = new WatchPanel(w.getExpression());
146: JComponent panel = wp.getPanel();
147:
148: org.openide.DialogDescriptor dd = new org.openide.DialogDescriptor(
149: panel, NbBundle.getMessage(
150: WatchesActionsProvider.class,
151: "CTL_WatchDialog_Title", // NOI18N
152: w.getExpression()));
153: dd.setHelpCtx(new HelpCtx("debug.add.watch"));
154: Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
155: dialog.setVisible(true);
156: dialog.dispose();
157:
158: if (dd.getValue() != org.openide.DialogDescriptor.OK_OPTION)
159: return;
160: w.setExpression(wp.getExpression());
161: }
162: }
|