1 19 20 package org.openide.loaders; 21 import java.beans.PropertyChangeEvent ; 22 import java.beans.PropertyVetoException ; 23 import java.beans.VetoableChangeListener ; 24 import java.lang.reflect.InvocationTargetException ; 25 import java.util.HashSet ; 26 import org.openide.NotifyDescriptor; 27 import org.openide.cookies.EditorCookie; 28 import org.openide.filesystems.*; 29 import org.openide.nodes.Node; 30 import org.openide.text.DataEditorSupport; 31 import org.openide.util.Lookup; 32 import java.io.IOException ; 33 import java.util.Arrays ; 34 import javax.swing.text.Document ; 35 import org.netbeans.junit.*; 36 import org.openide.cookies.OpenCookie; 37 import org.openide.nodes.Children; 38 import org.openide.nodes.CookieSet; 39 import org.openide.util.NbBundle; 40 import org.openide.util.lookup.AbstractLookup; 41 import org.openide.util.lookup.InstanceContent; 42 43 44 47 public class Sample60M7ProblemWithGetDataObjectTest extends NbTestCase { 48 49 public Sample60M7ProblemWithGetDataObjectTest(String name) { 50 super(name); 51 } 52 53 54 protected void setUp() throws Exception { 55 System.setProperty("org.openide.util.Lookup", Lkp.class.getName()); 56 assertEquals(Lkp.class, Lookup.getDefault().getClass()); 57 } 58 59 public void testHasDataObjectInItsLookup() throws Exception { 60 FileObject sample = FileUtil.createData(FileUtil.createMemoryFileSystem().getRoot(), "sample/S.sample"); 61 DataObject obj = DataObject.find(sample); 62 assertEquals(Sample60M6DataLoader.class, obj.getLoader().getClass()); 63 64 assertEquals("Object is in its own node's lookup", obj, obj.getNodeDelegate().getLookup().lookup(DataObject.class)); 65 assertEquals("Object is in its own lookup", obj, obj.getLookup().lookup(DataObject.class)); 66 assertEquals("Object is own node's cookie", obj, obj.getNodeDelegate().getCookie(DataObject.class)); 67 assertEquals("Object is own cookie", obj, obj.getCookie(DataObject.class)); 68 } 69 70 static class Sample60M6DataObject extends MultiDataObject 71 implements Lookup.Provider { 72 73 public Sample60M6DataObject(FileObject pf, Sample60M6DataLoader loader) throws DataObjectExistsException, IOException { 74 super(pf, loader); 75 CookieSet cookies = getCookieSet(); 76 cookies.add((Node.Cookie) DataEditorSupport.create(this, getPrimaryEntry(), cookies)); 77 } 78 79 protected Node createNodeDelegate() { 80 return new Sample60M6DataNode(this, getLookup()); 81 } 82 83 public Lookup getLookup() { 84 return getCookieSet().getLookup(); 85 } 86 } 87 88 public static class Sample60M6DataLoader extends UniFileLoader { 89 90 public static final String REQUIRED_MIME = "text/x-sample"; 91 92 private static final long serialVersionUID = 1L; 93 94 public Sample60M6DataLoader() { 95 super("org.openide.loaders.Sample60M6DataObject"); 96 } 97 98 protected String defaultDisplayName() { 99 return NbBundle.getMessage(Sample60M6DataLoader.class, "LBL_Sample60M6_loader_name"); 100 } 101 102 protected void initialize() { 103 super.initialize(); 104 getExtensions().addExtension("sample"); 105 } 106 107 protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException { 108 return new Sample60M6DataObject(primaryFile, this); 109 } 110 111 protected String actionsContext() { 112 return "Loaders/" + REQUIRED_MIME + "/Actions"; 113 } 114 115 } 116 static class Sample60M6DataNode extends DataNode { 117 public Sample60M6DataNode(Sample60M6DataObject obj) { 118 super(obj, Children.LEAF); 119 } 121 Sample60M6DataNode(Sample60M6DataObject obj, Lookup lookup) { 122 super(obj, Children.LEAF, lookup); 123 } 125 126 138 } 139 140 public static final class Lkp extends AbstractLookup { 141 public Lkp() { 142 this(new InstanceContent()); 143 } 144 private Lkp(InstanceContent ic) { 145 super(ic); 146 ic.add(Sample60M6DataLoader.getLoader(Sample60M6DataLoader.class)); 147 } 148 } 149 } 150 | Popular Tags |