diff -r 766e8327016d ruby.debugger/src/org/netbeans/modules/ruby/debugger/EditorUtil.java --- a/ruby.debugger/src/org/netbeans/modules/ruby/debugger/EditorUtil.java Fri Jun 06 19:28:24 2008 +0200 +++ b/ruby.debugger/src/org/netbeans/modules/ruby/debugger/EditorUtil.java Wed Jun 11 17:38:04 2008 +0200 @@ -43,22 +43,19 @@ package org.netbeans.modules.ruby.debugg import java.awt.EventQueue; import java.io.File; -import java.lang.reflect.InvocationTargetException; import java.util.logging.Level; import javax.swing.JEditorPane; -import javax.swing.SwingUtilities; import javax.swing.text.Caret; import javax.swing.text.StyledDocument; +import org.netbeans.spi.debugger.ui.EditorContextDispatcher; import org.openide.cookies.EditorCookie; import org.openide.cookies.LineCookie; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.loaders.DataObject; import org.openide.loaders.DataObjectNotFoundException; -import org.openide.nodes.Node; import org.openide.text.Line; import org.openide.text.NbDocument; -import org.openide.windows.TopComponent; public final class EditorUtil { @@ -167,26 +164,14 @@ public final class EditorUtil { * supported mime-types}. For unsupported ones returns null. */ public static Line getCurrentLine() { - Node[] nodes = TopComponent.getRegistry().getCurrentNodes(); - if (nodes == null) return null; - if (nodes.length != 1) return null; - Node n = nodes [0]; - FileObject fo = n.getLookup().lookup(FileObject.class); - if (fo == null) { - DataObject dobj = n.getLookup().lookup(DataObject.class); - if (dobj != null) { - fo = dobj.getPrimaryFile(); - } - } + FileObject fo = EditorContextDispatcher.getDefault().getCurrentFile(); if (fo == null) { return null; } if (!Util.isRubySource(fo)) { return null; } - LineCookie lineCookie = n.getCookie(LineCookie.class); - if (lineCookie == null) return null; - 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; @@ -194,40 +179,14 @@ public final class EditorUtil { if (caret == null) return null; int lineNumber = NbDocument.findLineNumber(document, 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 { - EventQueue.invokeAndWait(new Runnable() { - public void run() { - ce[0] = getEditorPane_(editorCookie); - } - }); - } catch (InvocationTargetException ex) { - Util.severe(ex); - } catch (InterruptedException ex) { - Util.severe(ex); - Thread.currentThread().interrupt(); - } - return ce[0]; - } - } // } diff -r 766e8327016d ruby.debugger/src/org/netbeans/modules/ruby/debugger/ToolTipAnnotation.java --- a/ruby.debugger/src/org/netbeans/modules/ruby/debugger/ToolTipAnnotation.java Fri Jun 06 19:28:24 2008 +0200 +++ b/ruby.debugger/src/org/netbeans/modules/ruby/debugger/ToolTipAnnotation.java Wed Jun 11 17:38:04 2008 +0200 @@ -42,23 +42,19 @@ package org.netbeans.modules.ruby.debugg package org.netbeans.modules.ruby.debugger; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; import javax.swing.JEditorPane; -import javax.swing.SwingUtilities; import javax.swing.text.BadLocationException; import javax.swing.text.Element; import javax.swing.text.StyledDocument; -import org.openide.ErrorManager; +import org.netbeans.spi.debugger.ui.EditorContextDispatcher; import org.openide.cookies.EditorCookie; import org.openide.loaders.DataObject; -import org.openide.nodes.Node; import org.openide.text.Annotation; import org.openide.text.DataEditorSupport; import org.openide.text.Line; import org.openide.text.Line.Part; import org.openide.text.NbDocument; import org.openide.util.RequestProcessor; -import org.openide.windows.TopComponent; import org.rubyforge.debugcommons.model.RubyValue; import org.rubyforge.debugcommons.model.RubyVariable; @@ -91,7 +87,7 @@ public final class ToolTipAnnotation ext } catch (IOException ex) { return; } - JEditorPane ep = getCurrentEditor(); + JEditorPane ep = EditorContextDispatcher.getDefault().getCurrentEditor(); if (ep == null) { return; } String expression = getIdentifier(doc, ep, NbDocument.findLineOffset(doc, lp.getLine().getLineNumber()) + lp.getColumn()); if (expression == null) { return; } @@ -155,48 +151,5 @@ public final class ToolTipAnnotation ext return ch == '@' || ch == '?' || Character.isJavaIdentifierPart(ch); } - /** Returns current editor component instance. */ - 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]; - } - - private 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 n.getCookie(EditorCookie.class); - } - } diff -r 766e8327016d ruby.debugger/src/org/netbeans/modules/ruby/debugger/Util.java --- a/ruby.debugger/src/org/netbeans/modules/ruby/debugger/Util.java Fri Jun 06 19:28:24 2008 +0200 +++ b/ruby.debugger/src/org/netbeans/modules/ruby/debugger/Util.java Wed Jun 11 17:38:04 2008 +0200 @@ -59,8 +59,8 @@ public final class Util { public static final Logger LOGGER = Logger.getLogger(Util.class.getName()); - private static final String RUBY_MIME_TYPE = "text/x-ruby"; // NOI18N - private static final String ERB_MIME_TYPE = "application/x-httpd-eruby"; // NOI18N + public static final String RUBY_MIME_TYPE = "text/x-ruby"; // NOI18N + public static final String ERB_MIME_TYPE = "application/x-httpd-eruby"; // NOI18N private Util() { /* do not allow instances */ } diff -r 766e8327016d ruby.debugger/src/org/netbeans/modules/ruby/debugger/breakpoints/RubyBreakpointActionProvider.java --- a/ruby.debugger/src/org/netbeans/modules/ruby/debugger/breakpoints/RubyBreakpointActionProvider.java Fri Jun 06 19:28:24 2008 +0200 +++ b/ruby.debugger/src/org/netbeans/modules/ruby/debugger/breakpoints/RubyBreakpointActionProvider.java Wed Jun 11 17:38:04 2008 +0200 @@ -51,9 +51,9 @@ import org.netbeans.modules.ruby.debugge import org.netbeans.modules.ruby.debugger.EditorUtil; import org.netbeans.modules.ruby.debugger.Util; import org.netbeans.spi.debugger.ActionsProviderSupport; +import org.netbeans.spi.debugger.ui.EditorContextDispatcher; import org.openide.text.Line; import org.openide.util.WeakListeners; -import org.openide.windows.TopComponent; import org.rubyforge.debugcommons.RubyDebuggerException; /** @@ -67,8 +67,9 @@ public final class RubyBreakpointActionP public RubyBreakpointActionProvider() { setEnabled(ActionsManager.ACTION_TOGGLE_BREAKPOINT, true); - TopComponent.getRegistry().addPropertyChangeListener( - WeakListeners.propertyChange(this, TopComponent.getRegistry())); + PropertyChangeListener l = WeakListeners.propertyChange(this, EditorContextDispatcher.getDefault()); + EditorContextDispatcher.getDefault().addPropertyChangeListener(Util.RUBY_MIME_TYPE, l); + EditorContextDispatcher.getDefault().addPropertyChangeListener(Util.ERB_MIME_TYPE, l); } @Override