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.web.debug.watchesfiltering;
043:
044: import org.netbeans.spi.viewmodel.*;
045: import org.netbeans.api.debugger.DebuggerManager;
046: import org.netbeans.api.debugger.Watch;
047: import org.openide.util.NbBundle;
048: import org.openide.util.HelpCtx;
049: import org.openide.DialogDisplayer;
050:
051: import javax.swing.*;
052: import java.awt.event.ActionEvent;
053: import java.awt.Dialog;
054: import java.util.*;
055:
056: /**
057: * Provides actions for JspElWatch nodes.
058: *
059: * @author Maros Sandor
060: */
061: public class JspWatchesActionsProvider implements NodeActionsProvider {
062:
063: private static final Action NEW_WATCH_ACTION = new AbstractAction(
064: NbBundle.getBundle(JspWatchesActionsProvider.class)
065: .getString("CTL_WatchAction_AddNew")) {
066: public void actionPerformed(ActionEvent e) {
067: newWatch();
068: }
069: };
070: private static final Action DELETE_ALL_ACTION = new AbstractAction(
071: NbBundle.getBundle(JspWatchesActionsProvider.class)
072: .getString("CTL_WatchAction_DeleteAll")) {
073: public void actionPerformed(ActionEvent e) {
074: DebuggerManager.getDebuggerManager().removeAllWatches();
075: }
076: };
077: private static final Action DELETE_ACTION = Models.createAction(
078: NbBundle.getBundle(JspWatchesActionsProvider.class)
079: .getString("CTL_WatchAction_Delete"),
080: new Models.ActionPerformer() {
081: public boolean isEnabled(Object node) {
082: return true;
083: }
084:
085: public void perform(Object[] nodes) {
086: int i, k = nodes.length;
087: for (i = 0; i < k; i++)
088: ((JspElWatch) nodes[i]).getWatch().remove();
089: }
090: }, Models.MULTISELECTION_TYPE_ANY);
091: static {
092: DELETE_ACTION.putValue(Action.ACCELERATOR_KEY, KeyStroke
093: .getKeyStroke("DELETE"));
094: };
095: private static final Action CUSTOMIZE_ACTION = Models.createAction(
096: NbBundle.getBundle(JspWatchesActionsProvider.class)
097: .getString("CTL_WatchAction_Customize"),
098: new Models.ActionPerformer() {
099: public boolean isEnabled(Object node) {
100: return true;
101: }
102:
103: public void perform(Object[] nodes) {
104: customize(((JspElWatch) nodes[0]).getWatch());
105: }
106: }, Models.MULTISELECTION_TYPE_EXACTLY_ONE);
107:
108: public Action[] getActions(Object node) throws UnknownTypeException {
109: if (node instanceof JspElWatch)
110: return new Action[] { NEW_WATCH_ACTION, null,
111: DELETE_ACTION, DELETE_ALL_ACTION, null,
112: CUSTOMIZE_ACTION };
113: throw new UnknownTypeException(node);
114: }
115:
116: public void performDefaultAction(Object node)
117: throws UnknownTypeException {
118: if (node instanceof JspElWatch) {
119: customize(((JspElWatch) node).getWatch());
120: return;
121: }
122: throw new UnknownTypeException(node);
123: }
124:
125: public void addModelListener(ModelListener l) {
126: }
127:
128: public void removeModelListener(ModelListener l) {
129: }
130:
131: private static void customize(Watch w) {
132: WatchPanel wp = new WatchPanel(w.getExpression());
133: JComponent panel = wp.getPanel();
134:
135: org.openide.DialogDescriptor dd = new org.openide.DialogDescriptor(
136: panel, NbBundle.getMessage(
137: JspWatchesActionsProvider.class,
138: "CTL_Edit_Watch_Dialog_Title", // NOI18N
139: w.getExpression()));
140: dd.setHelpCtx(new HelpCtx("debug.add.watch"));
141: Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
142: dialog.setVisible(true);
143: dialog.dispose();
144:
145: if (dd.getValue() != org.openide.DialogDescriptor.OK_OPTION)
146: return;
147: w.setExpression(wp.getExpression());
148: }
149:
150: private static void newWatch() {
151: WatchPanel wp = new WatchPanel("");
152: JComponent panel = wp.getPanel();
153:
154: org.openide.DialogDescriptor dd = new org.openide.DialogDescriptor(
155: panel, NbBundle.getMessage(
156: JspWatchesActionsProvider.class,
157: "CTL_New_Watch_Dialog_Title") // NOI18N
158: );
159: dd.setHelpCtx(new HelpCtx("debug.new.watch"));
160: Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
161: dialog.setVisible(true);
162: dialog.dispose();
163:
164: if (dd.getValue() != org.openide.DialogDescriptor.OK_OPTION)
165: return;
166: DebuggerManager.getDebuggerManager().createWatch(
167: wp.getExpression());
168: }
169:
170: }
|