View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.custom.tree.event;
20  
21  import javax.faces.event.FacesEvent;
22  import javax.faces.event.FacesListener;
23  import javax.faces.component.UIComponent;
24  
25  import org.apache.myfaces.custom.tree.model.TreePath;
26  
27  
28  /**
29   * Event fired by {@link org.apache.myfaces.custom.tree.HtmlTree} on selection changes.
30   *
31   * @author <a href="mailto:oliver@rossmueller.com">Oliver Rossmueller</a>
32   * @version $Revision: 472638 $ $Date: 2006-11-08 15:54:13 -0500 (Wed, 08 Nov 2006) $
33   */
34  public class TreeSelectionEvent extends FacesEvent
35  {
36      private static final long serialVersionUID = -361206105634892091L;
37      private TreePath oldSelectionPath;
38      private TreePath newSelectionPath;
39  
40  
41      /**
42       * Construct an event.
43       *
44       * @param uiComponent      event source
45       * @param oldSelectionPath path of the old selection, null if no node was selected before
46       * @param newSelectionPath path of the current selection
47       */
48      public TreeSelectionEvent(UIComponent uiComponent, TreePath oldSelectionPath, TreePath newSelectionPath)
49      {
50          super(uiComponent);
51          this.oldSelectionPath = oldSelectionPath;
52          this.newSelectionPath = newSelectionPath;
53      }
54  
55  
56      /**
57       * Answer the path of the old selection.
58       *
59       * @return path of previous (old) selection, null if no node was selected before
60       */
61      public TreePath getOldSelectionPath()
62      {
63          return oldSelectionPath;
64      }
65  
66  
67      /**
68       * Answer the path of the current (new) selection.
69       *
70       * @return path of the new selected node
71       */
72      public TreePath getNewSelectionPath()
73      {
74          return newSelectionPath;
75      }
76  
77  
78      public boolean isAppropriateListener(FacesListener faceslistener)
79      {
80          return faceslistener instanceof TreeSelectionListener;
81      }
82  
83  
84      public void processListener(FacesListener faceslistener)
85      {
86          ((TreeSelectionListener) faceslistener).valueChanged(this);
87      }
88  }