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());
}
}
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();
}
}
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;
}
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;
}
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;
}
Aggregations