use of org.freeplane.plugin.workspace.model.AWorkspaceTreeNode in project freeplane by freeplane.
the class AWorkspaceAction method getSelectedNodes.
protected AWorkspaceTreeNode[] getSelectedNodes(ActionEvent e) {
JTree tree = null;
if (e.getSource() instanceof JTree) {
tree = (JTree) e.getSource();
} else {
WorkspacePopupMenu pop = getRootPopupMenu((Component) e.getSource());
if (pop == null) {
return null;
}
tree = (JTree) pop.getInvoker();
}
AWorkspaceTreeNode[] nodes = new AWorkspaceTreeNode[tree.getSelectionPaths().length];
int i = 0;
for (TreePath path : tree.getSelectionPaths()) {
nodes[i++] = (AWorkspaceTreeNode) path.getLastPathComponent();
}
return nodes;
}
use of org.freeplane.plugin.workspace.model.AWorkspaceTreeNode in project freeplane by freeplane.
the class AWorkspaceAction method getNodeFromActionEvent.
protected AWorkspaceTreeNode getNodeFromActionEvent(ActionEvent e) {
JTree tree = null;
TreePath path = null;
if (e.getSource() instanceof JTree) {
tree = (JTree) e.getSource();
path = tree.getSelectionPath();
} else {
WorkspacePopupMenu pop = getRootPopupMenu((Component) e.getSource());
if (pop == null) {
return null;
}
tree = (JTree) pop.getInvoker();
int x = pop.getInvokerLocation().x;
int y = pop.getInvokerLocation().y;
path = tree.getClosestPathForLocation(x, y);
}
if (path == null) {
return null;
}
return (AWorkspaceTreeNode) path.getLastPathComponent();
}
use of org.freeplane.plugin.workspace.model.AWorkspaceTreeNode in project freeplane by freeplane.
the class FileNodeNewMindmapAction method actionPerformed.
public void actionPerformed(final ActionEvent e) {
Controller.getCurrentController().selectMode(MModeController.MODENAME);
AWorkspaceTreeNode targetNode = this.getNodeFromActionEvent(e);
if (targetNode instanceof IFileSystemRepresentation) {
String fileName = JOptionPane.showInputDialog(Controller.getCurrentController().getViewController().getContentPane(), TextUtils.getText("add_new_mindmap"), TextUtils.getText("add_new_mindmap_title"), JOptionPane.OK_CANCEL_OPTION);
if (fileName != null && fileName.length() > 0) {
if (!fileName.endsWith(".mm")) {
fileName += ".mm";
}
File file = new File(((IFileSystemRepresentation) targetNode).getFile(), fileName);
try {
file = WorkspaceController.getFileSystemMgr().createFile(fileName, ((IFileSystemRepresentation) targetNode).getFile());
if (createNewMindmap(file)) {
targetNode.refresh();
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(UITools.getFrame(), ex.getMessage(), "Error ... ", JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
}
}
}
}
use of org.freeplane.plugin.workspace.model.AWorkspaceTreeNode 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.model.AWorkspaceTreeNode in project freeplane by freeplane.
the class NodePasteAction method actionPerformed.
public void actionPerformed(final ActionEvent e) {
AWorkspaceTreeNode targetNode = getNodeFromActionEvent(e);
if (DnDController.isDropAllowed(targetNode)) {
Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable transf = clip.getContents(null);
if (transf == null) {
return;
}
int dndAction = DnDConstants.ACTION_COPY;
if (transf.isDataFlavorSupported(WorkspaceTransferable.WORKSPACE_MOVE_NODE_FLAVOR)) {
dndAction = DnDConstants.ACTION_MOVE;
}
if (WorkspaceController.getCurrentModeExtension().getView() != null) {
try {
WorkspaceController.getCurrentModeExtension().getView().getTransferHandler().handleDrop(targetNode, transf, dndAction);
if (dndAction == DnDConstants.ACTION_MOVE) {
clip.setContents(null, null);
}
} catch (NoDropHandlerFoundExeption ex) {
LogUtils.info("Exception in org.freeplane.plugin.workspace.actions.NodePasteAction.actionPerformed(ActionEvent): " + ex.getMessage());
}
}
}
}
Aggregations