1 // WARNING: This file was automatically generated. Do not edit it directly,
2 // or you will lose your changes.
3
4 /*
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 */
22 package org.apache.myfaces.trinidad.component;
23
24 import java.util.Collections;
25 import java.util.Iterator;
26 import javax.el.MethodExpression;
27 import javax.faces.component.UIComponent;
28 import javax.faces.context.FacesContext;
29 import javax.faces.el.MethodBinding;
30 import javax.faces.event.AbortProcessingException;
31 import javax.faces.event.FacesEvent;
32 import javax.faces.event.PhaseId;
33 import org.apache.myfaces.trinidad.bean.FacesBean;
34 import org.apache.myfaces.trinidad.bean.PropertyKey;
35 import org.apache.myfaces.trinidad.event.DisclosureEvent;
36 import org.apache.myfaces.trinidad.event.DisclosureListener;
37 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
38 import org.apache.myfaces.trinidad.util.ComponentUtils;
39
40 /**
41 *
42 * <h4>Events:</h4>
43 * <table border="1" width="100%" cellpadding="3" summary="">
44 * <tr bgcolor="#CCCCFF" class="TableHeadingColor">
45 * <th align="left">Type</th>
46 * <th align="left">Phases</th>
47 * <th align="left">Description</th>
48 * </tr>
49 * <tr class="TableRowColor">
50 * <td valign="top"><code>org.apache.myfaces.trinidad.event.DisclosureEvent</code></td>
51 * <td valign="top" nowrap>Apply<br>Request<br>Values<br>Invoke<br>Application</td>
52 * <td valign="top">The disclosure event is delivered when a node is
53 disclosed.</td>
54 * </tr>
55 * <tr class="TableRowColor">
56 * <td valign="top"><code>org.apache.myfaces.trinidad.event.AttributeChangeEvent</code></td>
57 * <td valign="top" nowrap>Invoke<br>Application<br>Apply<br>Request<br>Values</td>
58 * <td valign="top">Event delivered to describe an attribute change. Attribute change events are not delivered for any programmatic change to a property. They are only delivered when a renderer changes a property without the application's specific request. An example of an attribute change event might include the width of a column that supported client-side resizing.</td>
59 * </tr>
60 * </table>
61 */
62 public class UIXShowDetail extends UIXComponentBase
63 {
64 static public final FacesBean.Type TYPE = new FacesBean.Type(
65 UIXComponentBase.TYPE);
66 static public final PropertyKey DISCLOSED_KEY =
67 TYPE.registerKey("disclosed", Boolean.class, Boolean.FALSE);
68 static public final PropertyKey DISCLOSED_TRANSIENT_KEY =
69 TYPE.registerKey("disclosedTransient", Boolean.class, Boolean.FALSE);
70 static public final PropertyKey IMMEDIATE_KEY =
71 TYPE.registerKey("immediate", Boolean.class, Boolean.FALSE);
72 static public final PropertyKey DISCLOSURE_LISTENER_KEY =
73 TYPE.registerKey("disclosureListener", MethodExpression.class);
74
75 static public final String COMPONENT_FAMILY =
76 "org.apache.myfaces.trinidad.ShowDetail";
77 static public final String COMPONENT_TYPE =
78 "org.apache.myfaces.trinidad.ShowDetail";
79
80 /**
81 * Construct an instance of the UIXShowDetail.
82 */
83 public UIXShowDetail()
84 {
85 super("org.apache.myfaces.trinidad.ShowDetail");
86 }
87
88 @Deprecated
89 public void setDisclosureListener(MethodBinding binding)
90 {
91 setDisclosureListener(adaptMethodBinding(binding));
92 }
93
94 @Override
95 public void broadcast(FacesEvent event) throws AbortProcessingException
96 {
97 // Perform standard superclass processing
98 super.broadcast(event);
99
100 if (event instanceof DisclosureEvent)
101 {
102 // Do not update the disclosed if "transient"
103 if (!isDisclosedTransient())
104 {
105 // Expand or collapse this showDetail
106 boolean isDisclosed = ((DisclosureEvent) event).isExpanded();
107 // If the component is already in that disclosure state, we
108 // have a renderer bug. Either it delivered an unnecessary event,
109 // or even worse it set disclosed on its own instead of waiting
110 // for the disclosure event to do that, which will lead to lifecycle
111 // problems. So in either case, warn the developer.
112 if (isDisclosed == isDisclosed())
113 {
114 _LOG.warning("EVENT_DELIVERED_ALREADY_IN_DISCLOSURE_STATE", event);
115 }
116 else
117 {
118 setDisclosed(isDisclosed);
119 }
120
121 //pu: Implicitly record a Change for 'disclosed' attribute
122 addAttributeChange("disclosed",
123 isDisclosed ? Boolean.TRUE : Boolean.FALSE);
124 }
125
126 if (isImmediate())
127 getFacesContext().renderResponse();
128
129 // Notify the specified disclosure listener method (if any)
130 broadcastToMethodExpression(event, getDisclosureListener());
131 }
132 }
133
134 @Override
135 public void queueEvent(FacesEvent e)
136 {
137 if ((e instanceof DisclosureEvent) && (e.getSource() == this))
138 {
139 if (isImmediate())
140 {
141 e.setPhaseId(PhaseId.ANY_PHASE);
142 }
143 else
144 {
145 e.setPhaseId(PhaseId.INVOKE_APPLICATION);
146 }
147 }
148
149 super.queueEvent(e);
150 }
151
152 protected Iterator<UIComponent> getRenderedFacetsAndChildren(FacesContext facesContext)
153 {
154 if (isDisclosed())
155 {
156 return super.getRenderedFacetsAndChildren(facesContext);
157 }
158 else
159 {
160 return Collections.<UIComponent>emptyList().iterator();
161 }
162 }
163
164 static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(UIXShowDetail.class);
165
166 /**
167 * Gets whether or not to disclose the children
168 *
169 * @return the new disclosed value
170 */
171 final public boolean isDisclosed()
172 {
173 return ComponentUtils.resolveBoolean(getProperty(DISCLOSED_KEY), false);
174 }
175
176 /**
177 * Sets whether or not to disclose the children
178 *
179 * @param disclosed the new disclosed value
180 */
181 final public void setDisclosed(boolean disclosed)
182 {
183 setProperty(DISCLOSED_KEY, disclosed ? Boolean.TRUE : Boolean.FALSE);
184 }
185
186 /**
187 * Gets stops the local value of disclosed from being set
188 * by renderers. This allows the value to always be taken from the value of the disclosed
189 * value expression. Disclosed values must be updated in other ways (i.e. from a
190 * disclosure listener)
191 *
192 * @return the new disclosedTransient value
193 */
194 final public boolean isDisclosedTransient()
195 {
196 return ComponentUtils.resolveBoolean(getProperty(DISCLOSED_TRANSIENT_KEY), false);
197 }
198
199 /**
200 * Sets stops the local value of disclosed from being set
201 * by renderers. This allows the value to always be taken from the value of the disclosed
202 * value expression. Disclosed values must be updated in other ways (i.e. from a
203 * disclosure listener)
204 *
205 * @param disclosedTransient the new disclosedTransient value
206 */
207 final public void setDisclosedTransient(boolean disclosedTransient)
208 {
209 setProperty(DISCLOSED_TRANSIENT_KEY, disclosedTransient ? Boolean.TRUE : Boolean.FALSE);
210 }
211
212 /**
213 * Gets whether data validation - client-side or
214 * server-side - should be skipped when
215 * events are generated by this component.
216 *
217 * When immediate is false (the default), the disclosure event will
218 * be delivered during the Invoke Application phase, which
219 * will trigger validation. When set to true, the disclosure
220 * event will be executed during the Apply Request Values phase.
221 *
222 * @return the new immediate value
223 */
224 final public boolean isImmediate()
225 {
226 return ComponentUtils.resolveBoolean(getProperty(IMMEDIATE_KEY), false);
227 }
228
229 /**
230 * Sets whether data validation - client-side or
231 * server-side - should be skipped when
232 * events are generated by this component.
233 *
234 * When immediate is false (the default), the disclosure event will
235 * be delivered during the Invoke Application phase, which
236 * will trigger validation. When set to true, the disclosure
237 * event will be executed during the Apply Request Values phase.
238 *
239 * @param immediate the new immediate value
240 */
241 final public void setImmediate(boolean immediate)
242 {
243 setProperty(IMMEDIATE_KEY, immediate ? Boolean.TRUE : Boolean.FALSE);
244 }
245
246 /**
247 * Gets a method reference to a disclosure listener
248 *
249 * @return the new disclosureListener value
250 */
251 final public MethodExpression getDisclosureListener()
252 {
253 return (MethodExpression)getProperty(DISCLOSURE_LISTENER_KEY);
254 }
255
256 /**
257 * Sets a method reference to a disclosure listener
258 *
259 * @param disclosureListener the new disclosureListener value
260 */
261 final public void setDisclosureListener(MethodExpression disclosureListener)
262 {
263 setProperty(DISCLOSURE_LISTENER_KEY, (disclosureListener));
264 }
265
266 /**
267 * Adds a disclosure listener.
268 *
269 * @param listener the disclosure listener to add
270 */
271 final public void addDisclosureListener(
272 DisclosureListener listener)
273 {
274 addFacesListener(listener);
275 }
276
277 /**
278 * Removes a disclosure listener.
279 *
280 * @param listener the disclosure listener to remove
281 */
282 final public void removeDisclosureListener(
283 DisclosureListener listener)
284 {
285 removeFacesListener(listener);
286 }
287
288 /**
289 * Returns an array of attached disclosure listeners.
290 *
291 * @return an array of attached disclosure listeners.
292 */
293 final public DisclosureListener[] getDisclosureListeners()
294 {
295 return (DisclosureListener[])getFacesListeners(DisclosureListener.class);
296 }
297
298 @Override
299 public String getFamily()
300 {
301 return COMPONENT_FAMILY;
302 }
303
304 @Override
305 protected FacesBean.Type getBeanType()
306 {
307 return TYPE;
308 }
309
310 /**
311 * Construct an instance of the UIXShowDetail.
312 */
313 protected UIXShowDetail(
314 String rendererType
315 )
316 {
317 super(rendererType);
318 }
319
320 static
321 {
322 TYPE.lockAndRegister("org.apache.myfaces.trinidad.ShowDetail","org.apache.myfaces.trinidad.ShowDetail");
323 }
324 }