1 /* 2 * The contents of this file are subject to the terms of the Common Development 3 * and Distribution License (the License). You may not use this file except in 4 * compliance with the License. 5 * 6 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html 7 * or http://www.netbeans.org/cddl.txt. 8 * 9 * When distributing Covered Code, include this CDDL Header Notice in each file 10 * and include the License file at http://www.netbeans.org/cddl.txt. 11 * If applicable, add the following below the CDDL Header, with the fields 12 * enclosed by brackets [] replaced by your own identifying information: 13 * "Portions Copyrighted [year] [name of copyright owner]" 14 * 15 * The Original Software is NetBeans. 16 * Portions Copyrighted 2007 Sun Microsystems, Inc. 17 */ 18 package org.openide.text; 19 20 import org.openide.util.Lookup; 21 22 /** 23 * Allows to find another {@link CloneableEditorSupport} that all the 24 * requests passed to given one should be redirected to. This is useful 25 * for redirecting operation on <a HREF="@org-openide-filesystems@/org/openide/filesystems/FileObject.html"> 26 * FileObject</a> to another one in cases when two <code>FileObject</code>s 27 * represent the same physical file. 28 * <p> 29 * Instances should be registered to default lookup. 30 * @author Jaroslav Tulach 31 * @since 6.13 32 */ 33 public abstract class CloneableEditorSupportRedirector { 34 /** Find a delegate for given {@link CloneableEditorSupport}'s {@link Lookup}. 35 * The common code can be to extract for example a 36 * <a HREF="@org-openide-filesystems@/org/openide/filesystems/FileObject.html"> 37 * FileObject</a> from the lookup and use its location to find another 38 * <code>CloneableEditorSupport</code> to delegate to. 39 * 40 * @param env the environment associated with current CloneableEditorSupport 41 * @return null or another CloneableEditorSupport to use as a replacement 42 */ 43 protected abstract CloneableEditorSupport redirect(Lookup env); 44 45 static CloneableEditorSupport findRedirect(CloneableEditorSupport one) { 46 for (CloneableEditorSupportRedirector r : Lookup.getDefault().lookupAll(CloneableEditorSupportRedirector.class)) { 47 CloneableEditorSupport ces = r.redirect(one.getLookup()); 48 if (ces != null && ces != one) { 49 return ces; 50 } 51 } 52 return null; 53 } 54 } 55 56 57