KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > ui > actions > LineBreakpointCustomizeAction


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.actions;
21
22 import java.net.MalformedURLException JavaDoc;
23 import java.net.URL JavaDoc;
24 import org.netbeans.api.debugger.Breakpoint;
25 import org.netbeans.api.debugger.DebuggerManager;
26 import org.netbeans.api.debugger.jpda.LineBreakpoint;
27 import org.netbeans.modules.debugger.jpda.ui.EditorContextBridge;
28 import org.netbeans.modules.debugger.jpda.ui.models.BreakpointsActionsProvider;
29 import org.openide.util.HelpCtx;
30 import org.openide.util.NbBundle;
31 import org.openide.util.actions.NodeAction;
32
33 /**
34  * Customize action for line breakpoint, which is available from the gutter popup.
35  *
36  * @author Martin Entlicher
37  */

38 public class LineBreakpointCustomizeAction extends NodeAction {
39     
40     /** Creates a new instance of LineBreakpointCustomizeAction */
41     public LineBreakpointCustomizeAction() {
42     }
43     
44     static LineBreakpoint getCurrentBreakpoint() {
45         String JavaDoc currentURLStr = EditorContextBridge.getCurrentURL();
46         if (currentURLStr == null) return null;
47         URL JavaDoc currentURL;
48         try {
49             currentURL = new URL JavaDoc(currentURLStr);
50         } catch (MalformedURLException JavaDoc muex) {
51             return null;
52         }
53         int lineNumber = EditorContextBridge.getCurrentLineNumber();
54         if (lineNumber < 0) return null;
55         Breakpoint[] bs = DebuggerManager.getDebuggerManager ().
56                 getBreakpoints ();
57         for (int i = 0; i < bs.length; i++) {
58             if (bs[i] instanceof LineBreakpoint) {
59                 LineBreakpoint lb = (LineBreakpoint) bs[i];
60                 URL JavaDoc url;
61                 try {
62                     url = new URL JavaDoc(lb.getURL());
63                 } catch (MalformedURLException JavaDoc muex) {
64                     continue;
65                 }
66                 if (currentURL.equals(url)) {
67                     if (lineNumber == lb.getLineNumber()) {
68                         return lb;
69                     }
70                 }
71             }
72         }
73         return null;
74     }
75     
76     public boolean isEnabled() { // overriden, because orig impl caches the nodes
77
return enable(null);
78     }
79
80     protected boolean enable(org.openide.nodes.Node[] activatedNodes) {
81         LineBreakpoint lb = getCurrentBreakpoint();
82         return lb != null;
83     }
84
85     public String JavaDoc getName() {
86         return NbBundle.getMessage(LineBreakpointCustomizeAction.class, "CTL_customize");
87     }
88
89     protected void performAction(org.openide.nodes.Node[] activatedNodes) {
90         LineBreakpoint lb = getCurrentBreakpoint();
91         if (lb == null) return ;
92         BreakpointsActionsProvider.customize(lb);
93     }
94     
95     protected boolean asynchronous() {
96         return false; //This action should run in AWT.
97
}
98     
99     public HelpCtx getHelpCtx() {
100         return null;
101     }
102     
103 }
104
Popular Tags