Search in sources :

Example 1 with TransferableDataItem

use of com.sldeditor.datasource.extension.filesystem.node.TransferableDataItem in project sldeditor by robward-scisys.

the class TransferableDataItemTest method testTransferableDataItem.

/**
 * Test method for
 * {@link com.sldeditor.datasource.extension.filesystem.node.TransferableDataItem#TransferableDataItem()}.
 */
@Test
public void testTransferableDataItem() {
    Map<NodeInterface, TreePath> selectedData = new HashMap<NodeInterface, TreePath>();
    FileTreeNode fileTreeNode1 = null;
    FileTreeNode fileTreeNode2 = null;
    FileTreeNode fileTreeNode3 = null;
    FileTreeNode fileTreeNode4 = null;
    try {
        fileTreeNode1 = new FileTreeNode(new File(System.getProperty("user.dir")), "file1.txt");
        fileTreeNode2 = new FileTreeNode(new File(System.getProperty("user.dir")), "file2.txt");
        fileTreeNode3 = new FileTreeNode(new File(System.getProperty("user.dir")), "file3.txt");
        fileTreeNode4 = new FileTreeNode(new File(System.getProperty("user.dir")), "file4.txt");
        selectedData.put(fileTreeNode1, new TreePath(new DefaultMutableTreeNode("branch1")));
        selectedData.put(fileTreeNode2, new TreePath(new DefaultMutableTreeNode("branch2")));
        selectedData.put(fileTreeNode3, new TreePath(new DefaultMutableTreeNode("branch3")));
        selectedData.put(fileTreeNode4, new TreePath(new DefaultMutableTreeNode("branch4")));
        TransferableDataItem dataItem = new TransferableDataItem(selectedData);
        DataFlavor dataFlavour = dataItem.getDataFlavour();
        assertEquals(FileTreeNode.class, dataFlavour.getRepresentationClass());
        try {
            Object data = dataItem.getTransferData(DataFlavourManager.FOLDER_DATAITEM_FLAVOR);
            assertTrue(data instanceof TransferredData);
            assertEquals(selectedData.size(), ((TransferredData) data).getDataListSize());
            assertFalse(dataItem.isDataFlavorSupported(BuiltInDataFlavour.GEOSERVER_DATAITEM_FLAVOUR));
            assertTrue(dataItem.isDataFlavorSupported(DataFlavourManager.FOLDER_DATAITEM_FLAVOR));
        } catch (UnsupportedFlavorException e) {
            e.printStackTrace();
            fail(e.getMessage());
        } catch (IOException e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    } catch (SecurityException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) HashMap(java.util.HashMap) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) DataFlavor(java.awt.datatransfer.DataFlavor) TransferredData(com.sldeditor.datasource.extension.filesystem.dataflavour.TransferredData) TreePath(javax.swing.tree.TreePath) TransferableDataItem(com.sldeditor.datasource.extension.filesystem.node.TransferableDataItem) File(java.io.File) NodeInterface(com.sldeditor.common.NodeInterface) Test(org.junit.Test)

Aggregations

NodeInterface (com.sldeditor.common.NodeInterface)1 TransferredData (com.sldeditor.datasource.extension.filesystem.dataflavour.TransferredData)1 TransferableDataItem (com.sldeditor.datasource.extension.filesystem.node.TransferableDataItem)1 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)1 DataFlavor (java.awt.datatransfer.DataFlavor)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 TreePath (javax.swing.tree.TreePath)1 Test (org.junit.Test)1