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-2007 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.actions;
043:
044: import java.awt.Dialog;
045: import java.util.ResourceBundle;
046: import javax.swing.*;
047: import org.netbeans.api.debugger.DebuggerManager;
048: import org.netbeans.modules.debugger.ui.WatchPanel;
049:
050: import org.openide.DialogDisplayer;
051: import org.openide.awt.Mnemonics;
052: import org.openide.util.HelpCtx;
053: import org.openide.util.NbBundle;
054: import org.openide.util.actions.CallableSystemAction;
055:
056: /**
057: * DebuggerManager Window action.
058: *
059: * @author Jan Jancura
060: */
061: public class AddWatchAction extends CallableSystemAction {
062:
063: private static String watchHistory = ""; // NOI18N
064:
065: public AddWatchAction() {
066: // The action is not in the toolbar by default, so it should not have the
067: // icon in the menu.
068: putValue("noIconInMenu", Boolean.TRUE);
069: }
070:
071: protected boolean asynchronous() {
072: return false;
073: }
074:
075: public String getName() {
076: return NbBundle.getMessage(AddWatchAction.class,
077: "CTL_New_Watch");
078: }
079:
080: public HelpCtx getHelpCtx() {
081: return new HelpCtx(AddWatchAction.class);
082:
083: }
084:
085: /** The action's icon location.
086: * @return the action's icon location
087: */
088: protected String iconResource() {
089: return "org/netbeans/modules/debugger/resources/actions/NewWatch.gif"; // NOI18N
090: }
091:
092: public void performAction() {
093: ResourceBundle bundle = NbBundle
094: .getBundle(AddWatchAction.class);
095:
096: WatchPanel wp = new WatchPanel(watchHistory);
097: JComponent panel = wp.getPanel();
098:
099: // <RAVE>
100: // Add help ID for 'Add Watch' dialog
101: // org.openide.DialogDescriptor dd = new org.openide.DialogDescriptor (
102: // panel,
103: // bundle.getString ("CTL_WatchDialog_Title") // NOI18N
104: // );
105: // ====
106: org.openide.DialogDescriptor dd = new org.openide.DialogDescriptor(
107: panel,
108: bundle.getString("CTL_WatchDialog_Title"), // NOI18N
109: true, org.openide.DialogDescriptor.OK_CANCEL_OPTION,
110: null, org.openide.DialogDescriptor.DEFAULT_ALIGN,
111: new org.openide.util.HelpCtx("debug.add.watch"), null);
112: // </RAVE>
113: Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
114: dialog.setVisible(true);
115: dialog.dispose();
116:
117: if (dd.getValue() != org.openide.DialogDescriptor.OK_OPTION)
118: return;
119: String watch = wp.getExpression();
120: if ((watch == null) || (watch.trim().length() == 0))
121: return;
122:
123: String s = watch;
124: int i = s.indexOf(';');
125: while (i > 0) {
126: String ss = s.substring(0, i).trim();
127: if (ss.length() > 0)
128: DebuggerManager.getDebuggerManager().createWatch(ss);
129: s = s.substring(i + 1);
130: i = s.indexOf(';');
131: }
132: s = s.trim();
133: if (s.length() > 0)
134: DebuggerManager.getDebuggerManager().createWatch(s);
135:
136: watchHistory = watch;
137:
138: // open watches view
139: ViewActions.openComponent("watchesView", false)
140: .requestVisible();
141: }
142: }
|