/**
  * Gets the selected node in the tags tree and applies all attributes fro the attributes list to
  * it. Do nothing if no node is selected.
  */
 public void apply() {
   JTree tree = (JTree) document.getTagById("tagsTree").getComponent();
   if (tree.getSelectionPath() != null) {
     DefaultMutableTreeNode node =
         (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
     Tag tag = (Tag) node.getUserObject();
     for (Attribute attr : attributes) {
       tag.setAttribute(attr.getName(), attr.getValue());
     }
     tag.applyAttributes(tag.getComponent());
   }
 }
  /**
   * Updates attributes list on node selection change in the tags tree. Loads attributes of the
   * selected node into the attributes list. Just clears attributes if no node is selected.
   *
   * @param e
   */
  public void onTagChange(TreeSelectionEvent e) {
    if (e.getNewLeadSelectionPath() != null) {
      TreePath path = e.getNewLeadSelectionPath();
      attributes.clear();
      if (path.getPathCount() >= 1) {

        DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
        Tag tag = (Tag) node.getUserObject();
        for (String name : tag.getAttributes().keySet()) {
          Attribute attr = new Attribute();
          attr.setName(name);
          attr.setValue(tag.getAttribute(name));
          attributes.add(attr);
        }
      }
    }
  }