KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > ui > models > BreakpointsActionsProvider


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.debugger.jpda.ui.models;
21
22 import java.awt.Dialog JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import javax.swing.Action JavaDoc;
26 import javax.swing.JButton JavaDoc;
27 import javax.swing.JComponent JavaDoc;
28
29 import org.netbeans.api.debugger.Breakpoint;
30 import org.netbeans.api.debugger.jpda.ClassLoadUnloadBreakpoint;
31 import org.netbeans.api.debugger.jpda.ExceptionBreakpoint;
32 import org.netbeans.api.debugger.jpda.FieldBreakpoint;
33 import org.netbeans.api.debugger.jpda.JPDABreakpoint;
34 import org.netbeans.api.debugger.jpda.LineBreakpoint;
35 import org.netbeans.api.debugger.jpda.MethodBreakpoint;
36 import org.netbeans.api.debugger.jpda.ThreadBreakpoint;
37 import org.netbeans.spi.viewmodel.NodeActionsProvider;
38 import org.netbeans.spi.viewmodel.ModelListener;
39 import org.netbeans.spi.viewmodel.UnknownTypeException;
40 import org.netbeans.spi.viewmodel.Models;
41
42 import org.netbeans.modules.debugger.jpda.ui.EditorContextBridge;
43 import org.netbeans.modules.debugger.jpda.ui.breakpoints.*;
44 import org.netbeans.spi.debugger.ui.Controller;
45 import org.netbeans.spi.viewmodel.NodeActionsProviderFilter;
46
47 import org.openide.DialogDescriptor;
48 import org.openide.DialogDisplayer;
49 import org.openide.util.HelpCtx;
50 import org.openide.util.NbBundle;
51
52
53 /**
54  * @author Jan Jancura
55  */

56 public class BreakpointsActionsProvider implements NodeActionsProviderFilter {
57     
58     private static final Action JavaDoc GO_TO_SOURCE_ACTION = Models.createAction (
59         loc("CTL_Breakpoint_GoToSource_Label"), // NOI18N
60
new Models.ActionPerformer () {
61             public boolean isEnabled (Object JavaDoc node) {
62                 return true;
63             }
64             public void perform (Object JavaDoc[] nodes) {
65                 goToSource ((LineBreakpoint) nodes [0]);
66             }
67         },
68         Models.MULTISELECTION_TYPE_EXACTLY_ONE
69     );
70     private static final Action JavaDoc CUSTOMIZE_ACTION = Models.createAction (
71         loc("CTL_Breakpoint_Customize_Label"), // NOI18N
72
new Models.ActionPerformer () {
73             public boolean isEnabled (Object JavaDoc node) {
74                 return true;
75             }
76             public void perform (Object JavaDoc[] nodes) {
77                 customize ((Breakpoint) nodes [0]);
78             }
79         },
80         Models.MULTISELECTION_TYPE_EXACTLY_ONE
81     );
82         
83     private static String JavaDoc loc(String JavaDoc key) {
84         return NbBundle.getBundle(BreakpointsActionsProvider.class).getString(key);
85     }
86
87     public Action JavaDoc[] getActions (NodeActionsProvider original, Object JavaDoc node)
88     throws UnknownTypeException {
89         if (!(node instanceof JPDABreakpoint))
90             return original.getActions (node);
91         
92         Action JavaDoc[] oas = original.getActions (node);
93         if (node instanceof LineBreakpoint) {
94             Action JavaDoc[] as = new Action JavaDoc [oas.length + 3];
95             as [0] = GO_TO_SOURCE_ACTION;
96             as [1] = null;
97             System.arraycopy (oas, 0, as, 2, oas.length);
98             as [as.length - 1] = CUSTOMIZE_ACTION;
99             return as;
100         }
101         Action JavaDoc[] as = new Action JavaDoc [oas.length + 1];
102         System.arraycopy (oas, 0, as, 0, oas.length);
103         as [as.length - 1] = CUSTOMIZE_ACTION;
104         return as;
105     }
106     
107     public void performDefaultAction (NodeActionsProvider original, Object JavaDoc node) throws UnknownTypeException {
108         if (node instanceof LineBreakpoint)
109             goToSource ((LineBreakpoint) node);
110         else
111         if (node instanceof JPDABreakpoint)
112             customize ((Breakpoint) node);
113         else
114             original.performDefaultAction (node);
115     }
116
117     public void addModelListener (ModelListener l) {
118     }
119
120     public void removeModelListener (ModelListener l) {
121     }
122
123     public static void customize (Breakpoint b) {
124         JComponent JavaDoc c = null;
125         if (b instanceof LineBreakpoint)
126             c = new LineBreakpointPanel ((LineBreakpoint) b);
127         else
128         if (b instanceof FieldBreakpoint)
129             c = new FieldBreakpointPanel ((FieldBreakpoint) b);
130         else
131         if (b instanceof ClassLoadUnloadBreakpoint)
132             c = new ClassBreakpointPanel ((ClassLoadUnloadBreakpoint) b);
133         else
134         if (b instanceof MethodBreakpoint)
135             c = new MethodBreakpointPanel ((MethodBreakpoint) b);
136         else
137         if (b instanceof ThreadBreakpoint)
138             c = new ThreadBreakpointPanel ((ThreadBreakpoint) b);
139         else
140         if (b instanceof ExceptionBreakpoint)
141             c = new ExceptionBreakpointPanel ((ExceptionBreakpoint) b);
142
143         c.getAccessibleContext().setAccessibleDescription(
144                 NbBundle.getMessage(BreakpointsActionsProvider.class, "ACSD_Breakpoint_Customizer_Dialog")); // NOI18N
145
HelpCtx helpCtx = HelpCtx.findHelp (c);
146         if (helpCtx == null) {
147             helpCtx = new HelpCtx ("debug.add.breakpoint"); // NOI18N
148
}
149         final Controller[] cPtr = new Controller[] { (Controller) c };
150         final DialogDescriptor[] descriptorPtr = new DialogDescriptor[1];
151         final Dialog JavaDoc[] dialogPtr = new Dialog JavaDoc[1];
152         ActionListener JavaDoc buttonsActionListener = new ActionListener JavaDoc() {
153             public void actionPerformed(ActionEvent JavaDoc ev) {
154                 if (descriptorPtr[0].getValue() == DialogDescriptor.OK_OPTION) {
155                     boolean ok = cPtr[0].ok();
156                     if (ok) {
157                         dialogPtr[0].setVisible(false);
158                     }
159                 } else {
160                     dialogPtr[0].setVisible(false);
161                 }
162             }
163         };
164         DialogDescriptor descriptor = new DialogDescriptor (
165             c,
166             NbBundle.getMessage (
167                 BreakpointsActionsProvider.class,
168                 "CTL_Breakpoint_Customizer_Title" // NOI18N
169
),
170             true,
171             DialogDescriptor.OK_CANCEL_OPTION,
172             DialogDescriptor.OK_OPTION,
173             DialogDescriptor.DEFAULT_ALIGN,
174             helpCtx,
175             buttonsActionListener
176         );
177         descriptor.setClosingOptions(new Object JavaDoc[] {});
178         Dialog JavaDoc d = DialogDisplayer.getDefault ().createDialog (descriptor);
179         d.pack ();
180         descriptorPtr[0] = descriptor;
181         dialogPtr[0] = d;
182         d.setVisible (true);
183     }
184     
185     private static void goToSource (LineBreakpoint b) {
186         EditorContextBridge.showSource (b, null);
187     }
188 }
189
Popular Tags