FileObject
s
+ * represent the same physical file.
+ *
+ * @author Jaroslav Tulach
+ * @since 6.13
+ */
+ public abstract class CloneableEditorSupportRedirector {
+ /** Find a delegate for given {@link CloneableEditorSupport}'s {@link Lookup}.
+ * The common code can be to extract for example a
+ *
+ * FileObject from the lookup and use its location to find another
+ * CloneableEditorSupport
to delegate to.
+ *
+ * @param env the environment associated with current CloneableEditorSupport
+ * @return null or another CloneableEditorSupport to use as a replacement
+ */
+ protected abstract CloneableEditorSupport redirect(Lookup env);
+
+ static CloneableEditorSupport findRedirect(CloneableEditorSupport one) {
+ for (CloneableEditorSupportRedirector r : Lookup.getDefault().lookupAll(CloneableEditorSupportRedirector.class)) {
+ CloneableEditorSupport ces = r.redirect(one.getLookup());
+ if (ces != null && ces != one) {
+ return ces;
+ }
+ }
+ return null;
+ }
+ }
+
+
Index: test/unit/src/org/openide/text/CloneableEditorSupportRedirectorTest.java
*** /doma/jarda/netbeans-src/openide/text/test/unit/src/org/openide/text/CloneableEditorSupportRedirectorTest.java No Base Revision
--- /doma/jarda/netbeans-src/openide/text/test/unit/src/org/openide/text/CloneableEditorSupportRedirectorTest.java Locally New
***************
*** 1,0 ****
--- 1,334 ----
+ /*
+ * The contents of this file are subject to the terms of the Common Development
+ * and Distribution License (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.html
+ * or http://www.netbeans.org/cddl.txt.
+ *
+ * When distributing Covered Code, include this CDDL Header Notice in each file
+ * and include the License file at http://www.netbeans.org/cddl.txt.
+ * If applicable, add the following below the CDDL Header, with the fields
+ * enclosed by brackets [] replaced by your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * The Original Software is NetBeans.
+ * Portions Copyrighted 2007 Sun Microsystems, Inc.
+ */
+ package org.openide.text;
+
+ import java.beans.PropertyChangeListener;
+ import java.io.ByteArrayOutputStream;
+ import java.io.IOException;
+ import java.io.InputStream;
+ import java.lang.ref.WeakReference;
+ import java.util.Arrays;
+ import javax.swing.SwingUtilities;
+ import javax.swing.text.Document;
+ import javax.swing.text.EditorKit;
+ import junit.framework.Test;
+ import junit.framework.TestSuite;
+ import org.netbeans.junit.MockServices;
+ import org.netbeans.junit.NbTestCase;
+ import org.netbeans.junit.NbTestSuite;
+ import org.openide.util.Exceptions;
+ import org.openide.util.Lookup;
+ import org.openide.util.lookup.AbstractLookup;
+ import org.openide.util.lookup.InstanceContent;
+
+ /**
+ *
+ * @author Jaroslav Tulach
+ */
+ public class CloneableEditorSupportRedirectorTest extends NbTestCase
+ implements CloneableEditorSupport.Env {
+ /** the content of lookup of support */
+ private InstanceContent ic;
+ Redirector red;
+
+
+ // Env variables
+ private String content = "";
+ private boolean valid = true;
+ private boolean modified = false;
+ /** if not null contains message why this document cannot be modified */
+ private String cannotBeModified;
+ private java.util.Date date = new java.util.Date ();
+ private java.util.ListThe CloneableEditorSupportRedirector
+ class allows a redirection of operations on a CloneableEditorSupport
+ object to another one. This can be useful if there are two logical
+ files representing one physical and one wants to have just a single
+ editor for both files. In such case just implement the
+ CloneableEditorSupportRedirector.
+
null
if it is not yet loaded
*/
public StyledDocument getDocument() {
+ CloneableEditorSupport redirect = CloneableEditorSupportRedirector.findRedirect(this);
+ if (redirect != null) {
+ return redirect.getDocument();
+ }
synchronized (getLock()) {
while (true) {
switch (documentStatus) {
***************
*** 722,727 ****
--- 745,754 ----
* otherwise false
*/
public boolean isModified() {
+ CloneableEditorSupport redirect = CloneableEditorSupportRedirector.findRedirect(this);
+ if (redirect != null) {
+ return redirect.isModified();
+ }
return cesEnv().isModified();
}
***************
*** 730,735 ****
--- 757,767 ----
* @exception IOException on I/O error
*/
public void saveDocument() throws IOException {
+ CloneableEditorSupport redirect = CloneableEditorSupportRedirector.findRedirect(this);
+ if (redirect != null) {
+ redirect.saveDocument();
+ return;
+ }
// #17714: Don't try to save unmodified doc.
if (!cesEnv().isModified()) {
return;
***************
*** 834,839 ****
--- 866,875 ----
public JEditorPane[] getOpenedPanes() {
// expected in AWT only
assert SwingUtilities.isEventDispatchThread(); // NOI18N
+ CloneableEditorSupport redirect = CloneableEditorSupportRedirector.findRedirect(this);
+ if (redirect != null) {
+ return redirect.getOpenedPanes();
+ }
LinkedListtrue
if document is loaded
*/
public boolean isDocumentLoaded() {
+ CloneableEditorSupport redirect = CloneableEditorSupportRedirector.findRedirect(this);
+ if (redirect != null) {
+ return redirect.isDocumentLoaded();
+ }
return documentStatus != DOCUMENT_NO;
}
***************
*** 1133,1138 ****
--- 1182,1192 ----
* @param s the new MIME type
*/
public void setMIMEType(String s) {
+ CloneableEditorSupport redirect = CloneableEditorSupportRedirector.findRedirect(this);
+ if (redirect != null) {
+ redirect.setMIMEType(s);
+ return;
+ }
mimeType = s;
}
***************
*** 1227,1232 ****
--- 1281,1290 ----
* @since 4.7
*/
public InputStream getInputStream() throws IOException {
+ CloneableEditorSupport redirect = CloneableEditorSupportRedirector.findRedirect(this);
+ if (redirect != null) {
+ return redirect.getInputStream();
+ }
// Implementation note
// Piped stream will not work, as we are in the same thread
// Doing this in a different thread would need to lock the document for
***************
*** 1780,1785 ****
--- 1838,1848 ----
* @return false
if the operation is cancelled
*/
protected boolean close(boolean ask) {
+ CloneableEditorSupport redirect = CloneableEditorSupportRedirector.findRedirect(this);
+ if (redirect != null) {
+ return redirect.close(ask);
+ }
+
if (!super.close(ask)) {
// if not all editors has been closed
return false;
***************
*** 2054,2059 ****
--- 2117,2126 ----
* @since 5.2
*/
protected final Pane openAt(final PositionRef pos, final int column) {
+ CloneableEditorSupport redirect = CloneableEditorSupportRedirector.findRedirect(this);
+ if (redirect != null) {
+ return redirect.openAt(pos, column);
+ }
final Pane e = openPane();
final Task t = prepareDocument();
e.ensureVisible();
Index: manifest.mf
*** /doma/jarda/netbeans-src/openide/text/manifest.mf Base (1.14)
--- /doma/jarda/netbeans-src/openide/text/manifest.mf Locally Modified (Based On 1.14)
***************
*** 1,5 ****
Manifest-Version: 1.0
OpenIDE-Module: org.openide.text
! OpenIDE-Module-Specification-Version: 6.12
OpenIDE-Module-Localizing-Bundle: org/openide/text/Bundle.properties
--- 1,5 ----
Manifest-Version: 1.0
OpenIDE-Module: org.openide.text
! OpenIDE-Module-Specification-Version: 6.13
OpenIDE-Module-Localizing-Bundle: org/openide/text/Bundle.properties