Search in sources :

Example 16 with FileTreeNode

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

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

the class FileTreeNodeTest method test.

/**
 * Test.
 */
@Ignore
@Test
public void test() {
    Map<String, FileHandlerInterface> fileHandlerMap = new LinkedHashMap<String, FileHandlerInterface>();
    FileHandlerInterface fileHandler = new DummyFileHandler();
    for (String fileExtension : fileHandler.getFileExtensionList()) {
        fileHandlerMap.put(fileExtension, fileHandler);
    }
    Path tmpFolder = null;
    try {
        tmpFolder = Files.createTempDirectory(getClass().getSimpleName());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    File folder = tmpFolder.toFile();
    File parent = folder.getParentFile();
    String name = folder.getName();
    try {
        FileTreeNode.setFileHandlerMap(fileHandlerMap);
        FileTreeNode node = new FileTreeNode(parent, name);
        assertTrue(node.isDir());
        assertTrue(node.getAllowsChildren());
        assertFalse(node.isLeaf());
        assertNull(node.getHandler());
        assertEquals(name, node.getName());
        assertEquals(DataFlavourManager.FOLDER_DATAITEM_FLAVOR, node.getDataFlavour());
        // CHECKSTYLE:OFF
        File tmpFile1 = File.createTempFile("sldeditor", ".abc", folder);
        // CHECKSTYLE:ON
        Thread.sleep(1000);
        // Has a file extension not expecting
        assertEquals(0, node.getChildCount());
        File tmpFile2 = File.createTempFile("sldeditor", ".test", folder);
        Thread.sleep(10000);
        assertEquals(1, node.getChildCount());
        tmpFile2.delete();
        Thread.sleep(10000);
        assertEquals(0, node.getChildCount());
        assertEquals(folder.getAbsolutePath(), node.getDestinationText());
        tmpFile1.delete();
        folder.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());
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) FileHandlerInterface(com.sldeditor.datasource.extension.filesystem.node.file.FileHandlerInterface) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with FileTreeNode

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

the class SLDEditorFileHandler 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;
        File f = fileTreeNode.getFile();
        if (f != null) {
            if (FileSystemUtils.isFileExtensionSupported(f, getFileExtensionList())) {
                List<SLDDataInterface> list = new ArrayList<SLDDataInterface>();
                SLDDataInterface sldData = readSLDEditorFile(f);
                list.add(sldData);
                return list;
            }
        }
    }
    return null;
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) ArrayList(java.util.ArrayList) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)

Example 19 with FileTreeNode

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

the class VectorFileHandler 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);
        }
    } else if (node instanceof DatabaseFeatureClassNode) {
        return open(null);
    }
    return null;
}
Also used : DatabaseFeatureClassNode(com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)

Example 20 with FileTreeNode

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

the class YSLDFileHandler 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 : 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