use of org.freeplane.plugin.workspace.nodes.LinkTypeFileNode in project freeplane by freeplane.
the class NodeNewLinkAction method actionPerformed.
/**
*********************************************************************************
* METHODS
*********************************************************************************
*/
/**
*********************************************************************************
* REQUIRED METHODS FOR INTERFACES
*********************************************************************************
*/
public void actionPerformed(ActionEvent e) {
AWorkspaceTreeNode targetNode = null;
if (e == null || getRootPopupMenu((Component) e.getSource()) == null) {
targetNode = WorkspaceController.getCurrentProject().getModel().getRoot();
} else {
targetNode = getNodeFromActionEvent(e);
}
if (targetNode == null) {
return;
}
AWorkspaceProject project = WorkspaceController.getProject(targetNode);
if (targetNode instanceof AFolderNode) {
JFileChooser chooser = new JFileChooser(URIUtils.getAbsoluteFile(((AFolderNode) targetNode).getPath() == null ? WorkspaceController.getCurrentProject().getProjectHome() : ((AFolderNode) targetNode).getPath()));
chooser.setMultiSelectionEnabled(false);
int response = chooser.showOpenDialog(UITools.getFrame());
if (response == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
if (file != null) {
LinkTypeFileNode node = new LinkTypeFileNode();
node.setName(file.getName());
URI path = chooser.getSelectedFile().toURI();
if (path == null) {
return;
}
URI uri = project.getRelativeURI(path);
if (uri == null) {
node.setLinkURI(path);
} else {
node.setLinkURI(uri);
}
targetNode.getModel().addNodeTo(node, targetNode);
targetNode.refresh();
targetNode.getModel().requestSave();
}
}
}
}
use of org.freeplane.plugin.workspace.nodes.LinkTypeFileNode in project freeplane by freeplane.
the class VirtualFolderDropHandler method createFSNodeLinks.
/**
* @param file
* @return
*/
private AWorkspaceTreeNode createFSNodeLinks(AWorkspaceTreeNode targetNode, File file) {
AWorkspaceTreeNode node = null;
AWorkspaceProject project = WorkspaceController.getProject(targetNode);
if (file.isDirectory()) {
FolderLinkNode pNode = new FolderLinkNode();
pNode.setPath(project.getRelativeURI(file.toURI()));
node = pNode;
} else {
LinkTypeFileNode lNode = new LinkTypeFileNode();
lNode.setLinkURI(project.getRelativeURI(file.toURI()));
node = lNode;
}
node.setName(file.getName());
return node;
}
use of org.freeplane.plugin.workspace.nodes.LinkTypeFileNode in project freeplane by freeplane.
the class FileNodeDeleteAction method deleteFile.
private void deleteFile(final AWorkspaceTreeNode node) {
if (node instanceof DefaultFileNode) {
((DefaultFileNode) node).delete();
} else if (node instanceof LinkTypeFileNode) {
File file = URIUtils.getAbsoluteFile(((LinkTypeFileNode) node).getLinkURI());
if (file != null) {
if (!file.delete()) {
// show message?
}
}
}
AWorkspaceTreeNode parent = node.getParent();
node.getModel().removeNodeFromParent(node);
parent.refresh();
parent.getModel().requestSave();
}
use of org.freeplane.plugin.workspace.nodes.LinkTypeFileNode 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);
}
}
use of org.freeplane.plugin.workspace.nodes.LinkTypeFileNode in project freeplane by freeplane.
the class LinkTypeFileCreator method getNode.
@Override
public AWorkspaceTreeNode getNode(XMLElement data) {
String type = data.getAttribute("type", "file");
LinkTypeFileNode node = new LinkTypeFileNode(type);
String path = data.getAttribute("path", null);
if (path == null || path.length() == 0) {
return null;
}
node.setLinkURI(URIUtils.createURI(path));
String name = data.getAttribute("name", URIUtils.getAbsoluteFile(node.getLinkURI()).getName());
node.setName(name);
return node;
}
Aggregations