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.breakpoints;
043:
044: import java.awt.Dialog;
045: import javax.swing.Action;
046: import javax.swing.JButton;
047: import javax.swing.JComponent;
048:
049: import org.netbeans.api.debugger.*;
050: import org.netbeans.api.debugger.jpda.*;
051: import org.netbeans.spi.debugger.ui.*;
052: import org.netbeans.spi.viewmodel.*;
053:
054: import org.netbeans.modules.web.debug.*;
055:
056: import org.openide.*;
057: import org.openide.util.*;
058:
059: /**
060: * @author Martin Grebac
061: */
062: public class JspBreakpointActionsProvider implements
063: NodeActionsProviderFilter {
064:
065: private static final Action GO_TO_SOURCE_ACTION = Models
066: .createAction(NbBundle.getMessage(
067: JspBreakpointActionsProvider.class,
068: "LBL_Action_Go_To_Source"),
069: new Models.ActionPerformer() {
070: public boolean isEnabled(Object node) {
071: return true;
072: }
073:
074: public void perform(Object[] nodes) {
075: goToSource((JspLineBreakpoint) nodes[0]);
076: }
077: }, Models.MULTISELECTION_TYPE_EXACTLY_ONE);
078: private static final Action CUSTOMIZE_ACTION = Models.createAction(
079: NbBundle.getMessage(JspBreakpointActionsProvider.class,
080: "LBL_Action_Customize"),
081: new Models.ActionPerformer() {
082: public boolean isEnabled(Object node) {
083: return true;
084: }
085:
086: public void perform(Object[] nodes) {
087: customize((Breakpoint) nodes[0]);
088: }
089: }, Models.MULTISELECTION_TYPE_EXACTLY_ONE);
090:
091: public Action[] getActions(NodeActionsProvider original, Object node)
092: throws UnknownTypeException {
093: if (!(node instanceof JspLineBreakpoint))
094: return original.getActions(node);
095:
096: Action[] oas = original.getActions(node);
097: if (node instanceof JspLineBreakpoint) {
098: Action[] as = new Action[oas.length + 3];
099: as[0] = GO_TO_SOURCE_ACTION;
100: as[1] = null;
101: System.arraycopy(oas, 0, as, 2, oas.length);
102: as[as.length - 1] = CUSTOMIZE_ACTION;
103: return as;
104: }
105: Action[] as = new Action[oas.length + 1];
106: System.arraycopy(oas, 0, as, 0, oas.length);
107: as[as.length - 1] = CUSTOMIZE_ACTION;
108: return as;
109: }
110:
111: public void performDefaultAction(NodeActionsProvider original,
112: Object node) throws UnknownTypeException {
113: if (node instanceof JspLineBreakpoint)
114: goToSource((JspLineBreakpoint) node);
115: else
116: original.performDefaultAction(node);
117: }
118:
119: public void addModelListener(ModelListener l) {
120: }
121:
122: public void removeModelListener(ModelListener l) {
123: }
124:
125: private static void customize(Breakpoint b) {
126: JComponent c = null;
127: if (b instanceof JspLineBreakpoint) {
128: c = new JspBreakpointPanel((JspLineBreakpoint) b);
129: }
130:
131: DialogDescriptor descriptor = new DialogDescriptor(c, NbBundle
132: .getMessage(JspBreakpointActionsProvider.class,
133: "CTL_Breakpoint_Customizer_Title" // NOI18N
134: ));
135:
136: JButton bOk = null;
137: JButton bClose = null;
138: descriptor.setOptions(new JButton[] {
139: bOk = new JButton(NbBundle.getMessage(
140: JspBreakpointActionsProvider.class, "CTL_Ok" // NOI18N
141: )),
142: bClose = new JButton(NbBundle.getMessage(
143: JspBreakpointActionsProvider.class, "CTL_Close" // NOI18N
144: )) });
145: HelpCtx helpCtx = HelpCtx.findHelp(c);
146: if (helpCtx == null)
147: helpCtx = new HelpCtx("debug.add.breakpoint");
148: ;
149: descriptor.setHelpCtx(helpCtx);
150: bOk.getAccessibleContext().setAccessibleDescription(
151: NbBundle.getMessage(JspBreakpointActionsProvider.class,
152: "ACSD_CTL_Ok" // NOI18N
153: ));
154: bOk.setMnemonic(NbBundle.getMessage(
155: JspBreakpointActionsProvider.class, "CTL_Ok_MNEM")
156: .charAt(0)); // NOI18N
157: bClose.getAccessibleContext().setAccessibleDescription(
158: NbBundle.getMessage(JspBreakpointActionsProvider.class,
159: "ACSD_CTL_Close" // NOI18N
160: ));
161: bClose.setMnemonic(NbBundle.getMessage(
162: JspBreakpointActionsProvider.class, "CTL_Close_MNEM")
163: .charAt(0)); // NOI18N
164: descriptor.setClosingOptions(null);
165: Dialog d = DialogDisplayer.getDefault()
166: .createDialog(descriptor);
167: d.pack();
168: d.setVisible(true);
169: if (descriptor.getValue() == bOk) {
170: ((Controller) c).ok();
171: }
172: }
173:
174: private static void goToSource(JspLineBreakpoint b) {
175: Context.showSource(b);
176: }
177: }
|