Search in sources :

Example 6 with DefaultFileNode

use of org.freeplane.plugin.workspace.nodes.DefaultFileNode in project freeplane by freeplane.

the class NodeRenameAction method actionPerformed.

public void actionPerformed(final ActionEvent e) {
    AWorkspaceTreeNode targetNode = this.getNodeFromActionEvent(e);
    String oldName = targetNode.getName();
    NodeRenameDialogPanel panel;
    // if (targetNode instanceof IMutableLinkNode) {
    // panel = new NodeRenameDialogPanel(oldName, true);
    // }
    // else {
    panel = new NodeRenameDialogPanel(oldName);
    if (targetNode instanceof DefaultFileNode) {
        panel.setCheckboxSelected(true);
    }
    // }
    int okButton = JOptionPane.showConfirmDialog(UITools.getFrame(), panel, TextUtils.getText("confirm_rename_file_action"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    String newName = panel.getText();
    if (okButton != JOptionPane.OK_OPTION || oldName.equals(newName)) {
        return;
    }
    if (newName != null) {
        if (targetNode instanceof IMutableLinkNode) {
            if (((IMutableLinkNode) targetNode).changeName(newName, panel.applyChangesForLink())) {
                targetNode.refresh();
            } else {
                JOptionPane.showMessageDialog(UITools.getFrame(), TextUtils.getText("error_rename_file"), TextUtils.getText("error_rename_file_title"), JOptionPane.ERROR_MESSAGE);
                targetNode.setName(oldName);
            }
        } else {
            try {
                targetNode.getModel().changeNodeName(targetNode, newName);
                targetNode.refresh();
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(UITools.getFrame(), TextUtils.getText("error_rename_file") + " (" + ex.getMessage() + ")", TextUtils.getText("error_rename_file_title"), JOptionPane.ERROR_MESSAGE);
            }
        }
    }
}
Also used : AWorkspaceTreeNode(org.freeplane.plugin.workspace.model.AWorkspaceTreeNode) IMutableLinkNode(org.freeplane.plugin.workspace.model.IMutableLinkNode) NodeRenameDialogPanel(org.freeplane.plugin.workspace.components.dialog.NodeRenameDialogPanel) DefaultFileNode(org.freeplane.plugin.workspace.nodes.DefaultFileNode)

Aggregations

AWorkspaceTreeNode (org.freeplane.plugin.workspace.model.AWorkspaceTreeNode)6 DefaultFileNode (org.freeplane.plugin.workspace.nodes.DefaultFileNode)6 File (java.io.File)3 LinkTypeFileNode (org.freeplane.plugin.workspace.nodes.LinkTypeFileNode)2 IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 NodeRenameDialogPanel (org.freeplane.plugin.workspace.components.dialog.NodeRenameDialogPanel)1 IFileSystemRepresentation (org.freeplane.plugin.workspace.io.IFileSystemRepresentation)1 ITask (org.freeplane.plugin.workspace.io.ITask)1 SkipTaskException (org.freeplane.plugin.workspace.io.SkipTaskException)1 IMutableLinkNode (org.freeplane.plugin.workspace.model.IMutableLinkNode)1 AFolderNode (org.freeplane.plugin.workspace.nodes.AFolderNode)1 ALinkNode (org.freeplane.plugin.workspace.nodes.ALinkNode)1 FolderFileNode (org.freeplane.plugin.workspace.nodes.FolderFileNode)1 FolderLinkNode (org.freeplane.plugin.workspace.nodes.FolderLinkNode)1