void removeSelectedNode() {
    PreferencesNode selectedNode = this.selectedPreferencesNode();
    if (selectedNode == null || selectedNode.cannotBeRemoved()) {
      return;
    }

    TreePath postRemoveSelectionPath = this.calculatePostRemoveSelectionPath(selectedNode);
    // clear the selection *before* removing the node, so we are no longer
    // listening to the node when it gets deleted - it will be in an invalid state...
    this.treeSelectionModel.clearSelection();
    Preferences preferences = selectedNode.preferences();
    try {
      preferences.removeNode();
      // flush the change, so an event is fired and the parent node is updated
      preferences.flush();
    } catch (BackingStoreException ex) {
      this.handleException(ex);
      return; // skip the selection of the parent node...
    }
    this.treeSelectionModel.setSelectionPath(postRemoveSelectionPath);
  }
  /** we can't simply rename the node - we have to clone it, then remove it... */
  void renameSelectedNode() {
    PreferencesNode selectedNode = this.selectedPreferencesNode();
    if (selectedNode == null || selectedNode.cannotBeRemoved()) {
      return;
    }

    String name = this.promptForNodeName();
    if (name == null) {
      return;
    }

    Preferences oldPreferences = selectedNode.preferences();
    PreferencesNode parentNode = (PreferencesNode) selectedNode.getParent();
    Preferences parentPreferences = parentNode.preferences();
    try {
      if (parentPreferences.nodeExists(name)) {
        // cannot rename to same name as existing node
        return;
      }
    } catch (BackingStoreException ex) {
      this.handleException(ex);
      return;
    }

    // clear the selection *before* removing the node, so we are no longer
    // listening to the node when it gets deleted - it will be in an invalid state...
    this.treeSelectionModel.clearSelection();
    Preferences newPreferences = parentPreferences.node(name);
    try {
      this.clone(oldPreferences, newPreferences);
      oldPreferences.removeNode();
      // flush the changes, so events are fired and the tree is updated
      parentPreferences.flush();
    } catch (BackingStoreException ex) {
      this.handleException(ex);
      return; // skip the selection of a node that might not be there...
    }
    PreferencesNode newNode = parentNode.childNodeFor(newPreferences);
    this.treeSelectionModel.setSelectionPath(new TreePath(newNode.getPath()));
  }