1 19 20 package org.openide.loaders; 21 22 import java.awt.datatransfer.DataFlavor ; 23 import java.awt.datatransfer.Transferable ; 24 import java.awt.datatransfer.UnsupportedFlavorException ; 25 import java.io.File ; 26 import java.io.IOException ; 27 import java.util.List ; 28 import org.openide.filesystems.FileObject; 29 import org.openide.filesystems.FileUtil; 30 import org.openide.nodes.Children; 31 import org.netbeans.junit.*; 32 import org.openide.filesystems.LocalFileSystem; 33 34 public class DragAndDropDataNodeTest extends NbTestCase { 35 36 private LocalFileSystem testFileSystem; 37 38 public DragAndDropDataNodeTest(String name) { 39 super(name); 40 } 41 42 protected void setUp() throws Exception { 43 clearWorkDir(); 44 45 testFileSystem = new LocalFileSystem(); 46 testFileSystem.setRootDirectory( getWorkDir() ); 47 } 48 49 public void testClipboardCopy() throws IOException , ClassNotFoundException , UnsupportedFlavorException { 50 DataFlavor uriListFlavor = new DataFlavor ("text/uri-list;class=java.lang.String"); 51 52 FileObject fo = FileUtil.createData( testFileSystem.getRoot(), "dndtest.txt" ); 53 File tmpFile = FileUtil.toFile( fo ); 54 55 DataObject dob = DataObject.find( fo ); 56 DataNode node = new DataNode( dob, Children.LEAF ); 57 58 Transferable t = node.clipboardCopy(); 59 assertTrue( t.isDataFlavorSupported( DataFlavor.javaFileListFlavor ) ); 60 List fileList = (List ) t.getTransferData( DataFlavor.javaFileListFlavor ); 61 assertNotNull( fileList ); 62 assertEquals( 1, fileList.size() ); 63 assertTrue( fileList.contains( tmpFile ) ); 64 65 assertTrue( t.isDataFlavorSupported( uriListFlavor ) ); 66 String uriList = (String ) t.getTransferData( uriListFlavor ); 67 assertEquals( tmpFile.toURI()+"\r\n", uriList ); 68 } 69 70 public void testClipboardCut() throws ClassNotFoundException , IOException , UnsupportedFlavorException { 71 DataFlavor uriListFlavor = new DataFlavor ("text/uri-list;class=java.lang.String"); 72 73 FileObject fo = FileUtil.createData( testFileSystem.getRoot(), "dndtest.txt" ); 74 File tmpFile = FileUtil.toFile( fo ); 75 76 DataObject dob = DataObject.find( fo ); 77 DataNode node = new DataNode( dob, Children.LEAF ); 78 79 Transferable t = node.clipboardCopy(); 80 assertTrue( t.isDataFlavorSupported( DataFlavor.javaFileListFlavor ) ); 81 List fileList = (List ) t.getTransferData( DataFlavor.javaFileListFlavor ); 82 assertNotNull( fileList ); 83 assertEquals( 1, fileList.size() ); 84 assertTrue( fileList.contains( tmpFile ) ); 85 86 assertTrue( t.isDataFlavorSupported( uriListFlavor ) ); 87 String uriList = (String ) t.getTransferData( uriListFlavor ); 88 assertEquals( tmpFile.toURI()+"\r\n", uriList ); 89 } 90 } 91 | Popular Tags |