Search in sources :

Example 6 with FileTreeNode

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

the class FileSystemInput method deleteNodes.

/*
     * (non-Javadoc)
     * 
     * @see
     * com.sldeditor.extension.input.FileSystemInterface#deleteNodes(com.sldeditor.extension.input.
     * NodeInterface, java.util.List)
     */
@Override
public void deleteNodes(NodeInterface nodeToTransfer, List<SLDDataInterface> sldDataList) {
    if (sldDataList == null) {
        return;
    }
    if (nodeToTransfer instanceof FileTreeNode) {
        for (SLDDataInterface sldData : sldDataList) {
            String sldFilename = sldData.getSLDFile().getAbsolutePath();
            File file = new File(sldFilename);
            file.delete();
        }
        DefaultMutableTreeNode destinationNode = (DefaultMutableTreeNode) nodeToTransfer;
        TreeNode parent = destinationNode.getParent();
        destinationNode.removeFromParent();
        if (treeModel != null) {
            treeModel.reload(parent);
        }
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) TreeNode(javax.swing.tree.TreeNode) File(java.io.File) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)

Example 7 with FileTreeNode

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

the class FileSystemInput method copyNodes.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.extension.input.FileSystemInterface#drop(com.sldeditor.extension.input.
     * NodeInterface, java.util.Map)
     */
@Override
public boolean copyNodes(NodeInterface destinationTreeNode, Map<NodeInterface, List<SLDDataInterface>> copyDataMap) {
    if ((destinationTreeNode == null) || (copyDataMap == null)) {
        return false;
    }
    FileTreeNode destinationNode = (FileTreeNode) destinationTreeNode;
    if (!destinationNode.isDir()) {
        destinationNode = (FileTreeNode) destinationNode.getParent();
    }
    File destinationFolder = destinationNode.getFile();
    for (NodeInterface key : copyDataMap.keySet()) {
        List<SLDDataInterface> sldDataList = copyDataMap.get(key);
        for (SLDDataInterface sldData : sldDataList) {
            String sldFilename = sldData.getSLDFile().getAbsolutePath();
            FileHandlerInterface handler = getFileHandler(sldFilename);
            if (handler != null) {
                String sldName = handler.getSLDName(sldData);
                File existingFolder = new File(sldFilename).getParentFile();
                if (existingFolder.equals(destinationFolder)) {
                    sldName = "Copy of " + sldName;
                }
                File updateFile = new File(destinationFolder, sldName);
                sldData.setSLDFile(updateFile);
                save(sldData);
            }
        }
        destinationNode.refreshFolder();
        if (treeModel != null) {
            treeModel.reload(destinationNode);
        }
    }
    return true;
}
Also used : FileHandlerInterface(com.sldeditor.datasource.extension.filesystem.node.file.FileHandlerInterface) SLDDataInterface(com.sldeditor.common.SLDDataInterface) File(java.io.File) NodeInterface(com.sldeditor.common.NodeInterface) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)

Example 8 with FileTreeNode

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

the class RasterFileHandler method getSLDContents.

/**
 * Gets the SLD contents.
 *
 * @param node the node
 * @return the SLD contents
 */
/*
     * (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;
        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 9 with FileTreeNode

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

the class DatabaseConnectionTool method setSelectedItems.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.tool.ToolInterface#setSelectedItems(java.util.List, java.util.List)
     */
@Override
public void setSelectedItems(List<NodeInterface> nodeTypeList, List<SLDDataInterface> sldDataList) {
    connectionList.clear();
    if (nodeTypeList != null) {
        for (NodeInterface node : nodeTypeList) {
            if (node instanceof DatabaseNode) {
                DatabaseNode databaseNode = (DatabaseNode) node;
                connectionList.add(databaseNode.getConnection());
            } else if (node instanceof FileTreeNode) {
                FileTreeNode fileNode = (FileTreeNode) node;
                if (fileNode.getFileCategory() == FileTreeNodeTypeEnum.DATABASE) {
                    DatabaseConnection databaseConnection = DatabaseConnectionFactory.getConnection(fileNode.getFile().getAbsolutePath());
                    connectionList.add(databaseConnection);
                }
            }
        }
    }
    updateButtonState();
}
Also used : DatabaseNode(com.sldeditor.datasource.extension.filesystem.node.database.DatabaseNode) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection) NodeInterface(com.sldeditor.common.NodeInterface) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)

Example 10 with FileTreeNode

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

the class FileSystemInputTest method testFileSystemInput.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.file.FileSystemInput#FileSystemInput(com.sldeditor.common.ToolSelectionInterface)}.
 */
@Test
public void testFileSystemInput() {
    FileSystemInput input = new FileSystemInput(null);
    FSTree tree = new FSTree();
    DefaultMutableTreeNode rootNode;
    try {
        rootNode = new DefaultMutableTreeNode("Root");
        DefaultTreeModel model = new DefaultTreeModel(rootNode);
        input.populate(tree, model, rootNode);
        URL url = SLDFileHandlerTest.class.getResource("/point/sld/point_attribute.sld");
        List<SLDDataInterface> sldDataList = input.open(url);
        assertEquals(1, sldDataList.size());
        File parent = null;
        try {
            parent = new File(url.toURI());
            parent = parent.getParentFile();
        } catch (URISyntaxException e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
        FileTreeNode fileTreeNode = new FileTreeNode(parent, "point_attribute.sld");
        List<SLDDataInterface> sldDataContentsList = input.getSLDContents(fileTreeNode).getSldData();
        assertEquals(1, sldDataContentsList.size());
        // Changes where the file is to be saved to
        File saveFile = File.createTempFile(getClass().getSimpleName(), ".sld");
        SLDData sldData = (SLDData) sldDataContentsList.get(0);
        sldData.setSLDFile(saveFile);
        assertFalse(input.save(null));
        assertTrue(input.save(sldData));
        saveFile.delete();
    } catch (SecurityException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : SLDData(com.sldeditor.common.data.SLDData) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) FSTree(com.sldeditor.datasource.extension.filesystem.node.FSTree) FileNotFoundException(java.io.FileNotFoundException) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URL(java.net.URL) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) FileSystemInput(com.sldeditor.extension.filesystem.file.FileSystemInput) File(java.io.File) Test(org.junit.Test) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

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