1 19 20 package org.netbeans.modules.web.debug.actions; 21 22 import java.util.*; 23 import java.beans.*; 24 25 import org.netbeans.api.debugger.*; 26 import org.netbeans.api.debugger.jpda.*; 27 import org.netbeans.modules.web.api.webmodule.WebModule; 28 import org.netbeans.spi.debugger.*; 29 30 import org.netbeans.modules.web.debug.Context; 31 import org.netbeans.modules.web.debug.JspBreakpointAnnotationListener; 32 import org.netbeans.modules.web.debug.util.Utils; 33 import org.netbeans.modules.web.debug.breakpoints.JspLineBreakpoint; 34 import org.openide.filesystems.FileObject; 35 import org.openide.filesystems.FileUtil; 36 37 42 public class JspToggleBreakpointActionProvider extends ActionsProviderSupport implements PropertyChangeListener { 43 44 45 private JPDADebugger debugger; 46 47 48 public JspToggleBreakpointActionProvider () { 49 Context.addPropertyChangeListener (this); 50 } 51 52 public JspToggleBreakpointActionProvider (ContextProvider contextProvider) { 53 debugger = (JPDADebugger) contextProvider.lookupFirst 54 (null, JPDADebugger.class); 55 debugger.addPropertyChangeListener (debugger.PROP_STATE, this); 56 Context.addPropertyChangeListener (this); 57 } 58 59 private void destroy () { 60 debugger.removePropertyChangeListener (debugger.PROP_STATE, this); 61 Context.removePropertyChangeListener (this); 62 } 63 64 public void propertyChange (PropertyChangeEvent evt) { 65 String url = Context.getCurrentURL(); 66 67 FileObject fo = Utils.getFileObjectFromUrl(url); 69 WebModule owner = null; 70 if (fo != null) { 71 owner = WebModule.getWebModule(fo); 72 } 73 74 boolean isJsp = Utils.isJsp(fo) || Utils.isTag(fo); 75 76 String webRoot = null; 77 if (owner != null && owner.getDocumentBase() != null) { 78 webRoot = FileUtil.getRelativePath(owner.getDocumentBase(), fo); 79 } 80 81 String serverID = Utils.getTargetServerID(fo); 86 87 setEnabled(ActionsManager.ACTION_TOGGLE_BREAKPOINT, owner != null && webRoot != null && isJsp && !"WebLogic9".equals(serverID)); if ( debugger != null && 89 debugger.getState () == debugger.STATE_DISCONNECTED 90 ) 91 destroy (); 92 } 93 94 public Set getActions () { 95 return Collections.singleton (ActionsManager.ACTION_TOGGLE_BREAKPOINT); 96 } 97 98 public void doAction (Object action) { 99 DebuggerManager d = DebuggerManager.getDebuggerManager (); 100 101 int ln = Context.getCurrentLineNumber (); 103 String url = Context.getCurrentURL (); 104 if (url == null) return; 105 106 JspLineBreakpoint lb = getJspBreakpointAnnotationListener().findBreakpoint(url, ln); 108 if (lb != null) { 109 d.removeBreakpoint(lb); 110 return; 111 } 112 lb = JspLineBreakpoint.create(url, ln); 113 d.addBreakpoint(lb); 114 } 115 116 private JspBreakpointAnnotationListener jspBreakpointAnnotationListener; 117 private JspBreakpointAnnotationListener getJspBreakpointAnnotationListener () { 118 if (jspBreakpointAnnotationListener == null) 119 jspBreakpointAnnotationListener = (JspBreakpointAnnotationListener) 120 DebuggerManager.getDebuggerManager ().lookupFirst 121 (null, JspBreakpointAnnotationListener.class); 122 return jspBreakpointAnnotationListener; 123 } 124 } 125 | Popular Tags |