+ Add NbDocument.findRecentEditorPane to allow non blocking retrieval of recently selected editor pane. + Method returns null when editor pane initialization is not finished. Client is notified about finished pane + initialization by property change event EditorCookie.Observable.PROP_OPENED_PANES. + NbDocument.findRecentEditorPane is replacement for EditorCookie.getOpenedPanes which waits till all editor + panes are initialized. It is nonblocking only when EditorCookie is instanceof CloneableEditorSupport. +
+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 Wed Aug 12 16:52:17 2009 +0200
@@ -1092,6 +1092,53 @@
return ll.isEmpty() ? null : ll.toArray(new JEditorPane[ll.size()]);
}
+ /**
+ * Gets recently selected editor pane opened by this support
+ * 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.
+ *
+ * @return pane or null
+ *
+ */
+ JEditorPane getRecentPane () {
+ // 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.getRecentPane();
+ }
+
+ Enumeration en = allEditors.getComponents();
+
+ while (en.hasMoreElements()) {
+ CloneableTopComponent ctc = (CloneableTopComponent) en.nextElement();
+ Pane ed = (Pane) ctc.getClientProperty(PROP_PANE);
+
+ if ((ed == null) && ctc instanceof Pane) {
+ ed = (Pane) ctc;
+ }
+
+ if (ed != null) {
+ JEditorPane p = null;
+ if (getLastSelected() == ed) {
+ 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 Wed Aug 12 16:52:17 2009 +0200
@@ -43,12 +43,12 @@
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;
/** Dummy class holding utility methods for working with NetBeans document conventions.
@@ -367,7 +367,34 @@
doc.setLogicalStyle(offset, st);
}
}
-
+
+ /**
+ * Gets recently selected editor pane opened by editor cookie
+ * Can be called from AWT event thread only.
+ *
+ * @param ec EditorCookie used to find out recently selected editor pane
+ * @return pane or null
+ *
+ * @since 6.24
+ *
+ */
+ public static JEditorPane findRecentEditorPane (EditorCookie ec) {
+ // 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
+ JEditorPane pane = ((CloneableEditorSupport) ec).getRecentPane();
+ return pane;
+ } else {
+ JEditorPane [] panes = ec.getOpenedPanes();
+ if (panes != null) {
+ return panes[0];
+ }
+ 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 openide.text/test/unit/src/org/openide/text/CloneableEditorCreationFinishedTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/openide.text/test/unit/src/org/openide/text/CloneableEditorCreationFinishedTest.java Wed Aug 12 16:52:17 2009 +0200
@@ -0,0 +1,253 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * The Original Software is NetBeans. The Initial Developer of the Original
+ * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ */
+
+package org.openide.text;
+
+
+import java.beans.*;
+import java.io.*;
+import java.util.*;
+import javax.swing.JEditorPane;
+import javax.swing.text.EditorKit;
+import org.netbeans.junit.NbTestCase;
+import org.openide.cookies.EditorCookie;
+import org.openide.util.Exceptions;
+import org.openide.util.Lookup;
+import org.openide.windows.*;
+
+public class CloneableEditorCreationFinishedTest extends NbTestCase
+implements CloneableEditorSupport.Env {
+ static {
+ System.setProperty("org.openide.windows.DummyWindowManager.VISIBLE", "false");
+ }
+ /** the support to work with */
+ private transient CES support;
+
+ // Env variables
+ private transient String content = "";
+ private transient boolean valid = true;
+ private transient boolean modified = false;
+ /** if not null contains message why this document cannot be modified */
+ private transient String cannotBeModified;
+ private transient Date date = new Date ();
+ private transient List/*