diff -r 9136c35a2fd8 openide.loaders/apichanges.xml --- a/openide.loaders/apichanges.xml Wed Nov 04 18:52:34 2009 +0100 +++ b/openide.loaders/apichanges.xml Thu Nov 05 16:16:48 2009 +0100 @@ -106,6 +106,22 @@ + + + New constructor of XMLDataObject + + + + + +

+ New constructor for subclasses of XMLDataObject. +

+
+ + +
Added annotateName and toolTip to DataEditorSupport diff -r 9136c35a2fd8 openide.loaders/manifest.mf --- a/openide.loaders/manifest.mf Wed Nov 04 18:52:34 2009 +0100 +++ b/openide.loaders/manifest.mf Thu Nov 05 16:16:48 2009 +0100 @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.openide.loaders -OpenIDE-Module-Specification-Version: 7.9 +OpenIDE-Module-Specification-Version: 7.10 OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties OpenIDE-Module-Recommends: org.netbeans.modules.templates.v1_0 AutoUpdate-Essential-Module: true diff -r 9136c35a2fd8 openide.loaders/src/org/openide/loaders/XMLDataObject.java --- a/openide.loaders/src/org/openide/loaders/XMLDataObject.java Wed Nov 04 18:52:34 2009 +0100 +++ b/openide.loaders/src/org/openide/loaders/XMLDataObject.java Thu Nov 05 16:16:48 2009 +0100 @@ -169,30 +169,50 @@ * * @param fo the primary file object, never null * @param loader loader of this data object, never null - * */ public XMLDataObject (FileObject fo, MultiFileLoader loader) throws DataObjectExistsException { + this(fo, loader, true); + } + + /** + * Constructs XMLDataObject without any registered cookies (for editor, + * open, etc.). Useful for subclasses. + * + * @param fo the primary file object, never null + * @param loader loader of this data object, never null + * @param registerEditor call with false to skip registrations of various + * editor related cookies + * @since 7.10 + */ + protected XMLDataObject (FileObject fo, MultiFileLoader loader, boolean registerEditor) + throws DataObjectExistsException { super (fo, loader); fo.addFileChangeListener (FileUtil.weakFileChangeListener (getIP (), fo)); status = STATUS_NOT; + if (registerEditor) { + registerEditor(); + } + } + + private void registerEditor() { // register provided cookies // EditorCookie must be for back compatability consulted with subclasses // // In new model subclasses should directly provide its CookieSet.Factory that // uses last prevails order instead of old CookieSet first prevails order. // It completely prevails over this factory :-) - + CookieSet.Factory factory = new CookieSet.Factory() { public T createCookie(Class klass) { if (klass.isAssignableFrom(EditorCookie.class) - || klass.isAssignableFrom(OpenCookie.class) - || klass.isAssignableFrom(CloseCookie.class) + || klass.isAssignableFrom(OpenCookie.class) + || klass.isAssignableFrom(CloseCookie.class) || klass.isAssignableFrom(PrintCookie.class) ) { - + if (editor == null) editor = createEditorCookie(); // the first pass if (editor == null) return null; //??? gc unfriendly @@ -202,15 +222,15 @@ } } }; - + CookieSet cookies = getCookieSet(); - // EditorCookie.class must be synchronized with + // EditorCookie.class must be synchronized with // XMLEditor.Env->findCloneableOpenSupport cookies.add(EditorCookie.class, factory); cookies.add(OpenCookie.class, factory); cookies.add(CloseCookie.class, factory); cookies.add(PrintCookie.class, factory); - + // set info for this file //getIP ().resolveInfo (); #16045 cookies.assign( SaveAsCapable.class, new SaveAsCapable() { diff -r 9136c35a2fd8 openide.loaders/test/unit/src/org/openide/loaders/XMLDataObjectSubclassTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openide.loaders/test/unit/src/org/openide/loaders/XMLDataObjectSubclassTest.java Thu Nov 05 16:16:48 2009 +0100 @@ -0,0 +1,149 @@ +/* + * 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.loaders; + +import java.util.Enumeration; +import org.openide.filesystems.*; +import java.io.*; +import java.lang.ref.Reference; +import java.lang.ref.WeakReference; +import java.security.Permission; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.logging.Level; +import junit.framework.Assert; +import org.netbeans.junit.Log; +import org.netbeans.junit.MockServices; +import org.netbeans.junit.RandomlyFails; +import org.openide.cookies.*; +import org.openide.loaders.MultiDataObject.Entry; +import org.openide.nodes.Node; +import org.openide.util.Enumerations; +import org.openide.util.RequestProcessor; +import org.openide.xml.XMLUtil; +import org.xml.sax.InputSource; +import org.xml.sax.SAXParseException; + +/** + * + * @author Jaroslav Tulach + */ +public class XMLDataObjectSubclassTest extends org.netbeans.junit.NbTestCase { + private FileObject data; + private CharSequence log; + + public XMLDataObjectSubclassTest (String name) { + super (name); + } + + @Override + protected void setUp () throws Exception { + clearWorkDir(); + MockServices.setServices(Pool.class); + + log = Log.enable("org.openide.loaders", Level.WARNING); + + super.setUp (); + String fsstruct [] = new String [] { + }; + FileSystem fs = TestUtilHid.createLocalFileSystem (getWorkDir(), fsstruct); + data = FileUtil.createData ( + fs.getRoot (), + "kuk/test/my.xml" + ); + FileLock lock = data.lock (); + OutputStream os = data.getOutputStream (lock); + PrintStream p = new PrintStream (os); + + p.println (""); + p.println (""); + p.println (""); + + p.close (); + lock.releaseLock (); + + } + + public void testCheckNoCookies() throws Exception { + DataObject obj = DataObject.find(data); + assertEquals("Correct obj type", MyXMLObject.class, obj.getClass()); + + assertNull("No open cookie", obj.getLookup().lookup(OpenCookie.class)); + assertNull("No edit cookie", obj.getLookup().lookup(EditCookie.class)); + assertNull("No print cookie", obj.getLookup().lookup(PrintCookie.class)); + assertNull("No close cookie", obj.getLookup().lookup(CloseCookie.class)); + } + + public static final class Pool extends DataLoaderPool { + + @Override + protected Enumeration loaders() { + return Enumerations.singleton(DataLoader.getLoader(MyXMLLoader.class)); + } + } + + public static final class MyXMLLoader extends UniFileLoader { + + public MyXMLLoader() { + super(MyXMLObject.class.getName()); + getExtensions().addExtension("xml"); + } + + @Override + protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException { + return new MyXMLObject(primaryFile, this); + } + } + + public static final class MyXMLObject extends XMLDataObject { + + public MyXMLObject(FileObject fo, MultiFileLoader loader) throws DataObjectExistsException { + super(fo, loader, false); + } + + } +} diff -r 9136c35a2fd8 openide.nodes/test/unit/src/org/openide/nodes/CookieSetTest.java --- a/openide.nodes/test/unit/src/org/openide/nodes/CookieSetTest.java Wed Nov 04 18:52:34 2009 +0100 +++ b/openide.nodes/test/unit/src/org/openide/nodes/CookieSetTest.java Thu Nov 05 16:16:48 2009 +0100 @@ -90,6 +90,39 @@ } static interface Cook extends Node.Cookie { } + public void testInconsistencyWhenDoubleCookie175750() { + CookieSet cs = CookieSet.createGeneric(null); + + + class Factory implements CookieSet.Factory { + public T createCookie(Class klass) { + if (klass == Cook.class || klass == Hook.class) { + return klass.cast(new Hook() { }); + } + return null; + } + } + final Factory f = new Factory(); + cs.add(new Class[] { Cook.class, Hook.class }, f); + + Cook one = cs.getCookie(Hook.class); + Cook two = cs.getCookie(Cook.class); + Cook three = cs.getLookup().lookup(Cook.class); + Cook four = cs.getLookup().lookup(Hook.class); + + assertSame("One and two", one, two); + assertSame("3 and two", three, two); + assertSame("One and 4", one, four); + + cs.remove(new Class[] { Hook.class, Cook.class }, f); + + assertNull("No cookie now ", cs.getCookie(Cook.class)); + assertNull("No lkp now ", cs.getLookup().lookup(Cook.class)); + assertNull("No h cookie now ", cs.getCookie(Hook.class)); + assertNull("No h lkp now ", cs.getLookup().lookup(Hook.class)); + } + static interface Hook extends Cook { + } public void testAddRemove () throws Exception { diff -r 9136c35a2fd8 xml/nbproject/project.xml --- a/xml/nbproject/project.xml Wed Nov 04 18:52:34 2009 +0100 +++ b/xml/nbproject/project.xml Thu Nov 05 16:16:48 2009 +0100 @@ -206,7 +206,7 @@ - 7.0 + 7.10 diff -r 9136c35a2fd8 xml/src/org/netbeans/modules/xml/XMLDataObject.java --- a/xml/src/org/netbeans/modules/xml/XMLDataObject.java Wed Nov 04 18:52:34 2009 +0100 +++ b/xml/src/org/netbeans/modules/xml/XMLDataObject.java Thu Nov 05 16:16:48 2009 +0100 @@ -84,7 +84,7 @@ * @param loader loader of this data object */ public XMLDataObject (final FileObject fo, MultiFileLoader loader) throws DataObjectExistsException { - super (fo, loader); + super (fo, loader, false); CookieSet set = getCookieSet(); set.add (cookieManager = new DataObjectCookieManager (this, set)); diff -r 9136c35a2fd8 xml/test/unit/src/org/netbeans/modules/xml/XMLDataObjectTest.java --- a/xml/test/unit/src/org/netbeans/modules/xml/XMLDataObjectTest.java Wed Nov 04 18:52:34 2009 +0100 +++ b/xml/test/unit/src/org/netbeans/modules/xml/XMLDataObjectTest.java Thu Nov 05 16:16:48 2009 +0100 @@ -40,20 +40,25 @@ */ package org.netbeans.modules.xml; -import java.io.IOException; +import java.util.Set; import org.netbeans.junit.NbTestCase; import org.openide.cookies.EditCookie; +import org.openide.cookies.OpenCookie; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.loaders.DataObject; -import org.openide.loaders.DataObjectNotFoundException; import org.openide.util.test.MockLookup; +import org.openide.windows.WindowManager; /** * * @author Petr Hejl */ public class XMLDataObjectTest extends NbTestCase { + static { + System.setProperty ("org.openide.util.Lookup", "org.openide.text.DataEditorSupportTest$Lkp"); + System.setProperty("org.openide.windows.DummyWindowManager.VISIBLE", "false"); + } public XMLDataObjectTest(String name) { super(name); @@ -64,7 +69,7 @@ MockLookup.init(); } - public void testLookup() throws DataObjectNotFoundException, IOException { + public void testLookup() throws Exception { MockLookup.setInstances(XMLDataLoader.getLoader(XMLDataLoader.class)); FileObject document = FileUtil.toFileObject( @@ -83,5 +88,23 @@ EditCookie lkp = dataObject.getLookup().lookup(EditCookie.class); assertEquals("Cookies are the same", ec, lkp); + + OpenCookie lkp2 = dataObject.getLookup().lookup(OpenCookie.class); + + lkp.edit(); + lkp2.open(); + + Set all = null; + for (int i = 0; i < 10; i++) { + Thread.sleep(1000); + all = WindowManager.getDefault().getRegistry().getOpened(); + if (all.size() > 0) { + break; + } + } + + assertEquals("There is just one TC: " + all, 1, all.size()); + + assertEquals("Cookies are the same", lkp, lkp2); } }