Search in sources :

Example 1 with FileTreeNode

use of com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode 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 FileTreeNode

use of com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode 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 FileTreeNode

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

the class FileSystemNodeManager method searchNode.

/**
 * Search node.
 *
 * @param isRoot the is root
 * @param rootNode the root node
 * @param nodeStr the node str
 * @return the default mutable tree node
 */
private static DefaultMutableTreeNode searchNode(boolean isRoot, DefaultMutableTreeNode rootNode, String nodeStr) {
    DefaultMutableTreeNode node = null;
    @SuppressWarnings("rawtypes") Enumeration e = rootNode.breadthFirstEnumeration();
    while (e.hasMoreElements()) {
        node = (DefaultMutableTreeNode) e.nextElement();
        if (isRoot || (node != rootNode)) {
            Object userObject = node.getUserObject();
            if (nodeStr.equals(userObject.toString())) {
                if (node instanceof FileTreeNode) {
                    if (((FileTreeNode) node).populateDirectories(true)) {
                        ((DefaultTreeModel) fileSystemTreeComponent.getModel()).nodeStructureChanged(node);
                    }
                }
                return node;
            }
        }
    }
    return null;
}
Also used : Enumeration(java.util.Enumeration) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)

Example 4 with FileTreeNode

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

the class SLDFileHandler method getSLDContents.

/*
     * (non-Javadoc)
     * 
     * @see
     * com.sldeditor.extension.input.FileHandlerInterface#getSLDContents(com.sldeditor.extension.
     * input.NodeInterface)
     */
@Override
public List<SLDDataInterface> getSLDContents(NodeInterface node) {
    if (node instanceof FileTreeNode) {
        FileTreeNode fileTreeNode = (FileTreeNode) node;
        if (fileTreeNode.isDir()) {
            // Cater for folders
            return open(fileTreeNode.getFile());
        } else {
            // Cater for single file
            File f = fileTreeNode.getFile();
            String fileExtension = ExternalFilenames.getFileExtension(f.getAbsolutePath());
            if (getFileExtensionList().contains(fileExtension)) {
                return open(f);
            }
        }
    }
    return null;
}
Also used : SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)

Example 5 with FileTreeNode

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

the class FileSystemInput method getSLDContents.

/**
 * Gets the SLD contents.
 *
 * @param node the node
 * @return the SLD contents
 */
@Override
public SelectedFiles getSLDContents(NodeInterface node) {
    SelectedFiles selectedFiles = new SelectedFiles();
    if (node instanceof FileTreeNode) {
        FileTreeNode fileTreeNode = (FileTreeNode) node;
        selectedFiles.setIsFolder(fileTreeNode.isDir());
        File f = fileTreeNode.getFile();
        String folderName = f.isFile() ? f.getParent() : f.getAbsolutePath();
        selectedFiles.setFolderName(folderName);
    }
    for (FileHandlerInterface handler : fileHandlerMap.values()) {
        List<SLDDataInterface> sldContentList = handler.getSLDContents(node);
        if (sldContentList != null) {
            selectedFiles.setSldData(sldContentList);
            selectedFiles.setDataSource(handler.isDataSource());
            return selectedFiles;
        }
    }
    return selectedFiles;
}
Also used : FileHandlerInterface(com.sldeditor.datasource.extension.filesystem.node.file.FileHandlerInterface) SLDDataInterface(com.sldeditor.common.SLDDataInterface) SelectedFiles(com.sldeditor.common.filesystem.SelectedFiles) File(java.io.File) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)

Aggregations

FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)33 File (java.io.File)28 SLDDataInterface (com.sldeditor.common.SLDDataInterface)17 FileNotFoundException (java.io.FileNotFoundException)17 Test (org.junit.Test)17 IOException (java.io.IOException)13 URL (java.net.URL)10 NodeInterface (com.sldeditor.common.NodeInterface)9 URISyntaxException (java.net.URISyntaxException)9 SLDData (com.sldeditor.common.data.SLDData)8 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)7 ArrayList (java.util.ArrayList)7 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4 DatabaseFeatureClassNode (com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode)3 FileHandlerInterface (com.sldeditor.datasource.extension.filesystem.node.file.FileHandlerInterface)3 SLDFileHandler (com.sldeditor.extension.filesystem.file.sld.SLDFileHandler)3 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)3 Path (java.nio.file.Path)3