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.cnd.debugger.gdb.models;
043:
044: import java.awt.Dialog;
045: import java.awt.event.ActionEvent;
046: import java.awt.event.ActionListener;
047: import javax.swing.Action;
048: import javax.swing.JComponent;
049:
050: import org.openide.DialogDescriptor;
051: import org.openide.DialogDisplayer;
052: import org.openide.util.HelpCtx;
053: import org.openide.util.NbBundle;
054:
055: import org.netbeans.api.debugger.Breakpoint;
056: import org.netbeans.spi.debugger.ui.Controller;
057: import org.netbeans.spi.viewmodel.NodeActionsProvider;
058: import org.netbeans.spi.viewmodel.ModelListener;
059: import org.netbeans.spi.viewmodel.UnknownTypeException;
060: import org.netbeans.spi.viewmodel.Models;
061: import org.netbeans.spi.viewmodel.NodeActionsProviderFilter;
062:
063: import org.netbeans.modules.cnd.debugger.gdb.breakpoints.GdbBreakpoint;
064: import org.netbeans.modules.cnd.debugger.gdb.breakpoints.LineBreakpoint;
065: import org.netbeans.modules.cnd.debugger.gdb.breakpoints.FunctionBreakpoint;
066: import org.netbeans.modules.cnd.debugger.gdb.EditorContextBridge;
067: import org.netbeans.modules.cnd.debugger.gdb.breakpoints.AddressBreakpoint;
068: import org.netbeans.modules.cnd.debugger.gdb.breakpoints.AddressBreakpointPanel;
069: import org.netbeans.modules.cnd.debugger.gdb.breakpoints.FunctionBreakpointPanel;
070: import org.netbeans.modules.cnd.debugger.gdb.breakpoints.LineBreakpointPanel;
071: import org.netbeans.modules.cnd.debugger.gdb.disassembly.Disassembly;
072:
073: /**
074: * @author Jan Jancura and Gordon Prieur
075: */
076: public class BreakpointsActionsProvider implements
077: NodeActionsProviderFilter {
078:
079: private static final Action GO_TO_SOURCE_ACTION = Models
080: .createAction(loc("CTL_Breakpoint_GoToSource_Label"), // NOI18N
081: new Models.ActionPerformer() {
082: public boolean isEnabled(Object node) {
083: return true;
084: }
085:
086: public void perform(Object[] nodes) {
087: goToSource((LineBreakpoint) nodes[0]);
088: }
089: }, Models.MULTISELECTION_TYPE_EXACTLY_ONE);
090: private static final Action CUSTOMIZE_ACTION = Models.createAction(
091: loc("CTL_Breakpoint_Customize_Label"), // NOI18N
092: new Models.ActionPerformer() {
093: public boolean isEnabled(Object node) {
094: return true;
095: }
096:
097: public void perform(Object[] nodes) {
098: customize((Breakpoint) nodes[0]);
099: }
100: }, Models.MULTISELECTION_TYPE_EXACTLY_ONE);
101:
102: private static final Action GO_TO_DIS_ACTION = Models.createAction(
103: loc("CTL_Breakpoint_GoToDis_Label"), // NOI18N
104: new Models.ActionPerformer() {
105: public boolean isEnabled(Object node) {
106: return Disassembly.getCurrent() != null;
107: }
108:
109: public void perform(Object[] nodes) {
110: goToSource((AddressBreakpoint) nodes[0]);
111: }
112: }, Models.MULTISELECTION_TYPE_EXACTLY_ONE);
113:
114: private static String loc(String key) {
115: return NbBundle.getBundle(BreakpointsActionsProvider.class)
116: .getString(key);
117: }
118:
119: public Action[] getActions(NodeActionsProvider original, Object node)
120: throws UnknownTypeException {
121: if (!(node instanceof GdbBreakpoint))
122: return original.getActions(node);
123:
124: Action[] oas = original.getActions(node);
125: if (node instanceof LineBreakpoint) {
126: Action[] as = new Action[oas.length + 3];
127: as[0] = GO_TO_SOURCE_ACTION;
128: as[1] = null;
129: System.arraycopy(oas, 0, as, 2, oas.length);
130: as[as.length - 1] = CUSTOMIZE_ACTION;
131: return as;
132: } else if (node instanceof AddressBreakpoint) {
133: Action[] as = new Action[oas.length + 3];
134: as[0] = GO_TO_DIS_ACTION;
135: as[1] = null;
136: System.arraycopy(oas, 0, as, 2, oas.length);
137: as[as.length - 1] = CUSTOMIZE_ACTION;
138: return as;
139: }
140: Action[] as = new Action[oas.length + 1];
141: System.arraycopy(oas, 0, as, 0, oas.length);
142: as[as.length - 1] = CUSTOMIZE_ACTION;
143: return as;
144: }
145:
146: public void performDefaultAction(NodeActionsProvider original,
147: Object node) throws UnknownTypeException {
148: if (node instanceof LineBreakpoint)
149: goToSource((LineBreakpoint) node);
150: if (node instanceof AddressBreakpoint)
151: goToSource((AddressBreakpoint) node);
152: else if (node instanceof GdbBreakpoint)
153: customize((Breakpoint) node);
154: else
155: original.performDefaultAction(node);
156: }
157:
158: public void addModelListener(ModelListener l) {
159: }
160:
161: public void removeModelListener(ModelListener l) {
162: }
163:
164: public static void customize(Breakpoint b) {
165: JComponent c = null;
166: if (b instanceof LineBreakpoint) {
167: c = new LineBreakpointPanel((LineBreakpoint) b);
168: } else if (b instanceof FunctionBreakpoint) {
169: c = new FunctionBreakpointPanel((FunctionBreakpoint) b);
170: } else if (b instanceof AddressBreakpoint) {
171: c = new AddressBreakpointPanel((AddressBreakpoint) b);
172: } else {
173: return; // should never happen (ie, its a developer error)
174: }
175:
176: c.getAccessibleContext().setAccessibleDescription(
177: NbBundle.getMessage(BreakpointsActionsProvider.class,
178: "ACSD_Breakpoint_Customizer_Dialog")); // NOI18N
179: HelpCtx helpCtx = HelpCtx.findHelp(c);
180: if (helpCtx == null) {
181: helpCtx = new HelpCtx("debug.add.breakpoint"); // FIXUP - Whats our help ID?
182: }
183: final Controller[] cPtr = new Controller[] { (Controller) c };
184: final DialogDescriptor[] descriptorPtr = new DialogDescriptor[1];
185: final Dialog[] dialogPtr = new Dialog[1];
186: ActionListener buttonsActionListener = new ActionListener() {
187: public void actionPerformed(ActionEvent ev) {
188: if (descriptorPtr[0].getValue() == DialogDescriptor.OK_OPTION) {
189: boolean ok = cPtr[0].ok();
190: if (ok) {
191: dialogPtr[0].setVisible(false);
192: }
193: } else {
194: dialogPtr[0].setVisible(false);
195: }
196: }
197: };
198: DialogDescriptor descriptor = new DialogDescriptor(
199: c,
200: NbBundle.getMessage(BreakpointsActionsProvider.class,
201: "CTL_Breakpoint_Customizer_Title"), // NOI18N
202:
203: true, DialogDescriptor.OK_CANCEL_OPTION,
204: DialogDescriptor.OK_OPTION,
205: DialogDescriptor.DEFAULT_ALIGN, helpCtx,
206: buttonsActionListener);
207: descriptor.setClosingOptions(new Object[] {});
208: Dialog d = DialogDisplayer.getDefault()
209: .createDialog(descriptor);
210: d.pack();
211: descriptorPtr[0] = descriptor;
212: dialogPtr[0] = d;
213: d.setVisible(true);
214: }
215:
216: private static void goToSource(GdbBreakpoint b) {
217: EditorContextBridge.showSource(b, null);
218: }
219: }
|