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