use of org.freeplane.plugin.workspace.io.ITask in project freeplane by freeplane.
the class FileFolderDropHandler method getPostOperation.
private ITask getPostOperation(final AWorkspaceTreeNode targetNode, final AWorkspaceTreeNode node, final File srcFile, final File destFile) {
return new ITask() {
public void exec(Properties properties) throws IOException {
if (onSkipList(destFile.getParentFile(), properties)) {
throw new SkipTaskException();
}
AWorkspaceTreeNode parent = node.getParent();
targetNode.getModel().cutNodeFromParent(node);
parent.refresh();
targetNode.getModel().nodeMoved(node, srcFile, destFile);
}
private boolean onSkipList(File dest, Properties properties) {
if (properties == null || dest == null) {
return false;
}
String list = properties.getProperty("skippedDirs", "");
String entry = dest.getPath() + ";";
if (list.contains(entry)) {
return true;
}
return false;
}
};
}
use of org.freeplane.plugin.workspace.io.ITask in project freeplane by freeplane.
the class FileFolderDropHandler method processWorkspaceNodeDrop.
/**
*********************************************************************************
* CONSTRUCTORS
*********************************************************************************
*/
/**
*********************************************************************************
* METHODS
*********************************************************************************
*/
private void processWorkspaceNodeDrop(AWorkspaceTreeNode targetNode, List<AWorkspaceTreeNode> nodes, int dropAction) {
try {
File targetDir = ((IFileSystemRepresentation) targetNode).getFile();
if (targetDir != null && targetDir.isDirectory()) {
List<ITask> opList = new ArrayList<ITask>();
for (AWorkspaceTreeNode node : nodes) {
if (node instanceof DefaultFileNode) {
File srcFile = ((DefaultFileNode) node).getFile();
if (srcFile.equals(targetDir)) {
continue;
}
File destFile = new File(targetDir, srcFile.getName());
if (dropAction == DnDConstants.ACTION_COPY) {
FileSystemManager.buildCopyOperationList(srcFile, destFile, opList);
} else if (dropAction == DnDConstants.ACTION_MOVE) {
FileSystemManager.buildMoveOperationList(srcFile, destFile, opList);
opList.add(getPostOperation(targetNode, node, srcFile, destFile));
}
} else if (node instanceof LinkTypeFileNode) {
File srcFile = URIUtils.getAbsoluteFile(((LinkTypeFileNode) node).getLinkURI());
if (srcFile.equals(targetDir)) {
continue;
}
File destFile = new File(targetDir, srcFile.getName());
FileSystemManager.buildCopyOperationList(srcFile, destFile, opList);
if (dropAction == DnDConstants.ACTION_MOVE) {
opList.add(getPostOperation(targetNode, node, srcFile, destFile));
}
} else if (node instanceof FolderLinkNode) {
File srcFile = URIUtils.getAbsoluteFile(((FolderLinkNode) node).getPath());
if (srcFile.equals(targetDir)) {
continue;
}
File destFile = new File(targetDir, srcFile.getName());
FileSystemManager.buildCopyOperationList(srcFile, destFile, opList);
if (dropAction == DnDConstants.ACTION_MOVE) {
opList.add(getPostOperation(targetNode, node, srcFile, destFile));
}
}
}
FileSystemManager.execOperations(opList);
}
} catch (Exception e) {
LogUtils.warn(e);
}
}
Aggregations