1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.myfaces.trinidad.component;
23
24 import javax.faces.component.ActionSource;
25 import javax.faces.context.FacesContext;
26 import javax.faces.el.MethodBinding;
27 import javax.faces.event.AbortProcessingException;
28 import javax.faces.event.ActionEvent;
29 import javax.faces.event.ActionListener;
30 import javax.faces.event.FacesEvent;
31 import javax.faces.event.PhaseId;
32 import org.apache.myfaces.trinidad.bean.FacesBean;
33 import org.apache.myfaces.trinidad.bean.PropertyKey;
34 import org.apache.myfaces.trinidad.util.ComponentUtils;
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 public class UIXSingleStep extends UIXComponentBase
92 implements ActionSource
93 {
94 static public final FacesBean.Type TYPE = new FacesBean.Type(
95 UIXComponentBase.TYPE);
96 static public final PropertyKey SELECTED_STEP_KEY =
97 TYPE.registerKey("selectedStep", Integer.class, Integer.valueOf(1));
98 static public final PropertyKey MAX_STEP_KEY =
99 TYPE.registerKey("maxStep", Integer.class, Integer.valueOf(-1));
100 static public final PropertyKey PREVIOUS_ACTION_LISTENER_KEY =
101 TYPE.registerKey("previousActionListener", MethodBinding.class, PropertyKey.CAP_NOT_BOUND | PropertyKey.CAP_STATE_HOLDER);
102 static public final PropertyKey NEXT_ACTION_LISTENER_KEY =
103 TYPE.registerKey("nextActionListener", MethodBinding.class, PropertyKey.CAP_NOT_BOUND | PropertyKey.CAP_STATE_HOLDER);
104 static public final PropertyKey NEXT_ACTION_KEY =
105 TYPE.registerKey("nextAction", MethodBinding.class, PropertyKey.CAP_NOT_BOUND | PropertyKey.CAP_STATE_HOLDER);
106 static public final PropertyKey PREVIOUS_ACTION_KEY =
107 TYPE.registerKey("previousAction", MethodBinding.class, PropertyKey.CAP_NOT_BOUND | PropertyKey.CAP_STATE_HOLDER);
108
109 static public final String COMPONENT_FAMILY =
110 "org.apache.myfaces.trinidad.SingleStep";
111 static public final String COMPONENT_TYPE =
112 "org.apache.myfaces.trinidad.SingleStep";
113
114
115
116
117 public UIXSingleStep()
118 {
119 super("org.apache.myfaces.trinidad.ButtonBar");
120 }
121
122 @Override
123 public void queueEvent(FacesEvent e)
124 {
125 if (e.getSource() == this)
126 {
127 if (getActionType() == PREVIOUS_ACTION_TYPE)
128 e.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
129 else
130 e.setPhaseId(PhaseId.INVOKE_APPLICATION);
131 }
132
133 super.queueEvent(e);
134 }
135
136
137 public Object getActionType()
138 {
139 return _actionType;
140 }
141
142
143 public void setActionType(Object actionType)
144 {
145 _actionType = actionType;
146 }
147
148
149
150
151
152 @Override
153 public Object saveState(FacesContext context)
154 {
155 return super.saveState(context);
156 }
157
158 @Override
159 public void broadcast(FacesEvent event) throws AbortProcessingException
160 {
161
162 super.broadcast(event);
163
164
165 FacesContext context = getFacesContext();
166
167
168 if (event instanceof ActionEvent)
169 {
170 if (getActionType() == PREVIOUS_ACTION_TYPE)
171 {
172 broadcastToMethodBinding(event, getPreviousActionListener());
173 }
174 else
175 {
176 broadcastToMethodBinding(event, getNextActionListener());
177 }
178
179 ActionListener defaultActionListener =
180 context.getApplication().getActionListener();
181
182 if (defaultActionListener != null)
183 defaultActionListener.processAction((ActionEvent) event);
184 }
185 }
186
187 public MethodBinding getAction()
188 {
189 if ( getActionType() == PREVIOUS_ACTION_TYPE)
190 return getPreviousAction();
191
192 return getNextAction();
193 }
194
195
196
197 public void setAction(MethodBinding action)
198 {
199 if ( getActionType() == PREVIOUS_ACTION_TYPE)
200 setPreviousAction(action);
201 else
202 setNextAction(action);
203 }
204
205 public MethodBinding getActionListener()
206 {
207 if ( getActionType() == PREVIOUS_ACTION_TYPE)
208 return getPreviousActionListener();
209
210 return getNextActionListener();
211 }
212
213
214
215 public void setActionListener(MethodBinding listener)
216 {
217 if ( getActionType() == PREVIOUS_ACTION_TYPE)
218 setPreviousActionListener(listener);
219 else
220 setNextActionListener(listener);
221 }
222
223
224
225
226 public boolean isImmediate()
227 {
228 return (getActionType() == PREVIOUS_ACTION_TYPE);
229 }
230
231
232
233
234
235
236
237
238 public void setImmediate(boolean immediate)
239 {
240
241 }
242
243 private Object _actionType = NEXT_ACTION_TYPE;
244
245 public static final Object NEXT_ACTION_TYPE = new Object();
246 public static final Object PREVIOUS_ACTION_TYPE = new Object();
247
248
249
250
251
252
253
254
255
256
257
258 final public int getSelectedStep()
259 {
260 return ComponentUtils.resolveInteger(getProperty(SELECTED_STEP_KEY), 1);
261 }
262
263
264
265
266
267
268
269 final public void setSelectedStep(int selectedStep)
270 {
271 setProperty(SELECTED_STEP_KEY, Integer.valueOf(selectedStep));
272 }
273
274
275
276
277
278
279
280 final public void setSelectedStep(long selectedStep)
281 {
282 setProperty(SELECTED_STEP_KEY, Long.valueOf(selectedStep));
283 }
284
285
286
287
288
289
290
291
292
293
294
295
296 final public int getMaxStep()
297 {
298 return ComponentUtils.resolveInteger(getProperty(MAX_STEP_KEY), -1);
299 }
300
301
302
303
304
305
306
307
308
309
310
311
312 final public void setMaxStep(int maxStep)
313 {
314 setProperty(MAX_STEP_KEY, Integer.valueOf(maxStep));
315 }
316
317
318
319
320
321
322
323
324
325
326
327
328 final public void setMaxStep(long maxStep)
329 {
330 setProperty(MAX_STEP_KEY, Long.valueOf(maxStep));
331 }
332
333
334
335
336
337
338
339
340 final public MethodBinding getPreviousActionListener()
341 {
342 return (MethodBinding)getProperty(PREVIOUS_ACTION_LISTENER_KEY);
343 }
344
345
346
347
348
349
350
351
352 final public void setPreviousActionListener(MethodBinding previousActionListener)
353 {
354 setProperty(PREVIOUS_ACTION_LISTENER_KEY, (previousActionListener));
355 }
356
357
358
359
360
361
362
363
364 final public MethodBinding getNextActionListener()
365 {
366 return (MethodBinding)getProperty(NEXT_ACTION_LISTENER_KEY);
367 }
368
369
370
371
372
373
374
375
376 final public void setNextActionListener(MethodBinding nextActionListener)
377 {
378 setProperty(NEXT_ACTION_LISTENER_KEY, (nextActionListener));
379 }
380
381
382
383
384
385
386
387
388 final public MethodBinding getNextAction()
389 {
390 return (MethodBinding)getProperty(NEXT_ACTION_KEY);
391 }
392
393
394
395
396
397
398
399
400 final public void setNextAction(MethodBinding nextAction)
401 {
402 setProperty(NEXT_ACTION_KEY, (nextAction));
403 }
404
405
406
407
408
409
410
411
412 final public MethodBinding getPreviousAction()
413 {
414 return (MethodBinding)getProperty(PREVIOUS_ACTION_KEY);
415 }
416
417
418
419
420
421
422
423
424 final public void setPreviousAction(MethodBinding previousAction)
425 {
426 setProperty(PREVIOUS_ACTION_KEY, (previousAction));
427 }
428
429
430
431
432
433
434 final public void addActionListener(
435 ActionListener listener)
436 {
437 addFacesListener(listener);
438 }
439
440
441
442
443
444
445 final public void removeActionListener(
446 ActionListener listener)
447 {
448 removeFacesListener(listener);
449 }
450
451
452
453
454
455
456 final public ActionListener[] getActionListeners()
457 {
458 return (ActionListener[])getFacesListeners(ActionListener.class);
459 }
460
461 @Override
462 public String getFamily()
463 {
464 return COMPONENT_FAMILY;
465 }
466
467 @Override
468 protected FacesBean.Type getBeanType()
469 {
470 return TYPE;
471 }
472
473
474
475
476 protected UIXSingleStep(
477 String rendererType
478 )
479 {
480 super(rendererType);
481 }
482
483 static
484 {
485 TYPE.lockAndRegister("org.apache.myfaces.trinidad.SingleStep","org.apache.myfaces.trinidad.ButtonBar");
486 }
487 }