use of com.sldeditor.datasource.extension.filesystem.dataflavour.TransferredData 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.datasource.extension.filesystem.dataflavour.TransferredData 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.datasource.extension.filesystem.dataflavour.TransferredData 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);
}
use of com.sldeditor.datasource.extension.filesystem.dataflavour.TransferredData in project sldeditor by robward-scisys.
the class TransferableDataItemTest method testTransferableDataItem.
/**
* Test method for
* {@link com.sldeditor.datasource.extension.filesystem.node.TransferableDataItem#TransferableDataItem()}.
*/
@Test
public void testTransferableDataItem() {
Map<NodeInterface, TreePath> selectedData = new HashMap<NodeInterface, TreePath>();
FileTreeNode fileTreeNode1 = null;
FileTreeNode fileTreeNode2 = null;
FileTreeNode fileTreeNode3 = null;
FileTreeNode fileTreeNode4 = null;
try {
fileTreeNode1 = new FileTreeNode(new File(System.getProperty("user.dir")), "file1.txt");
fileTreeNode2 = new FileTreeNode(new File(System.getProperty("user.dir")), "file2.txt");
fileTreeNode3 = new FileTreeNode(new File(System.getProperty("user.dir")), "file3.txt");
fileTreeNode4 = new FileTreeNode(new File(System.getProperty("user.dir")), "file4.txt");
selectedData.put(fileTreeNode1, new TreePath(new DefaultMutableTreeNode("branch1")));
selectedData.put(fileTreeNode2, new TreePath(new DefaultMutableTreeNode("branch2")));
selectedData.put(fileTreeNode3, new TreePath(new DefaultMutableTreeNode("branch3")));
selectedData.put(fileTreeNode4, new TreePath(new DefaultMutableTreeNode("branch4")));
TransferableDataItem dataItem = new TransferableDataItem(selectedData);
DataFlavor dataFlavour = dataItem.getDataFlavour();
assertEquals(FileTreeNode.class, dataFlavour.getRepresentationClass());
try {
Object data = dataItem.getTransferData(DataFlavourManager.FOLDER_DATAITEM_FLAVOR);
assertTrue(data instanceof TransferredData);
assertEquals(selectedData.size(), ((TransferredData) data).getDataListSize());
assertFalse(dataItem.isDataFlavorSupported(BuiltInDataFlavour.GEOSERVER_DATAITEM_FLAVOUR));
assertTrue(dataItem.isDataFlavorSupported(DataFlavourManager.FOLDER_DATAITEM_FLAVOR));
} catch (UnsupportedFlavorException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
} catch (SecurityException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (FileNotFoundException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of com.sldeditor.datasource.extension.filesystem.dataflavour.TransferredData in project sldeditor by robward-scisys.
the class TransferredDataTest method testGetDataListSize.
/**
* Test method for {@link com.sldeditor.datasource.extension.filesystem.dataflavour.TransferredData#getDataListSize()}.
*/
@Test
public void testGetDataListSize() {
TransferredData data = new TransferredData();
assertEquals(0, data.getDataListSize());
Integer userObject1 = Integer.valueOf(42);
Double userObject2 = Double.valueOf(42.0);
String userObject3 = "xxxx";
SLDDataFlavour dataFlavour1 = new SLDDataFlavour(getClass(), "humanPresentableName");
SLDDataFlavour dataFlavour2 = new SLDDataFlavour(getClass(), "humanPresentableName");
SLDDataFlavour dataFlavour3 = new SLDDataFlavour(getClass(), "humanPresentableName");
TreePath treePath1 = new TreePath("test1");
TreePath treePath2 = new TreePath("test2");
TreePath treePath3 = new TreePath("test3");
data.addData(treePath1, userObject1, dataFlavour1);
data.addData(treePath2, userObject2, dataFlavour2);
data.addData(treePath3, userObject3, dataFlavour3);
assertEquals(3, data.getDataListSize());
assertEquals(dataFlavour2, data.getDataFlavour(1));
assertNull(data.getDataFlavour(-1));
assertNull(data.getDataFlavour(11));
assertEquals(userObject3, data.getUserObject(2));
assertNull(data.getUserObject(-1));
assertNull(data.getUserObject(11));
assertEquals(treePath1, data.getTreePath(0));
assertNull(data.getTreePath(-1));
assertNull(data.getTreePath(11));
}
Aggregations