use of com.sldeditor.common.NodeInterface 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.common.NodeInterface 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.common.NodeInterface in project sldeditor by robward-scisys.
the class TransferableDataItem method internalPopulate.
/**
* Internal populate.
*
* @param selectedData the selected data
*/
private void internalPopulate(Map<NodeInterface, TreePath> selectedData) {
if (selectedData != null) {
this.data = new TransferredData();
for (NodeInterface selection : selectedData.keySet()) {
TreePath path = selectedData.get(selection);
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
this.data.addData(path, node.getUserObject(), selection.getDataFlavour());
}
}
}
use of com.sldeditor.common.NodeInterface in project sldeditor by robward-scisys.
the class TreeTransferHandler method importData.
/*
* (non-Javadoc)
*
* @see javax.swing.TransferHandler#importData(javax.swing.JComponent, java.awt.datatransfer.Transferable)
*/
@Override
public boolean importData(JComponent comp, Transferable t) {
if (!(comp instanceof JTree) || (t == null)) {
return false;
}
boolean result = false;
JTree tree = (JTree) comp;
NodeInterface destinationTreeNode = (NodeInterface) tree.getLastSelectedPathComponent();
DataFlavor destDataFlavour = destinationTreeNode.getDataFlavour();
TransferredData transferredData = null;
try {
transferredData = (TransferredData) t.getTransferData(destDataFlavour);
result = DataFlavourManager.copy(destinationTreeNode, transferredData);
} catch (UnsupportedFlavorException e) {
ConsoleManager.getInstance().exception(this, e);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
return result;
}
use of com.sldeditor.common.NodeInterface in project sldeditor by robward-scisys.
the class TreeTransferHandler method canImport.
/*
* (non-Javadoc)
*
* @see javax.swing.TransferHandler#canImport(javax.swing.TransferHandler.TransferSupport)
*/
@Override
public boolean canImport(TransferSupport support) {
if (support == null) {
return false;
}
JTree.DropLocation dropLocation = (JTree.DropLocation) support.getDropLocation();
TreePath destinationPath = dropLocation.getPath();
NodeInterface destinationTreeNode = null;
try {
destinationTreeNode = (NodeInterface) destinationPath.getLastPathComponent();
} catch (ClassCastException e) {
return false;
}
Transferable transferable = support.getTransferable();
DataFlavor destDataFlavour = destinationTreeNode.getDataFlavour();
TransferredData transferredData = null;
try {
transferredData = (TransferredData) transferable.getTransferData(destDataFlavour);
} catch (UnsupportedFlavorException e) {
ConsoleManager.getInstance().exception(this, e);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
if (transferredData == null) {
return false;
}
TreePath treePath = transferredData.getTreePath(0);
if (isSameTreePath(treePath, destinationPath)) {
return false;
}
return DataFlavourManager.isSupported(transferredData.getDataFlavour(0), destDataFlavour);
}
Aggregations