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 expanding or collapsing a component.
29   * <p>
30   * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-api/src/main/java/oracle/adf/view/faces/event/DisclosureEvent.java#0 $) $Date: 10-nov-2005.19:09:00 $
31   */
32  public class DisclosureEvent extends FacesEvent
33  {
34    public DisclosureEvent(UIComponent source, boolean expanded)
35    {
36      super(source);
37      _expanded = expanded;
38    }
39  
40    public boolean isExpanded()
41    {
42      return _expanded;
43    }
44  
45    @Override
46    public void processListener(FacesListener listener)
47    {
48      ((DisclosureListener) listener).processDisclosure(this);
49    }
50  
51    @Override
52    public boolean isAppropriateListener(FacesListener listener)
53    {
54      return (listener instanceof DisclosureListener);
55    }
56    
57    @Override
58    public int hashCode()
59    {
60      int expandedHC = (_expanded ? Boolean.TRUE.hashCode() 
61                                  : Boolean.FALSE.hashCode());
62      return (expandedHC << 4) ^
63             (getPhaseId().hashCode() << 8) ^
64             (getComponent().hashCode());
65    }
66    
67    @Override
68    public boolean equals(Object o)
69    {
70      if (o instanceof DisclosureEvent)
71      {
72        DisclosureEvent that = (DisclosureEvent)o;
73        return (this._expanded == that._expanded &&
74                this.getComponent().equals(that.getComponent()) &&
75                this.getPhaseId().equals(that.getPhaseId()));
76      }
77      
78      return false;
79    }
80  
81    @Override
82    public String toString()
83    {
84      StringBuffer sb = new StringBuffer();
85      sb.append(getClass().getName());
86      sb.append("[phaseId=");
87      sb.append(getPhaseId());
88      sb.append(",component=");
89      sb.append(getComponent());
90      sb.append(",expanded=");
91      sb.append(isExpanded());
92      sb.append(']');
93      return sb.toString();
94    }
95  
96    private final boolean _expanded;
97    private static final long serialVersionUID = 1L;
98  }