use of com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode in project sldeditor by robward-scisys.
the class VectorTool method createUI.
/**
* Creates the ui.
*/
private void createUI() {
vectorPanel = new JPanel();
FlowLayout flowLayout = (FlowLayout) vectorPanel.getLayout();
flowLayout.setVgap(0);
flowLayout.setHgap(0);
vectorPanel.setBorder(BorderFactory.createTitledBorder(Localisation.getString(VectorTool.class, "VectorTool.title")));
//
// Import vector
//
importVectorButton = new ToolButton(Localisation.getString(VectorTool.class, "VectorTool.import"), "tool/importvector.png");
vectorPanel.add(importVectorButton);
importVectorButton.setEnabled(false);
importVectorButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if ((nodeTypeList != null) && (nodeTypeList.size() == 1)) {
if (sldEditorInterface != null) {
NodeInterface nodeInterface = nodeTypeList.get(0);
if (nodeInterface instanceof FileTreeNode) {
FileTreeNode fileTreeNode = (FileTreeNode) nodeInterface;
if (!importFile(fileTreeNode)) {
return;
}
} else if (nodeInterface instanceof DatabaseFeatureClassNode) {
DatabaseFeatureClassNode featureClassNode = (DatabaseFeatureClassNode) nodeInterface;
if (!importFeatureClass(featureClassNode)) {
return;
}
}
}
}
}
});
//
// Set data source
//
dataSourceButton = new ToolButton(Localisation.getString(VectorTool.class, "VectorTool.dataSource"), "tool/setdatasource.png");
vectorPanel.add(dataSourceButton);
dataSourceButton.setEnabled(false);
dataSourceButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if ((nodeTypeList != null) && (nodeTypeList.size() == 1)) {
if (sldEditorInterface != null) {
NodeInterface nodeInterface = nodeTypeList.get(0);
if (nodeInterface instanceof FileTreeNode) {
FileTreeNode fileTreeNode = (FileTreeNode) nodeInterface;
setDataSource(fileTreeNode);
} else if (nodeInterface instanceof DatabaseFeatureClassNode) {
DatabaseFeatureClassNode featureClassNode = (DatabaseFeatureClassNode) nodeInterface;
setDataSource(featureClassNode);
}
}
}
}
});
vectorPanel.setPreferredSize(new Dimension(PANEL_WIDTH, ToolPanel.TOOL_PANEL_HEIGHT));
}
use of com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode in project sldeditor by robward-scisys.
the class FileSystemInputTest method testCopyNodes.
/**
* Test method for
* {@link com.sldeditor.extension.filesystem.file.FileSystemInput#copyNodes(com.sldeditor.common.NodeInterface, java.util.Map)}.
*/
@Test
public void testCopyNodes() {
FileSystemInput input = new FileSystemInput(null);
URL url = SLDFileHandlerTest.class.getResource("/point/sld/point_attribute.sld");
List<SLDDataInterface> sldDataList = input.open(url);
assertEquals(1, sldDataList.size());
try {
Path tempFolder = Files.createTempDirectory(getClass().getSimpleName());
File tempFolderFile = tempFolder.toFile();
FileTreeNode destinationTreeNode = new FileTreeNode(tempFolderFile.getParentFile(), tempFolderFile.getName());
Map<NodeInterface, List<SLDDataInterface>> copyDataMap = new HashMap<NodeInterface, List<SLDDataInterface>>();
copyDataMap.put(destinationTreeNode, sldDataList);
assertTrue(input.copyNodes(destinationTreeNode, copyDataMap));
SLDData sldData = (SLDData) sldDataList.get(0);
sldData.setSLDFile(new File(tempFolderFile, "point_attribute.sld"));
input.deleteNodes(destinationTreeNode, sldDataList);
tempFolderFile.deleteOnExit();
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode in project sldeditor by robward-scisys.
the class RasterFileHandlerTest method testGetSLDContentsFile.
/**
* Single file
*
* <p>Test method for {@link com.sldeditor.extension.filesystem.file.raster.RasterFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
*/
@Test
public void testGetSLDContentsFile() {
assertNull(new RasterFileHandler().getSLDContents(null));
URL url = RasterFileHandlerTest.class.getResource("/point/sld");
File parent = null;
try {
parent = new File(url.toURI());
} catch (URISyntaxException e) {
e.printStackTrace();
fail(e.getMessage());
}
try {
FileTreeNode fileTreeNode = new FileTreeNode(parent, "point_attribute.sld");
RasterFileHandler handler = new RasterFileHandler();
List<SLDDataInterface> sldDataList = handler.getSLDContents(fileTreeNode);
assertNull(sldDataList);
// Try with valid vector file
FileTreeNode fileTreeNode2 = new FileTreeNode(parent, "point_attribute.tif");
sldDataList = handler.getSLDContents(fileTreeNode2);
assertTrue(sldDataList.isEmpty());
// Changes where the file is to be saved to
File saveFile = File.createTempFile(getClass().getSimpleName(), ".sld");
SLDData sldData = new SLDData(null, "");
sldData.setSLDFile(saveFile);
assertFalse(handler.save(null));
assertFalse(handler.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());
}
}
use of com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode in project sldeditor by robward-scisys.
the class SLDFileHandlerTest method testGetSLDContentsFile.
/**
* Single file
*
* <p>Test method for {@link com.sldeditor.extension.filesystem.file.sld.SLDFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
*/
@Test
public void testGetSLDContentsFile() {
assertNull(new SLDFileHandler().getSLDContents(null));
URL url = SLDFileHandlerTest.class.getResource("/point/sld");
File parent = null;
try {
parent = new File(url.toURI());
} catch (URISyntaxException e) {
e.printStackTrace();
fail(e.getMessage());
}
try {
FileTreeNode fileTreeNode = new FileTreeNode(parent, "point_attribute.sld");
SLDFileHandler handler = new SLDFileHandler();
List<SLDDataInterface> sldDataList = handler.getSLDContents(fileTreeNode);
assertEquals(1, sldDataList.size());
// Changes where the file is to be saved to
File saveFile = File.createTempFile(getClass().getSimpleName(), ".sld");
SLDData sldData = (SLDData) sldDataList.get(0);
sldData.setSLDFile(saveFile);
assertFalse(handler.save(null));
assertTrue(handler.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());
}
}
use of com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode in project sldeditor by robward-scisys.
the class VectorFileHandlerTest method testGetSLDContentsFile.
/**
* Single file
*
* <p>Test method for {@link com.sldeditor.extension.filesystem.file.vector.VectorFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
*/
@Test
public void testGetSLDContentsFile() {
assertNull(new VectorFileHandler().getSLDContents(null));
URL url = VectorFileHandlerTest.class.getResource("/point/sld");
File parent = null;
try {
parent = new File(url.toURI());
} catch (URISyntaxException e) {
e.printStackTrace();
fail(e.getMessage());
}
try {
FileTreeNode fileTreeNode = new FileTreeNode(parent, "point_attribute.sld");
VectorFileHandler handler = new VectorFileHandler();
List<SLDDataInterface> sldDataList = handler.getSLDContents(fileTreeNode);
assertNull(sldDataList);
// Try with valid vector file
FileTreeNode fileTreeNode2 = new FileTreeNode(parent, "point_attribute.shp");
sldDataList = handler.getSLDContents(fileTreeNode2);
assertTrue(sldDataList.isEmpty());
// Changes where the file is to be saved to
File saveFile = File.createTempFile(getClass().getSimpleName(), ".sld");
SLDData sldData = new SLDData(null, "");
sldData.setSLDFile(saveFile);
assertFalse(handler.save(null));
assertFalse(handler.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