Search in sources :

Example 1 with TransferredData

use of com.sldeditor.datasource.extension.filesystem.dataflavour.TransferredData in project sldeditor by robward-scisys.

the class TransferableDataItem method internalPopulate.

/**
 * Internal populate.
 *
 * @param selectedData the selected data
 */
private void internalPopulate(Map<NodeInterface, TreePath> selectedData) {
    if (selectedData != null) {
        this.data = new TransferredData();
        for (NodeInterface selection : selectedData.keySet()) {
            TreePath path = selectedData.get(selection);
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
            this.data.addData(path, node.getUserObject(), selection.getDataFlavour());
        }
    }
}
Also used : TransferredData(com.sldeditor.datasource.extension.filesystem.dataflavour.TransferredData) TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) NodeInterface(com.sldeditor.common.NodeInterface)

Example 2 with TransferredData

use of com.sldeditor.datasource.extension.filesystem.dataflavour.TransferredData in project sldeditor by robward-scisys.

the class TreeTransferHandler method importData.

/*
     * (non-Javadoc)
     * 
     * @see javax.swing.TransferHandler#importData(javax.swing.JComponent, java.awt.datatransfer.Transferable)
     */
@Override
public boolean importData(JComponent comp, Transferable t) {
    if (!(comp instanceof JTree) || (t == null)) {
        return false;
    }
    boolean result = false;
    JTree tree = (JTree) comp;
    NodeInterface destinationTreeNode = (NodeInterface) tree.getLastSelectedPathComponent();
    DataFlavor destDataFlavour = destinationTreeNode.getDataFlavour();
    TransferredData transferredData = null;
    try {
        transferredData = (TransferredData) t.getTransferData(destDataFlavour);
        result = DataFlavourManager.copy(destinationTreeNode, transferredData);
    } catch (UnsupportedFlavorException e) {
        ConsoleManager.getInstance().exception(this, e);
    } catch (IOException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
    return result;
}
Also used : JTree(javax.swing.JTree) TransferredData(com.sldeditor.datasource.extension.filesystem.dataflavour.TransferredData) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) NodeInterface(com.sldeditor.common.NodeInterface) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 3 with TransferredData

use of com.sldeditor.datasource.extension.filesystem.dataflavour.TransferredData in project sldeditor by robward-scisys.

the class TreeTransferHandler method canImport.

/*
     * (non-Javadoc)
     * 
     * @see javax.swing.TransferHandler#canImport(javax.swing.TransferHandler.TransferSupport)
     */
@Override
public boolean canImport(TransferSupport support) {
    if (support == null) {
        return false;
    }
    JTree.DropLocation dropLocation = (JTree.DropLocation) support.getDropLocation();
    TreePath destinationPath = dropLocation.getPath();
    NodeInterface destinationTreeNode = null;
    try {
        destinationTreeNode = (NodeInterface) destinationPath.getLastPathComponent();
    } catch (ClassCastException e) {
        return false;
    }
    Transferable transferable = support.getTransferable();
    DataFlavor destDataFlavour = destinationTreeNode.getDataFlavour();
    TransferredData transferredData = null;
    try {
        transferredData = (TransferredData) transferable.getTransferData(destDataFlavour);
    } catch (UnsupportedFlavorException e) {
        ConsoleManager.getInstance().exception(this, e);
    } catch (IOException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
    if (transferredData == null) {
        return false;
    }
    TreePath treePath = transferredData.getTreePath(0);
    if (isSameTreePath(treePath, destinationPath)) {
        return false;
    }
    return DataFlavourManager.isSupported(transferredData.getDataFlavour(0), destDataFlavour);
}
Also used : JTree(javax.swing.JTree) TransferredData(com.sldeditor.datasource.extension.filesystem.dataflavour.TransferredData) TreePath(javax.swing.tree.TreePath) Transferable(java.awt.datatransfer.Transferable) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) NodeInterface(com.sldeditor.common.NodeInterface) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 4 with TransferredData

use of com.sldeditor.datasource.extension.filesystem.dataflavour.TransferredData 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)

Example 5 with TransferredData

use of com.sldeditor.datasource.extension.filesystem.dataflavour.TransferredData in project sldeditor by robward-scisys.

the class TransferredDataTest method testGetDataListSize.

/**
 * Test method for {@link com.sldeditor.datasource.extension.filesystem.dataflavour.TransferredData#getDataListSize()}.
 */
@Test
public void testGetDataListSize() {
    TransferredData data = new TransferredData();
    assertEquals(0, data.getDataListSize());
    Integer userObject1 = Integer.valueOf(42);
    Double userObject2 = Double.valueOf(42.0);
    String userObject3 = "xxxx";
    SLDDataFlavour dataFlavour1 = new SLDDataFlavour(getClass(), "humanPresentableName");
    SLDDataFlavour dataFlavour2 = new SLDDataFlavour(getClass(), "humanPresentableName");
    SLDDataFlavour dataFlavour3 = new SLDDataFlavour(getClass(), "humanPresentableName");
    TreePath treePath1 = new TreePath("test1");
    TreePath treePath2 = new TreePath("test2");
    TreePath treePath3 = new TreePath("test3");
    data.addData(treePath1, userObject1, dataFlavour1);
    data.addData(treePath2, userObject2, dataFlavour2);
    data.addData(treePath3, userObject3, dataFlavour3);
    assertEquals(3, data.getDataListSize());
    assertEquals(dataFlavour2, data.getDataFlavour(1));
    assertNull(data.getDataFlavour(-1));
    assertNull(data.getDataFlavour(11));
    assertEquals(userObject3, data.getUserObject(2));
    assertNull(data.getUserObject(-1));
    assertNull(data.getUserObject(11));
    assertEquals(treePath1, data.getTreePath(0));
    assertNull(data.getTreePath(-1));
    assertNull(data.getTreePath(11));
}
Also used : TransferredData(com.sldeditor.datasource.extension.filesystem.dataflavour.TransferredData) TreePath(javax.swing.tree.TreePath) SLDDataFlavour(com.sldeditor.datasource.extension.filesystem.dataflavour.SLDDataFlavour) Test(org.junit.Test)

Aggregations

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