KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > debug > actions > JspGoToCursorActionProvider


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 package org.netbeans.modules.web.debug.actions;
20
21 import java.beans.*;
22 import java.util.*;
23
24 import org.netbeans.api.debugger.*;
25 import org.netbeans.api.debugger.jpda.*;
26 import org.netbeans.spi.debugger.*;
27 import org.netbeans.modules.web.debug.Context;
28 import org.netbeans.modules.web.debug.util.*;
29 import org.netbeans.modules.web.debug.breakpoints.*;
30
31
32 /**
33  *
34  * @author Martin Grebac
35  */

36 public class JspGoToCursorActionProvider extends ActionsProviderSupport implements PropertyChangeListener {
37
38     private JPDADebugger debugger;
39     private Session session;
40     private JspLineBreakpoint breakpoint;
41     
42     
43     public JspGoToCursorActionProvider(ContextProvider contextProvider) {
44         debugger = (JPDADebugger) contextProvider.lookupFirst(null, JPDADebugger.class);
45         session = (Session) contextProvider.lookupFirst(null, Session.class);
46         debugger.addPropertyChangeListener(debugger.PROP_STATE, this);
47         Context.addPropertyChangeListener(this);
48     }
49
50     private void destroy () {
51         debugger.removePropertyChangeListener (debugger.PROP_STATE, this);
52         Context.removePropertyChangeListener (this);
53     }
54     
55     public void propertyChange (PropertyChangeEvent evt) {
56         setEnabled (
57             ActionsManager.ACTION_RUN_TO_CURSOR,
58             (debugger.getState () == debugger.STATE_STOPPED) &&
59             (Utils.isJsp(Context.getCurrentURL()) || Utils.isTag(Context.getCurrentURL()))
60         );
61         if ((debugger.getState () != debugger.STATE_RUNNING) && (breakpoint != null)) {
62             DebuggerManager.getDebuggerManager ().removeBreakpoint (breakpoint);
63             breakpoint = null;
64         }
65         if (debugger.getState () == debugger.STATE_DISCONNECTED) {
66             destroy ();
67         }
68     }
69     
70     public Set getActions () {
71         return Collections.singleton (ActionsManager.ACTION_RUN_TO_CURSOR);
72     }
73     
74     public void doAction (Object JavaDoc action) {
75         if (breakpoint != null) {
76             DebuggerManager.getDebuggerManager ().removeBreakpoint (breakpoint);
77             breakpoint = null;
78         }
79         breakpoint = JspLineBreakpoint.create (
80             Context.getCurrentURL(),
81             Context.getCurrentLineNumber()
82         );
83         breakpoint.setHidden(true);
84         DebuggerManager.getDebuggerManager().addBreakpoint (breakpoint);
85         session.getEngineForLanguage ("JSP").getActionsManager ().doAction (
86             ActionsManager.ACTION_CONTINUE
87         );
88     }
89 }
90
Popular Tags