changeset: 254477:ef166f0be300 tag: COS tag: qbase user: Andrew Krasny date: Tue May 28 21:24:54 2013 +0400 summary: imported patch COS 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,14 @@ PropertyChangeListener, VetoableChangeListener { /** generated Serialized Version UID */ static final long serialVersionUID = -1934890789745432531L; + + public static DataObject findDataObject(Object env) { + if (env instanceof Env) { + return ((Env)env).getDataObject(); + } + return null; + } + /** object to serialize and be connected to*/ private DataObject obj; 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,109 @@ +/* + * 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; + +/** + * + * @author akrasny + */ +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); + } + + 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); + } } }