use of com.sldeditor.common.NodeInterface in project sldeditor by robward-scisys.
the class GeoServerLayerUpdateTool 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) {
layerList.clear();
connection = null;
for (NodeInterface node : nodeTypeList) {
if (node instanceof GeoServerLayerNode) {
GeoServerLayerNode layerNode = (GeoServerLayerNode) node;
GeoServerLayer layer = layerNode.getLayer();
layerList.add(layer);
if (connection == null) {
connection = layer.getConnection();
}
} else if (node instanceof GeoServerLayerHeadingNode) {
GeoServerLayerHeadingNode layerHeadingNode = (GeoServerLayerHeadingNode) node;
connection = layerHeadingNode.getConnection();
for (int workspaceIndex = 0; workspaceIndex < layerHeadingNode.getChildCount(); workspaceIndex++) {
TreeNode treeNode = layerHeadingNode.getChildAt(workspaceIndex);
if (treeNode instanceof GeoServerWorkspaceNode) {
GeoServerWorkspaceNode workspaceNode = (GeoServerWorkspaceNode) treeNode;
extractWorkspaceLayers(workspaceNode);
}
}
} else if (node instanceof GeoServerWorkspaceNode) {
GeoServerWorkspaceNode workspaceNode = (GeoServerWorkspaceNode) node;
if (!workspaceNode.isStyle()) {
connection = workspaceNode.getConnection();
extractWorkspaceLayers(workspaceNode);
}
}
}
}
use of com.sldeditor.common.NodeInterface in project sldeditor by robward-scisys.
the class DatabaseConnectionListTool 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();
selectedDatabaseType = null;
boolean databaseNodesSelected = false;
boolean canDuplicate = true;
for (NodeInterface nodeType : nodeTypeList) {
if (nodeType instanceof DatabaseNode) {
DatabaseNode databaseNode = (DatabaseNode) nodeType;
DatabaseConnection connection = databaseNode.getConnection();
connectionList.add(connection);
databaseNodesSelected = true;
if (!connection.isSupportsDuplication()) {
canDuplicate = false;
}
} else if (nodeType instanceof DatabaseOverallNode) {
DatabaseOverallNode databaseOverallNode = (DatabaseOverallNode) nodeType;
selectedDatabaseType = databaseOverallNode.toString();
canDuplicate = false;
}
}
btnDuplicate.setEnabled(canDuplicate && databaseNodesSelected && (connectionList.size() == 1));
btnEdit.setEnabled(databaseNodesSelected && (connectionList.size() == 1));
btnDelete.setEnabled(databaseNodesSelected);
}
use of com.sldeditor.common.NodeInterface 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.common.NodeInterface in project sldeditor by robward-scisys.
the class YSLDToolTest method testSupports.
/**
* Test which file types the tool supports.
*/
@Test
public void testSupports() {
YSLDTool tool = new YSLDTool();
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", ".ysld");
} 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 sld file
try {
List<NodeInterface> nodeTypeList = new ArrayList<NodeInterface>();
nodeTypeList.add(new FileTreeNode(testFile2.getParentFile(), testFile2.getName()));
assertTrue(tool.supports(null, nodeTypeList, null));
} catch (SecurityException | FileNotFoundException e) {
e.printStackTrace();
}
// Try with valid ysld 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.common.NodeInterface in project sldeditor by robward-scisys.
the class GeoServerInputTest method testCopyNodes.
/**
* Test method for
* {@link com.sldeditor.extension.filesystem.geoserver.GeoServerInput#copyNodes(com.sldeditor.common.NodeInterface, java.util.Map)}.
*/
@Test
public void testCopyNodes() {
GeoServerInput input = new GeoServerInput(null);
GeoServerInput.overrideGeoServerClientClass(DummyGeoServerClient.class);
FSTree tree = new FSTree();
DefaultMutableTreeNode rootNode;
rootNode = new DefaultMutableTreeNode("Root");
DefaultTreeModel model = new DefaultTreeModel(rootNode);
input.populate(tree, model, rootNode);
URL url = SLDFileHandlerTest.class.getResource("/sld/point_attribute.sld");
List<SLDDataInterface> sldDataList = input.open(url);
assertNull(sldDataList);
GeoServerConnection connection1 = new GeoServerConnection();
connection1.setConnectionName("test connection 1");
// Add some GeoServer connections
input.addNewConnection(connection1);
// Try null parameters
assertFalse(input.copyNodes(null, null));
// Try with valid parameters
GeoServerWorkspaceNode workspaceTreeNode = new GeoServerWorkspaceNode(input, connection1, "test workspace", false);
// Create test data
Map<NodeInterface, List<SLDDataInterface>> copyDataMap = new HashMap<NodeInterface, List<SLDDataInterface>>();
List<SLDDataInterface> sldToCopyList = new ArrayList<SLDDataInterface>();
StyleWrapper styleWrapper = new StyleWrapper("workspace", "layer1");
SLDData sldData = new SLDData(styleWrapper, "sld contents");
sldData.setConnectionData(connection1);
sldToCopyList.add(sldData);
copyDataMap.put(workspaceTreeNode, sldToCopyList);
assertFalse(input.copyNodes(workspaceTreeNode, null));
assertFalse(input.copyNodes(null, copyDataMap));
// Try with valid parameters
assertTrue(input.copyNodes(workspaceTreeNode, copyDataMap));
}
Aggregations