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 * A RangeChangeEvent is a notification that the range of the
29 * source component has been changed as a result of user interface activity.
30 * It contains the old start and end values and the new start and end values.
31 * <p>
32 * @version $Name: $ ($Revision: adfrt/faces/adf-faces-api/src/main/java/oracle/adf/view/faces/event/RangeChangeEvent.java#0 $) $Date: 10-nov-2005.19:09:04 $
33 */
34 public class RangeChangeEvent extends FacesEvent
35 {
36 /**
37 * Construct a new event object from the specified source component,
38 * old start (inclusive), old end (exclusive), new start (inclusive)
39 * and new end (exclusive).
40 * @param source - Source UIComponent for this event
41 * @param oldStart - The previous start of this UIComponent's selected range,
42 * inclusive
43 * @param oldEnd - The previous end of this UIComponent's selected range,
44 * exclusive
45 * @param newStart - The new start of this UIComponent's selected range,
46 * inclusive
47 * @param newEnd - The new end of this UIComponent's selected range,
48 * exclusive
49 */
50 public RangeChangeEvent(
51 UIComponent source,
52 int oldStart,
53 int oldEnd,
54 int newStart,
55 int newEnd)
56 {
57 super(source);
58 _oldStart = oldStart;
59 _oldEnd = oldEnd;
60 _newStart = newStart;
61 _newEnd = newEnd;
62
63 }
64
65 /**
66 * Returns the old start of the range, inclusive. E.g.,
67 * if the old range was for the first 5 items, oldStart would be 0.
68 */
69 public int getOldStart()
70 {
71 return _oldStart;
72 }
73
74 /**
75 * Returns the old end of the range, exclusive.E.g.,
76 * if the old range was for the first 5 items, oldEnd would be 5.
77 */
78 public int getOldEnd()
79 {
80 return _oldEnd;
81 }
82 /**
83 * Returns the new start, inclusive. E.g.,
84 * if the new range is for the second 5 items, newStart would be 5.
85 */
86 public int getNewStart()
87 {
88 return _newStart;
89 }
90
91 /**
92 * Returns the new end, exclusive. E.g.,
93 * if the new range is for the second 5 items, newEnd would be 10.
94 */
95 public int getNewEnd()
96 {
97 return _newEnd;
98 }
99
100 @Override
101 public void processListener(FacesListener listener)
102 {
103 ((RangeChangeListener)listener).processRangeChange(this);
104 }
105
106 @Override
107 public boolean isAppropriateListener(FacesListener listener)
108 {
109 return (listener instanceof RangeChangeListener);
110 }
111
112 @Override
113 public int hashCode()
114 {
115 return (_newStart << 4) ^
116 (getPhaseId().hashCode() << 8) ^
117 (getComponent().hashCode());
118 }
119
120 @Override
121 public boolean equals(Object o)
122 {
123 if (o instanceof RangeChangeEvent)
124 {
125 RangeChangeEvent that = (RangeChangeEvent)o;
126 return (this._newStart == that._newStart &&
127 this._newEnd == that._newEnd &&
128 this._oldStart == that._oldStart &&
129 this._oldEnd== that._oldEnd &&
130 this.getComponent().equals(that.getComponent()) &&
131 this.getPhaseId().equals(that.getPhaseId()));
132 }
133
134 return false;
135 }
136
137 @Override
138 public String toString()
139 {
140 StringBuffer sb = new StringBuffer();
141 sb.append(getClass().getName());
142 sb.append("[phaseId=");
143 sb.append(getPhaseId());
144 sb.append(",component=");
145 sb.append(getComponent());
146 sb.append(",newStart=");
147 sb.append(getNewStart());
148 sb.append(",newEnd=");
149 sb.append(getNewEnd());
150 sb.append(",oldStart=");
151 sb.append(getOldStart());
152 sb.append(",oldEnd=");
153 sb.append(getOldEnd());
154 sb.append(']');
155 return sb.toString();
156 }
157
158 private final int _oldStart;
159 private final int _oldEnd;
160 private final int _newStart;
161 private final int _newEnd;
162
163 private static final long serialVersionUID = 1L;
164 }