Search in sources :

Example 1 with NodeInterface

use of com.sldeditor.common.NodeInterface in project sldeditor by robward-scisys.

the class MapBoxToolTest method testSupports.

/**
 * Test method for
 * {@link com.sldeditor.tool.mapbox.MapBoxTool#supports(java.util.List, java.util.List, java.util.List)}.
 */
@Test
public void testSupports() {
    MapBoxTool tool = new MapBoxTool();
    assertFalse(tool.supports(null, null, null));
    File testFile1 = null;
    File testFile2 = null;
    File testFile3 = null;
    try {
        testFile1 = File.createTempFile("invalid", ".tst");
        testFile2 = File.createTempFile("valid", ".sld");
        testFile3 = File.createTempFile("valid", ".json");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    // Try with invalid file
    try {
        List<NodeInterface> nodeTypeList = new ArrayList<NodeInterface>();
        assertNotNull(testFile1);
        nodeTypeList.add(new FileTreeNode(testFile1.getParentFile(), testFile1.getName()));
        assertFalse(tool.supports(null, nodeTypeList, null));
    } catch (SecurityException | FileNotFoundException e) {
        e.printStackTrace();
    }
    // Try with valid mapbox file
    try {
        List<NodeInterface> nodeTypeList = new ArrayList<NodeInterface>();
        nodeTypeList.add(new FileTreeNode(testFile3.getParentFile(), testFile3.getName()));
        assertTrue(tool.supports(null, nodeTypeList, null));
    } catch (SecurityException | FileNotFoundException e) {
        e.printStackTrace();
    }
    // Try with several files
    try {
        List<NodeInterface> nodeTypeList = new ArrayList<NodeInterface>();
        nodeTypeList.add(new FileTreeNode(testFile1.getParentFile(), testFile1.getName()));
        nodeTypeList.add(new FileTreeNode(testFile2.getParentFile(), testFile2.getName()));
        nodeTypeList.add(new FileTreeNode(testFile3.getParentFile(), testFile3.getName()));
        assertFalse(tool.supports(null, nodeTypeList, null));
    } catch (SecurityException | FileNotFoundException e) {
        e.printStackTrace();
    }
    testFile1.delete();
    testFile2.delete();
    testFile3.delete();
}
Also used : MapBoxTool(com.sldeditor.tool.mapbox.MapBoxTool) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) NodeInterface(com.sldeditor.common.NodeInterface) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) Test(org.junit.Test)

Example 2 with NodeInterface

use of com.sldeditor.common.NodeInterface in project sldeditor by robward-scisys.

the class VectorToolTest method testSupports.

/**
 * Test method for {@link com.sldeditor.tool.vector.VectorTool#supports(java.util.List, java.util.List, java.util.List)}.
 */
@Test
public void testSupports() {
    try {
        FileTreeNode vectorTreeNode = new FileTreeNode(new File("/test"), "sld_cookbook_polygon.shp");
        vectorTreeNode.setFileCategory(FileTreeNodeTypeEnum.VECTOR);
        FileTreeNode rasterTreeNode = new FileTreeNode(new File("/test"), "sld_cookbook_polygon.tif");
        rasterTreeNode.setFileCategory(FileTreeNodeTypeEnum.RASTER);
        List<Class<?>> uniqueNodeTypeList = new ArrayList<Class<?>>();
        List<NodeInterface> nodeTypeList = new ArrayList<NodeInterface>();
        List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
        // Try vector file
        nodeTypeList.add(vectorTreeNode);
        VectorTool vectorTool = new VectorTool(null);
        assertTrue(vectorTool.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
        // Try raster file
        nodeTypeList.clear();
        nodeTypeList.add(rasterTreeNode);
        assertFalse(vectorTool.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
        // Try database feature class
        nodeTypeList.clear();
        DatabaseFeatureClassNode databaseFeatureClassNode = new DatabaseFeatureClassNode(null, null, "db fc");
        nodeTypeList.add(databaseFeatureClassNode);
        assertTrue(vectorTool.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
        // Try invalid node class
        nodeTypeList.clear();
        nodeTypeList.add(new GeoServerStyleHeadingNode(null, null, "test"));
        assertFalse(vectorTool.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
        // Try with no nodes
        nodeTypeList.clear();
        assertFalse(vectorTool.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
        // Try with null
        assertFalse(vectorTool.supports(uniqueNodeTypeList, null, sldDataList));
    } catch (SecurityException e) {
        e.printStackTrace();
        fail();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail();
    }
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) VectorTool(com.sldeditor.tool.vector.VectorTool) DatabaseFeatureClassNode(com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) GeoServerStyleHeadingNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleHeadingNode) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) NodeInterface(com.sldeditor.common.NodeInterface) Test(org.junit.Test)

Example 3 with NodeInterface

use of com.sldeditor.common.NodeInterface 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 4 with NodeInterface

use of com.sldeditor.common.NodeInterface 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 5 with NodeInterface

use of com.sldeditor.common.NodeInterface 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)

Aggregations

NodeInterface (com.sldeditor.common.NodeInterface)26 SLDDataInterface (com.sldeditor.common.SLDDataInterface)9 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)9 ArrayList (java.util.ArrayList)8 File (java.io.File)7 IOException (java.io.IOException)7 Test (org.junit.Test)7 TransferredData (com.sldeditor.datasource.extension.filesystem.dataflavour.TransferredData)5 FileNotFoundException (java.io.FileNotFoundException)5 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)5 TreePath (javax.swing.tree.TreePath)5 SelectedFiles (com.sldeditor.common.filesystem.SelectedFiles)4 JTree (javax.swing.JTree)4 DatabaseConnection (com.sldeditor.common.data.DatabaseConnection)3 DatabaseNode (com.sldeditor.datasource.extension.filesystem.node.database.DatabaseNode)3 GeoServerWorkspaceNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode)3 DataFlavor (java.awt.datatransfer.DataFlavor)3 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)3 HashMap (java.util.HashMap)3 List (java.util.List)3