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.trinidad.event;
20  
21  import javax.faces.component.UIComponent;
22  
23  import javax.faces.event.FacesEvent;
24  import javax.faces.event.FacesListener;
25  
26  
27  /**
28   * Event delivered when focusing on a node in a tree. The event includes information
29   * about the old and the new focus row keys.
30   * <p>
31   * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-api/src/main/java/oracle/adf/view/faces/event/FocusEvent.java#0 $) $Date: 10-nov-2005.19:09:01 $
32   */
33  public class FocusEvent extends FacesEvent
34  {
35    /**
36     * Creates a new FocusEvent
37     * @param source source component
38     * @param oldKey old focus row key
39     * @param newKey new focus row key
40     */
41    public FocusEvent(UIComponent source, Object oldKey, Object  newKey)
42    {
43      super(source);
44      _oldKey  = oldKey;
45      _newKey  = newKey;    
46    }
47  
48    /**
49     * The constructor with no key info is currently need for backwards compatibility.
50     * Will be remove at a later time.  
51     * @param source
52     */
53    public FocusEvent(UIComponent source)
54    {
55      this(source, null, null);
56    }
57    
58    public Object getOldKey()
59    {
60      return _oldKey;
61    }
62  
63    public Object getNewKey()
64    {
65      return _newKey;
66    }
67  
68    @Override
69    public void processListener(FacesListener listener)
70    {
71      ((FocusListener) listener).processFocus(this);
72    }
73  
74    @Override
75    public boolean isAppropriateListener(FacesListener listener)
76    {
77      return (listener instanceof FocusListener);
78    }
79  
80    @Override
81    public int hashCode()
82    {
83      return (getComponent() == null) ? 0 : getComponent().hashCode();
84    }
85  
86    @Override
87    public boolean equals(Object o)
88    {
89      if (o instanceof FocusEvent)
90      {
91        FocusEvent that = (FocusEvent)o;
92        return (this.getComponent().equals(that.getComponent()));
93      }
94  
95      return false;
96    }
97  
98    @Override
99    public String toString()
100   {
101     StringBuffer sb = new StringBuffer();
102     sb.append(getClass().getName());
103     sb.append("[component=");
104     sb.append(getComponent());
105     sb.append(",oldKey=");
106     sb.append(getOldKey());
107     sb.append(",newKey=");
108     sb.append(getNewKey());
109     sb.append(']');
110     return sb.toString();
111   }
112 
113   private final Object _oldKey;
114   private final Object _newKey;
115   private static final long serialVersionUID = 1L;
116 }