KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > debug > breakpoints > JspBreakpointActionsProvider


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.web.debug.breakpoints;
21
22 import java.awt.Dialog JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.util.List 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.*;
30 import org.netbeans.api.debugger.jpda.*;
31 import org.netbeans.spi.debugger.ui.*;
32 import org.netbeans.spi.viewmodel.*;
33
34 import org.netbeans.modules.web.debug.*;
35
36 import org.openide.*;
37 import org.openide.util.*;
38
39
40 /**
41  * @author Martin Grebac
42  */

43 public class JspBreakpointActionsProvider implements NodeActionsProviderFilter {
44     
45     private static final Action JavaDoc GO_TO_SOURCE_ACTION = Models.createAction (
46         "Go to Source",
47         new Models.ActionPerformer () {
48             public boolean isEnabled (Object JavaDoc node) {
49                 return true;
50             }
51             public void perform (Object JavaDoc[] nodes) {
52                 goToSource ((JspLineBreakpoint) nodes [0]);
53             }
54         },
55         Models.MULTISELECTION_TYPE_EXACTLY_ONE
56     );
57     private static final Action JavaDoc CUSTOMIZE_ACTION = Models.createAction (
58         "Customize",
59         new Models.ActionPerformer () {
60             public boolean isEnabled (Object JavaDoc node) {
61                 return true;
62             }
63             public void perform (Object JavaDoc[] nodes) {
64                 customize ((Breakpoint) nodes [0]);
65             }
66         },
67         Models.MULTISELECTION_TYPE_EXACTLY_ONE
68     );
69     
70     
71     public Action JavaDoc[] getActions (NodeActionsProvider original, Object JavaDoc node) throws UnknownTypeException {
72         if (!(node instanceof JspLineBreakpoint))
73             return original.getActions (node);
74         
75         Action JavaDoc[] oas = original.getActions (node);
76         if (node instanceof JspLineBreakpoint) {
77             Action JavaDoc[] as = new Action JavaDoc [oas.length + 3];
78             as [0] = GO_TO_SOURCE_ACTION;
79             as [1] = null;
80             System.arraycopy (oas, 0, as, 2, oas.length);
81             as [as.length - 1] = CUSTOMIZE_ACTION;
82             return as;
83         }
84         Action JavaDoc[] as = new Action JavaDoc [oas.length + 1];
85         System.arraycopy (oas, 0, as, 0, oas.length);
86         as [as.length - 1] = CUSTOMIZE_ACTION;
87         return as;
88     }
89     
90     public void performDefaultAction (NodeActionsProvider original, Object JavaDoc node) throws UnknownTypeException {
91         if (node instanceof JspLineBreakpoint)
92             goToSource ((JspLineBreakpoint) node);
93         else
94             original.performDefaultAction (node);
95     }
96
97     public void addModelListener (ModelListener l) {
98     }
99
100     public void removeModelListener (ModelListener l) {
101     }
102
103     private static void customize (Breakpoint b) {
104         JComponent JavaDoc c = null;
105         if (b instanceof JspLineBreakpoint) {
106             c = new JspBreakpointPanel((JspLineBreakpoint) b);
107         }
108
109         DialogDescriptor descriptor = new DialogDescriptor (
110             c,
111             NbBundle.getMessage (
112                 JspBreakpointActionsProvider.class,
113                 "CTL_Breakpoint_Customizer_Title" // NOI18N
114
)
115         );
116
117         JButton JavaDoc bOk = null;
118         JButton JavaDoc bClose = null;
119         descriptor.setOptions (new JButton JavaDoc[] {
120             bOk = new JButton JavaDoc (NbBundle.getMessage (
121                 JspBreakpointActionsProvider.class,
122                 "CTL_Ok" // NOI18N
123
)),
124             bClose = new JButton JavaDoc (NbBundle.getMessage (
125                 JspBreakpointActionsProvider.class,
126                 "CTL_Close" // NOI18N
127
))
128         });
129         HelpCtx helpCtx = HelpCtx.findHelp (c);
130         if (helpCtx == null)
131             helpCtx = new HelpCtx ("debug.add.breakpoint");;
132         descriptor.setHelpCtx (helpCtx);
133         bOk.getAccessibleContext ().setAccessibleDescription (
134             NbBundle.getMessage (
135                 JspBreakpointActionsProvider.class,
136                 "ACSD_CTL_Ok" // NOI18N
137
)
138         );
139         bOk.setMnemonic(NbBundle.getMessage(JspBreakpointActionsProvider.class, "CTL_Ok_MNEM").charAt(0)); // NOI18N
140
bClose.getAccessibleContext ().setAccessibleDescription (
141             NbBundle.getMessage (
142                 JspBreakpointActionsProvider.class,
143                 "ACSD_CTL_Close" // NOI18N
144
)
145         );
146         bClose.setMnemonic(NbBundle.getMessage(JspBreakpointActionsProvider.class, "CTL_Close_MNEM").charAt(0)); // NOI18N
147
descriptor.setClosingOptions (null);
148         Dialog JavaDoc d = DialogDisplayer.getDefault ().createDialog (descriptor);
149         d.pack ();
150         d.setVisible (true);
151         if (descriptor.getValue () == bOk) {
152             ((Controller) c).ok ();
153         }
154     }
155     
156     private static void goToSource (JspLineBreakpoint b) {
157         Context.showSource (b);
158     }
159 }
160
Popular Tags