changeset: 257799:e9f7efe7e261 tag: COS-230126 tag: qbase tag: qtip tag: tip user: Andrew Krasny date: Tue Jul 02 15:53:42 2013 +0400 summary: [mq]: COS-230126 diff --git a/openide.loaders/src/org/openide/loaders/OpenSupport.java b/openide.loaders/src/org/openide/loaders/OpenSupport.java --- a/openide.loaders/src/org/openide/loaders/OpenSupport.java +++ b/openide.loaders/src/org/openide/loaders/OpenSupport.java @@ -134,6 +134,7 @@ PropertyChangeListener, VetoableChangeListener { /** generated Serialized Version UID */ static final long serialVersionUID = -1934890789745432531L; + /** object to serialize and be connected to*/ private DataObject obj; diff --git a/openide.windows/manifest.mf b/openide.windows/manifest.mf --- a/openide.windows/manifest.mf +++ b/openide.windows/manifest.mf @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.openide.windows -OpenIDE-Module-Specification-Version: 6.64 +OpenIDE-Module-Specification-Version: 6.65 OpenIDE-Module-Localizing-Bundle: org/openide/windows/Bundle.properties AutoUpdate-Essential-Module: true diff --git a/openide.windows/src/org/openide/windows/CloneableOpenSupport.java b/openide.windows/src/org/openide/windows/CloneableOpenSupport.java --- a/openide.windows/src/org/openide/windows/CloneableOpenSupport.java +++ b/openide.windows/src/org/openide/windows/CloneableOpenSupport.java @@ -94,6 +94,11 @@ * @see #openCloneableTopComponent */ public void open() { + CloneableOpenSupport redirect = CloneableOpenSupportRedirector.findRedirect(this); + if (redirect != null) { + redirect.open(); + return; + } //Bugfix #10688 open() is now run in AWT thread Mutex.EVENT.writeAccess( new Runnable() { diff --git a/openide.windows/src/org/openide/windows/CloneableOpenSupportRedirector.java b/openide.windows/src/org/openide/windows/CloneableOpenSupportRedirector.java new file mode 100644 --- /dev/null +++ b/openide.windows/src/org/openide/windows/CloneableOpenSupportRedirector.java @@ -0,0 +1,121 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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]" + * + * 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. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.openide.windows; + +import java.util.Collection; +import java.util.concurrent.atomic.AtomicReference; +import org.openide.util.Lookup; +import org.openide.util.LookupEvent; +import org.openide.util.LookupListener; + +/** + * Allows to find another {@link CloneableOpenSupport} that all the + * requests passed to given one should be redirected to. This is useful + * for redirecting operation on + * FileObject to another one in cases when two FileObjects + * represent the same physical file. + *

+ * Instances should be registered to default lookup. + * @author akrasny + * @since 6.65 + */ +public abstract class CloneableOpenSupportRedirector { + + private static final Lookup.Result lkp = Lookup.getDefault().lookup(new Lookup.Template<>(CloneableOpenSupportRedirector.class)); + private static final AtomicReference> redirectors = new AtomicReference<>(); + private static final LookupListener listener = new LookupListener() { + @Override + public void resultChanged(LookupEvent ev) { + redirectors.set(lkp.allInstances()); + } + }; + + static { + lkp.addLookupListener(listener); + listener.resultChanged(null); + } + + /** Find a delegate for given {@link CloneableOpenSupport}'s {@link CloneableOpenSupport.Env}. + * + * @param env the environment associated with current CloneableOpenSupport + * @return null or another CloneableOpenSupport to use as a replacement + */ + protected abstract CloneableOpenSupport redirect(CloneableOpenSupport.Env env); + + protected abstract void opened(CloneableOpenSupport.Env env); + + protected abstract void closed(CloneableOpenSupport.Env env); + + static CloneableOpenSupport findRedirect(CloneableOpenSupport one) { + final CloneableOpenSupport.Env env = one.env; + Collection rlist = redirectors.get(); + if (rlist != null) { + for (CloneableOpenSupportRedirector r : rlist) { + CloneableOpenSupport ces = r.redirect(env); + if (ces != null && ces != one) { + return ces; + } + } + } + return null; + } + + static void notifyOpened(CloneableOpenSupport one) { + final CloneableOpenSupport.Env env = one.env; + Collection rlist = redirectors.get(); + if (rlist != null) { + for (CloneableOpenSupportRedirector r : rlist) { + r.opened(env); + } + } + } + + static void notifyClosed(CloneableOpenSupport one) { + final CloneableOpenSupport.Env env = one.env; + Collection rlist = redirectors.get(); + if (rlist != null) { + for (CloneableOpenSupportRedirector r : rlist) { + r.closed(env); + } + } + } +} diff --git a/openide.windows/src/org/openide/windows/CloneableTopComponent.java b/openide.windows/src/org/openide/windows/CloneableTopComponent.java --- a/openide.windows/src/org/openide/windows/CloneableTopComponent.java +++ b/openide.windows/src/org/openide/windows/CloneableTopComponent.java @@ -191,6 +191,10 @@ protected void componentOpened() { super.componentOpened(); getReference().register(this); + CloneableOpenSupport cos = getLookup().lookup(CloneableOpenSupport.class); + if (cos != null) { + CloneableOpenSupportRedirector.notifyOpened(cos); + } } /** Overrides superclass method, adds unregistering from references. @@ -199,7 +203,14 @@ super.componentClosed(); if (!isOpened()) { - getReference().unregister(this); + try { + CloneableOpenSupport cos = getLookup().lookup(CloneableOpenSupport.class); + if (cos != null) { + CloneableOpenSupportRedirector.notifyClosed(cos); + } + } finally { + getReference().unregister(this); + } } }