title: Get Edited TreeNode from a CellEditorListener
body: <p>Earlier I asked how  to fire an event when a TreeNode was renamed (<a href="https://stackoverflow.com/questions/11105401/java-defaultmutabletreenode-event-when-renamed/11105565">here</a>). My question was answered, but I ran into another problem. I need to access the TreeNode that is being edited in the CellEditorListener's editingStopped event. This is the code I have to do so:</p>
  
  <pre><code>package com.gamecreator;
  
  import javax.swing.event.CellEditorListener;
  import javax.swing.event.ChangeEvent;
  import javax.swing.tree.DefaultTreeCellEditor;
  
  public class CustomCellEditorListener implements CellEditorListener {
      public CustomCellEditorListener() {
  
      }
  
      public void editingCanceled(ChangeEvent e) {
  
      }
  
      public void editingStopped(ChangeEvent e) {
          DefaultTreeCellEditor editor = (DefaultTreeCellEditor) e.getSource(); //This gives me the error.
          CustomTreeNode node = //What do I put here???;
          node.getResource().setName((String) node.getUserObject());
  
          //For debugging
          System.out.println(node.getResource().getName());
      }
  }
  </code></pre>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p>Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException:
    javax.swing.tree.DefaultTreeCellEditor$1 cannot be cast to
    javax.swing.tree.DefaultTreeCellEditor</p>
  </blockquote>
  
  <p>EDIT:
  In another attempt, I used this code in the CustomCellEditorListener</p>
  
  <pre><code>public void editingStopped(ChangeEvent e) {
      TreePath path = ((CustomTreeCellEditor) e.getSource()).getLastPath();  //This gives me the error.
      CustomTreeNode node = (CustomTreeNode) path.getLastPathComponent();
      node.getResource().setName((String) node.getUserObject());
  
      //For debugging
      System.out.println(node.getResource().getName());
  }
  </code></pre>
  
  <p>and this code in the CustomTreeCellEditor</p>
  
  <pre><code>public TreePath getLastPath() {
      return lastPath;
  }
  </code></pre>
  
  <p>I got the same error (I expected I would). What I have should work, so the only real question remaining is, "Why am I getting the error and how can I fix it?," but if anyone has a better way to accomplish this, I'm willing to listen.</p>
  
  <p>EDIT 2:
  I have made a small example of what I'm trying to accomplish that can be found <a href="https://www.box.com/s/449e16cecb84bf4d4198" rel="nofollow noreferrer">here</a> (It's an Eclipse archive).</p>