Search in sources :

Example 1 with NodeRenameDialogPanel

use of org.freeplane.plugin.workspace.components.dialog.NodeRenameDialogPanel 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

NodeRenameDialogPanel (org.freeplane.plugin.workspace.components.dialog.NodeRenameDialogPanel)1 AWorkspaceTreeNode (org.freeplane.plugin.workspace.model.AWorkspaceTreeNode)1 IMutableLinkNode (org.freeplane.plugin.workspace.model.IMutableLinkNode)1 DefaultFileNode (org.freeplane.plugin.workspace.nodes.DefaultFileNode)1