diff -r 766e8327016d ant.debugger/src/org/netbeans/modules/ant/debugger/ToolTipAnnotation.java --- a/ant.debugger/src/org/netbeans/modules/ant/debugger/ToolTipAnnotation.java Fri Jun 06 19:28:24 2008 +0200 +++ b/ant.debugger/src/org/netbeans/modules/ant/debugger/ToolTipAnnotation.java Wed Jun 11 16:59:11 2008 +0200 @@ -62,6 +62,7 @@ import org.netbeans.api.debugger.Debugge import org.netbeans.api.debugger.DebuggerManager; import org.netbeans.api.debugger.Watch; +import org.netbeans.spi.debugger.ui.EditorContextDispatcher; import org.openide.nodes.Node; import org.openide.windows.TopComponent; @@ -103,7 +104,7 @@ public class ToolTipAnnotation extends A } catch (IOException ex) { return ; } - JEditorPane ep = getCurrentEditor (); + JEditorPane ep = EditorContextDispatcher.getDefault().getCurrentEditor(); if (ep == null) return ; String expression = getIdentifier ( doc, @@ -180,52 +181,5 @@ public class ToolTipAnnotation extends A } } - /** - * Returns current editor component instance. - * - * Used in: ToolTipAnnotation - */ - private static JEditorPane getCurrentEditor_() { - EditorCookie e = getCurrentEditorCookie (); - if (e == null) return null; - JEditorPane[] op = e.getOpenedPanes (); - if ((op == null) || (op.length < 1)) return null; - return op [0]; - } - - static JEditorPane getCurrentEditor () { - if (SwingUtilities.isEventDispatchThread()) { - return getCurrentEditor_(); - } else { - final JEditorPane[] ce = new JEditorPane[1]; - try { - SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - ce[0] = getCurrentEditor_(); - } - }); - } catch (InvocationTargetException ex) { - ErrorManager.getDefault().notify(ex.getTargetException()); - } catch (InterruptedException ex) { - ErrorManager.getDefault().notify(ex); - } - return ce[0]; - } - } - - /** - * Returns current editor component instance. - * - * @return current editor component instance - */ - private static EditorCookie getCurrentEditorCookie () { - Node[] nodes = TopComponent.getRegistry ().getActivatedNodes (); - if ( (nodes == null) || - (nodes.length != 1) ) return null; - Node n = nodes [0]; - return (EditorCookie) n.getCookie ( - EditorCookie.class - ); - } } diff -r 766e8327016d ant.debugger/src/org/netbeans/modules/ant/debugger/breakpoints/AntBreakpointActionProvider.java --- a/ant.debugger/src/org/netbeans/modules/ant/debugger/breakpoints/AntBreakpointActionProvider.java Fri Jun 06 19:28:24 2008 +0200 +++ b/ant.debugger/src/org/netbeans/modules/ant/debugger/breakpoints/AntBreakpointActionProvider.java Wed Jun 11 16:59:11 2008 +0200 @@ -54,6 +54,7 @@ import org.netbeans.api.debugger.Breakpo import org.netbeans.api.debugger.Breakpoint; import org.netbeans.api.debugger.DebuggerManager; import org.netbeans.spi.debugger.ActionsProviderSupport; +import org.netbeans.spi.debugger.ui.EditorContextDispatcher; import org.openide.ErrorManager; import org.openide.cookies.EditorCookie; import org.openide.cookies.LineCookie; @@ -72,15 +73,18 @@ public class AntBreakpointActionProvider public class AntBreakpointActionProvider extends ActionsProviderSupport implements PropertyChangeListener { + private static final String ANT_MIME_TYPE = "text/x-ant+xml"; // NOI8N + private static final Set actions = Collections.singleton ( ActionsManager.ACTION_TOGGLE_BREAKPOINT ); + EditorContextDispatcher context = EditorContextDispatcher.getDefault(); public AntBreakpointActionProvider () { + context.addPropertyChangeListener(ANT_MIME_TYPE, + WeakListeners.propertyChange(this, context)); setEnabled (ActionsManager.ACTION_TOGGLE_BREAKPOINT, true); - TopComponent.getRegistry().addPropertyChangeListener( - WeakListeners.propertyChange(this, TopComponent.getRegistry())); } /** @@ -119,29 +123,15 @@ public class AntBreakpointActionProvider } - static Line getCurrentLine () { - Node[] nodes = TopComponent.getRegistry ().getCurrentNodes (); - if (nodes == null) return null; - if (nodes.length != 1) return null; - Node n = nodes [0]; - //System.out.println("getCurrentLine()..."); - FileObject fo = (FileObject) n.getLookup ().lookup(FileObject.class); - if (fo == null) { - DataObject dobj = (DataObject) n.getLookup().lookup(DataObject.class); - if (dobj != null) { - fo = dobj.getPrimaryFile(); - } - } + private static Line getCurrentLine () { + FileObject fo = EditorContextDispatcher.getDefault().getCurrentFile(); //System.out.println("n = "+n+", FO = "+fo+" => is ANT = "+isAntFile(fo)); if (!isAntFile(fo)) { return null; } - LineCookie lineCookie = (LineCookie) n.getCookie (LineCookie.class); - //System.out.println("line cookie = "+lineCookie); - if (lineCookie == null) return null; - EditorCookie editorCookie = (EditorCookie) n.getCookie (EditorCookie.class); + EditorCookie editorCookie = EditorContextDispatcher.getDefault().getCurrentEditorCookie(); if (editorCookie == null) return null; - JEditorPane jEditorPane = getEditorPane(editorCookie); + JEditorPane jEditorPane = EditorContextDispatcher.getDefault().getCurrentEditor(); if (jEditorPane == null) return null; StyledDocument document = editorCookie.getDocument (); if (document == null) return null; @@ -152,40 +142,13 @@ public class AntBreakpointActionProvider caret.getDot () ); try { - Line.Set lineSet = lineCookie.getLineSet(); - assert lineSet != null : lineCookie; + Line.Set lineSet = editorCookie.getLineSet(); + assert lineSet != null : editorCookie; return lineSet.getCurrent(lineNumber); } catch (IndexOutOfBoundsException ex) { return null; } } - - private static JEditorPane getEditorPane_(EditorCookie editorCookie) { - JEditorPane[] op = editorCookie.getOpenedPanes (); - if ((op == null) || (op.length < 1)) return null; - return op [0]; - } - - private static JEditorPane getEditorPane(final EditorCookie editorCookie) { - if (SwingUtilities.isEventDispatchThread()) { - return getEditorPane_(editorCookie); - } else { - final JEditorPane[] ce = new JEditorPane[1]; - try { - SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - ce[0] = getEditorPane_(editorCookie); - } - }); - } catch (InvocationTargetException ex) { - ErrorManager.getDefault().notify(ex.getTargetException()); - } catch (InterruptedException ex) { - ErrorManager.getDefault().notify(ex); - } - return ce[0]; - } - } - private static boolean isAntFile(FileObject fo) {