diff -r dfca5ea7b2f1 openide.text/src/org/openide/text/CloneableEditor.java --- a/openide.text/src/org/openide/text/CloneableEditor.java Wed Jul 29 15:32:49 2009 +0200 +++ b/openide.text/src/org/openide/text/CloneableEditor.java Tue Aug 04 15:31:47 2009 +0200 @@ -78,6 +78,9 @@ /** Flag indicating it was initialized this CloneableEditor */ private boolean initialized; + /** Flag indicating progress of DoInitialize tasks */ + private boolean initVisualFinished; + /** Position of cursor. Used to keep the value between deserialization * and initialization time. */ private int cursorPosition = -1; @@ -533,6 +536,13 @@ } }); isInInitVisual = false; + initVisualFinished = true; + + //#168415: Notify clients that pane creation is finished. + CloneableEditorSupport ces = cloneableEditorSupport(); + if (ces != null) { + ces.firePropertyChange(EditorCookie.Observable.PROP_OPENED_PANES, null, null); + } } private void initRest() { @@ -593,6 +603,7 @@ customToolbar = null; pane = null; initialized = false; + initVisualFinished = false; } } ); @@ -921,6 +932,15 @@ return this; } + /** + * #168415: Returns true if creation of editor pane is finished. It is used + * to avoid blocking AWT thread by call of getEditorPane. + */ + boolean isEditorPaneReady () { + assert SwingUtilities.isEventDispatchThread(); + return initVisualFinished; + } + public JEditorPane getEditorPane() { assert SwingUtilities.isEventDispatchThread(); initialize(); diff -r dfca5ea7b2f1 openide.text/src/org/openide/text/CloneableEditorSupport.java --- a/openide.text/src/org/openide/text/CloneableEditorSupport.java Wed Jul 29 15:32:49 2009 +0200 +++ b/openide.text/src/org/openide/text/CloneableEditorSupport.java Tue Aug 04 15:31:47 2009 +0200 @@ -1092,6 +1092,54 @@ return ll.isEmpty() ? null : ll.toArray(new JEditorPane[ll.size()]); } + /** + * Gets editor pane opened by this support for TopComponent + * Can be called from AWT event thread only. It is nonblocking. It returns either pane + * if pane intialization is finished or null if initialization is still in progress. + * + * @param tc TopComponent for which pane is returned + * @return pane or null + * + */ + JEditorPane getOpenedPaneForTC (TopComponent tc) { + // expected in AWT only + assert SwingUtilities.isEventDispatchThread() + : "CloneableEditorSupport.getOpenedPaneForTC must be called from AWT thread only"; // NOI18N + CloneableEditorSupport redirect = CloneableEditorSupportRedirector.findRedirect(this); + if (redirect != null) { + return redirect.getOpenedPaneForTC(tc); + } + + Enumeration en = allEditors.getComponents(); + + while (en.hasMoreElements()) { + CloneableTopComponent ctc = (CloneableTopComponent) en.nextElement(); + if (ctc == tc) { + Pane ed = (Pane) ctc.getClientProperty(PROP_PANE); + + if ((ed == null) && ctc instanceof Pane) { + ed = (Pane) ctc; + } + + if (ed != null) { + JEditorPane p = null; + if (ed instanceof CloneableEditor) { + if (((CloneableEditor) ed).isEditorPaneReady()) { + p = ed.getEditorPane(); + } + } else { + p = ed.getEditorPane(); + } + return p; + } else { + throw new IllegalStateException("No reference to Pane. Please file a bug against openide/text"); + } + } + } + + return null; + } + /** Returns the lastly selected Pane or null */ final Pane getLastSelected() { diff -r dfca5ea7b2f1 openide.text/src/org/openide/text/NbDocument.java --- a/openide.text/src/org/openide/text/NbDocument.java Wed Jul 29 15:32:49 2009 +0200 +++ b/openide.text/src/org/openide/text/NbDocument.java Tue Aug 04 15:31:47 2009 +0200 @@ -43,12 +43,13 @@ import java.awt.Color; import java.awt.Component; -import java.beans.*; import javax.swing.JEditorPane; import javax.swing.JToolBar; import javax.swing.SwingUtilities; import javax.swing.text.*; +import org.openide.cookies.EditorCookie; +import org.openide.windows.TopComponent; /** Dummy class holding utility methods for working with NetBeans document conventions. @@ -367,7 +368,38 @@ doc.setLogicalStyle(offset, st); } } - + + /** + * Gets editor pane opened by editor cookie for TopComponent + * Can be called from AWT event thread only. + * + * @param ec EditorCookie used to find out editor pane for active TopComponent + * @param tc TopComponent for which pane is returned + * @return pane or null + * + */ + public static JEditorPane findEditorPaneForActiveTC(EditorCookie ec, TopComponent tc) { + // expected in AWT only + assert SwingUtilities.isEventDispatchThread() + : "NbDocument.findInitializedPaneForActiveTC must be called from AWT thread only"; // NOI18N + if (ec instanceof CloneableEditorSupport) { + // find if initialized or return null immediately + CloneableEditorSupport ces = (CloneableEditorSupport) ec; + JEditorPane pane = ces.getOpenedPaneForTC(tc); + return pane; + } else { + JEditorPane [] panes = ec.getOpenedPanes(); + if (panes != null) { + for (JEditorPane pane : panes) { + if (tc.isAncestorOf(pane)) { + return pane; + } + } + } + return null; + } + } + /** Locks the document to have exclusive access to it. * Documents implementing {@link Lockable} can specify exactly how to do this. * diff -r dfca5ea7b2f1 spi.debugger.ui/src/org/netbeans/spi/debugger/ui/EditorContextDispatcher.java --- a/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/EditorContextDispatcher.java Wed Jul 29 15:32:49 2009 +0200 +++ b/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/EditorContextDispatcher.java Tue Aug 04 15:31:47 2009 +0200 @@ -588,7 +588,7 @@ } } - private void updateCurrentOpenedPane(TopComponent activeComponnet, Object source) { + private void updateCurrentOpenedPane(TopComponent activeComponent, Object source) { JEditorPane oldEditor = null; JEditorPane newEditor = null; String MIMEType = null; @@ -597,7 +597,7 @@ EditorCookie ec = currentEditorCookie.get(); if ((source == null || source == ec)) { oldEditor = currentOpenedPane.get(); - if (ec != null && activeComponnet != null) { + if (ec != null && activeComponent != null) { if (ec.getDocument() == null && // !currentEditorCookie.prepareDocument().isFinished() && (ec instanceof EditorCookie.Observable)) { // Document is not yet loaded, wait till we're notified that it is. @@ -607,18 +607,12 @@ } logger.fine("Document " + ec + " loaded, updating..."); // NOI18N long t1 = System.nanoTime(); - JEditorPane[] openedPanes = ec.getOpenedPanes(); + JEditorPane openedPane = NbDocument.findEditorPaneForActiveTC(ec, activeComponent); long t2 = System.nanoTime(); logger.fine("Time to find opened panes = "+(t2 - t1)+" ns = "+(t2 - t1)/1000000+" ms."); // NOI18N - if (openedPanes != null && openedPanes.length >= 1) { - for (JEditorPane openedPane : openedPanes) { - if (activeComponnet.isAncestorOf(openedPane)) { - //System.err.println("\n"+newComponnet+".isAncestorOf("+openedPane+")\n"); - newEditor = openedPane; - isSetPane = true; - break; - } - } + if (openedPane != null) { + newEditor = openedPane; + isSetPane = true; } } if (!isSetPane && source == null) {