1
2
3
4
5 package pt.digitalis.dif.presentation.views.jsp.taglibs.objects;
6
7 import java.util.List;
8 import java.util.Map;
9
10 import pt.digitalis.dif.controller.http.HTTPConstants;
11 import pt.digitalis.dif.controller.interfaces.IDIFRequest;
12 import pt.digitalis.dif.presentation.views.jsp.taglibs.AbstractDIFTag;
13 import pt.digitalis.dif.presentation.views.jsp.taglibs.layout.Wizard;
14 import pt.digitalis.dif.presentation.views.jsp.taglibs.objects.beans.WizardStepItem;
15
16
17
18
19
20
21
22 public class WizardDefinition {
23
24
25 public static final String HTML_ACTION_PARAMETER = "_wiz_nav_action";
26
27
28 public static final String HTML_EXECUTION_STATE_PARAMETER = "_wiz_executed_step";
29
30
31 public static final String HTML_STEP_PARAMETER = "_wiz_step";
32
33
34 public static final String HTML_TO_STEP_PARAMETER = "_wiz_nav_tostep";
35
36
37 public static final String LEFT_INDEX_LAYOUT = "left";
38
39
40 public static final String TOP_INDEX_LAYOUT = "top";
41
42
43 public static final int TOP_INDEX_MAX_CHARS = 100;
44
45
46
47
48
49 public static final int TOP_INDEX_SINGLE_MAX_CHARS = 30;
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 static public int getWizardActiveStepNumber(IDIFRequest request, String wizardName, boolean hasIndex,
65 boolean canNavigate, WizardDefinition wizardDef)
66 {
67 int wizardStep;
68
69 Object stepParameter = request.getParameter(HTML_STEP_PARAMETER);
70 Object actionParameter = request.getParameter(HTML_ACTION_PARAMETER);
71 Object formParameter = request.getParameter(HTTPConstants.FORM_SUBMIT_NAME);
72 Object stageParameter = request.getParameter(HTTPConstants.FORM_SUBMIT_STAGE);
73 Object directStepNavParameter = request.getParameter(HTML_TO_STEP_PARAMETER);
74
75 if (stepParameter == null && wizardDef != null)
76 {
77
78 for (int i = 0; i < wizardDef.getItems().size(); i++)
79 {
80 if (request.getStage().equals(wizardDef.getItems().get(i).getStageId()))
81 {
82
83 actionParameter = request.getParameter(WizardDefinition.HTML_ACTION_PARAMETER);
84
85 stepParameter = ++i;
86
87 break;
88 }
89 }
90
91
92
93 if (wizardDef.getHasIndexPage() && stepParameter != null && (Integer) stepParameter == 2)
94 {
95 Object submittedStage = request.getParameter(HTTPConstants.FORM_SUBMIT_STAGE);
96
97 if (submittedStage == null || request.getStage().equalsIgnoreCase(submittedStage.toString()))
98 stepParameter = 1;
99 }
100
101 request.addParameter(WizardDefinition.HTML_STEP_PARAMETER, stepParameter);
102 request.addParameter(WizardDefinition.HTML_TO_STEP_PARAMETER, stepParameter);
103 request.addParameter(HTTPConstants.FORM_SUBMIT_NAME, wizardDef.getName());
104 request.addParameter(HTTPConstants.FORM_SUBMIT_STAGE, request.getStage());
105
106 stepParameter = request.getParameter(HTML_STEP_PARAMETER);
107 actionParameter = request.getParameter(HTML_ACTION_PARAMETER);
108 formParameter = wizardDef.getName();
109 stageParameter = request.getStage();
110 }
111
112 if (stepParameter == null || formParameter == null || !wizardName.equalsIgnoreCase(formParameter.toString())
113 || stageParameter == null || !request.getStage().equalsIgnoreCase(stageParameter.toString()))
114 wizardStep = 1;
115 else
116 {
117 wizardStep = Integer.parseInt(stepParameter.toString());
118
119 if (canNavigate || (hasIndex && wizardStep == 1))
120 {
121 if (directStepNavParameter != null)
122 {
123 wizardStep = Integer.parseInt(directStepNavParameter.toString().split(" ")[0]);
124
125 }
126 else if (actionParameter != null)
127 {
128 String action = actionParameter.toString();
129 Map<String, String> messages = AbstractDIFTag.getTagMessages(Wizard.class, request.getSession()
130 .getLanguage());
131
132 if (action.equalsIgnoreCase(messages.get("previous")) && wizardStep > 1)
133 wizardStep--;
134
135 else if (action.equalsIgnoreCase(messages.get("next")) && wizardStep < 90)
136 wizardStep++;
137 }
138 }
139 }
140
141 return wizardStep;
142 }
143
144
145 private Integer activeStep;
146
147
148 private Boolean canFinish;
149
150
151 private String description;
152
153
154 private String formLayout;
155
156
157 private Boolean hasIndexPage;
158
159
160 private Integer height;
161
162
163 private String indexLayout;
164
165
166 private List<WizardStepItem> items;
167
168
169 private String name;
170
171
172 private boolean noRequiredIndicator = false;
173
174
175 private Boolean readonly = false;
176
177
178 private Boolean showIndex;
179
180
181 private boolean showTitlePrefix = true;
182
183
184 private String submitTitle;
185
186
187 private String title;
188
189
190 private String titlePrefix;
191
192
193 private Boolean topNavigation = false;
194
195
196 private Boolean wrapWithForm = true;
197
198
199
200
201
202
203
204 public WizardDefinition(String name, List<WizardStepItem> items)
205 {
206 this.items = items;
207 this.name = name;
208 this.activeStep = null;
209 }
210
211
212
213
214
215
216
217
218 public WizardDefinition(String name, List<WizardStepItem> items, int activeStep)
219 {
220 this.items = items;
221 this.name = name;
222 this.activeStep = activeStep;
223 }
224
225
226
227
228 public int getActiveStep()
229 {
230 return activeStep;
231 }
232
233
234
235
236 public Boolean getCanFinish()
237 {
238 if (canFinish == null)
239 return (getActiveStep() == items.size());
240 else
241 return canFinish;
242 }
243
244
245
246
247 public String getDescription()
248 {
249 return description;
250 }
251
252
253
254
255
256
257 public String getFormLayout()
258 {
259 return formLayout;
260 }
261
262
263
264
265 public Boolean getHasIndexPage()
266 {
267 if (hasIndexPage == null)
268 return getDescription() != null;
269 else
270 return hasIndexPage;
271 }
272
273
274
275
276
277
278 public Integer getHeight()
279 {
280 return height;
281 }
282
283
284
285
286 public String getIndexLayout()
287 {
288 if (indexLayout == null)
289 return LEFT_INDEX_LAYOUT;
290
291 return indexLayout;
292 }
293
294
295
296
297 public List<WizardStepItem> getItems()
298 {
299 return items;
300 }
301
302
303
304
305 public String getName()
306 {
307 return name;
308 }
309
310
311
312
313
314
315 public Boolean getReadonly()
316 {
317 return readonly;
318 }
319
320
321
322
323 public Boolean getShowIndex()
324 {
325 if (showIndex == null)
326 return false;
327 else
328 return showIndex;
329 }
330
331
332
333
334
335
336 public String getSubmitTitle()
337 {
338 return submitTitle;
339 }
340
341
342
343
344 public String getTitle()
345 {
346 return title;
347 }
348
349
350
351
352
353
354 public String getTitlePrefix()
355 {
356 return titlePrefix;
357 }
358
359
360
361
362
363
364 public Boolean getTopNavigation()
365 {
366 return topNavigation;
367 }
368
369
370
371
372
373
374 public Boolean getWrapWithForm()
375 {
376 return wrapWithForm;
377 }
378
379
380
381
382
383
384 public boolean isNoRequiredIndicator()
385 {
386 return noRequiredIndicator;
387 }
388
389
390
391
392
393
394 public boolean isShowTitlePrefix()
395 {
396 return showTitlePrefix;
397 }
398
399
400
401
402
403 public void setActiveStep(int activeStep)
404 {
405 this.activeStep = activeStep;
406 }
407
408
409
410
411
412 public void setCanFinish(Boolean canFinish)
413 {
414 this.canFinish = canFinish;
415 }
416
417
418
419
420
421 public void setDescription(String description)
422 {
423 this.description = description;
424 }
425
426
427
428
429
430
431
432 public void setFormLayout(String formLayout)
433 {
434 this.formLayout = formLayout;
435 }
436
437
438
439
440
441 public void setHasIndexPage(Boolean hasIndexPage)
442 {
443 this.hasIndexPage = hasIndexPage;
444 }
445
446
447
448
449
450
451
452 public void setHeight(Integer height)
453 {
454 this.height = height;
455 }
456
457
458
459
460
461 public void setIndexLayout(String indexLayout)
462 {
463 this.indexLayout = indexLayout;
464 }
465
466
467
468
469
470 public void setItems(List<WizardStepItem> items)
471 {
472 this.items = items;
473 }
474
475
476
477
478
479 public void setName(String name)
480 {
481 this.name = name;
482 }
483
484
485
486
487
488
489
490 public void setNoRequiredIndicator(boolean noRequiredIndicator)
491 {
492 this.noRequiredIndicator = noRequiredIndicator;
493 }
494
495
496
497
498
499
500
501 public void setReadonly(Boolean readonly)
502 {
503 this.readonly = readonly;
504 }
505
506
507
508
509
510 public void setShowIndex(Boolean showIndex)
511 {
512 this.showIndex = showIndex;
513 }
514
515
516
517
518
519
520
521 public void setShowTitlePrefix(boolean showTitlePrefix)
522 {
523 this.showTitlePrefix = showTitlePrefix;
524 }
525
526
527
528
529
530
531
532 public void setSubmitTitle(String submitTitle)
533 {
534 this.submitTitle = submitTitle;
535 }
536
537
538
539
540
541 public void setTitle(String title)
542 {
543 this.title = title;
544 }
545
546
547
548
549
550
551
552 public void setTitlePrefix(String titlePrefix)
553 {
554 this.titlePrefix = titlePrefix;
555 }
556
557
558
559
560
561
562
563 public void setTopNavigation(Boolean topNavigation)
564 {
565 this.topNavigation = topNavigation;
566 }
567
568
569
570
571
572
573
574 public void setWrapWithForm(Boolean wrapWithForm)
575 {
576 this.wrapWithForm = wrapWithForm;
577 }
578 }