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