title: Multiple event listener and adapter
body: <p>I am creating my custom event listener for Tree. I have created a listener interface here it is </p>
  
  <pre><code>public interface TreeActionListener extends EventListener {
      public void onAddNode(TreeEventObject eventObject);
      public void onRemoveNode(TreeEventObject eventObject);
      public void onRenameNode(TreeEventObject eventObject);
      public void onCreateNode(TreeEventObject eventObject);
  }
  </code></pre>
  
  <p>Also I've created custom event object named TreeEventObject here is code</p>
  
  <pre><code>public class TreeEventObject extends EventObject {
      private Object dataToPass =null;
      /**
       * Constructs a prototypical Event.
       *
       * @param source The object on which the Event initially occurred.
       * @throws IllegalArgumentException if source is null.
       */
  
      public TreeEventObject(Object source, Object dataToPass) {
          super(source);
          this.dataToPass = dataToPass;
      }
      public Object getPassedData() {
          return this.dataToPass;
      }
  }
  </code></pre>
  
  <p>And as mentioned in jdk pattern adapter is widely used. It used when I have a lot of methods in listener interface, but I need only one method. 
  So I have created my adapter </p>
  
  <pre><code>public class TreeActionAdapter implements TreeActionListener {
      @Override
      public void onAddNode(TreeEventObject eventObject) {
  
      }
  
      @Override
      public void onRemoveNode(TreeEventObject eventObject) {
  
      }
  
      @Override
      public void onRenameNode(TreeEventObject eventObject) {
  
      }
  
      @Override
      public void onCreateNode(TreeEventObject eventObject) {
  
      }
  }
  </code></pre>
  
  <p>But I am a little confused about one thing. I want to write code as clean as possible and  use patterns. So I wonder what is the most elegant way to do the next.
  I have class that has my listener as field. 
  I have four different events that can be occurred. So what is the right way to fire events. 
  I have some ideas, but don't know which is better.</p>
  
  <ol>
  <li><p>Create only one fireEvent method that should check what type of event has been performed. in case of else if. And if to do this way I should create for example enum and create field type in my event object and than in constructor to set it, and check it later in fireEvent method. And depending on type call different methods from listeners list. For instance :</p>
  
  <blockquote>
  <pre><code>  if(event.type==NODE_ADD) {
      for (TreeActionListener listener: listeners) {
          listener.onAddNode(event);
      }
      }else 
      if(event.type==NODE_DELETE) {
      for (TreeActionListener listener: listeners) {
          listener.onDeleteNode(event);
      }
       }
  </code></pre>
  </blockquote>
  
  <ol start="2">
  <li><p>Use different types of fireEvent methods : fireAddEvent,fireDelete event....... And depending on this also call different listener methods.</p></li>
  <li><p>Create separate arrays for each type of listener. And use special fireEvent method too.</p></li>
  </ol></li>
  </ol>
  
  <p>I don't know what will be better and good practice. Please suggest some other implementation or the best from listed before. 
  Thanks in advance </p>