KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > guiframework > view > DescriptorWizardImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.tools.guiframework.view;
25
26 import com.iplanet.jato.RequestContext;
27 import com.iplanet.jato.RequestManager;
28 import com.iplanet.jato.model.Model;
29 import com.iplanet.jato.view.View;
30
31 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
32 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor;
33 import com.sun.enterprise.tools.guiframework.exception.FrameworkError;
34 import com.sun.enterprise.tools.guiframework.event.descriptors.EventDescriptor;
35
36 import com.sun.web.ui.model.wizard.WizardEvent;
37 import com.sun.web.ui.model.wizard.WizardInterface;
38 import com.sun.web.ui.model.wizard.WizardInterfaceExt;
39 import com.sun.web.ui.model.CCWizardWindowModelInterface;
40
41 import java.lang.reflect.Field JavaDoc;
42 import java.util.ArrayList JavaDoc;
43 import java.util.Iterator JavaDoc;
44 import java.util.List JavaDoc;
45 import java.util.EventObject JavaDoc;
46
47
48 /**
49  * <p> I would have liked to have WizardWindowViewBean implement WizardImpl,
50  * however, the tags hard-code "WizardWindow" all over the place making it so
51  * only 1 instance of WizardWindowViewBean can exist. So, I was forced to
52  * make this a separate class.</p>
53  *
54  * <p> This implementation of WizardInterface uses Descriptor information
55  * stored in the ViewXML to define its information. However, even though it
56  * is defined as a "displayItem" in the ViewXML, it is not a View of any type.
57  * Hopefully in the in future this class can be merged with
58  * DescriptorWizardWindowViewBean.</p>
59  */

60
61 public class DescriptorWizardImpl implements WizardInterface, java.io.Serializable JavaDoc, WizardInterfaceExt {
62
63     /**
64      * Constructor.
65      *
66      * @param ctx The RequestContext
67      * @param name The name of the ViewBean
68      */

69     public DescriptorWizardImpl(RequestContext ctx, String JavaDoc name) {
70     // setRequestContext(ctx); Cannot store this b/c LH caches this obj.
71
if (name == null) {
72         throw new FrameworkException("Wizard name cannot be null! It "
73             + "is required to find the ViewDescriptor!");
74     }
75     setName(name);
76     ViewDescriptor viewDesc =
77         ViewDescriptorManager.getInstance().getViewDescriptor(name);
78     if (viewDesc == null) {
79         throw new FrameworkException("ViewDescriptor for wizard '" + name
80             + "' not found!");
81     }
82     setViewDescriptor(viewDesc);
83     // registerViewDescriptorChildren(); Not a displayitem
84
}
85
86     private List JavaDoc sequence = new ArrayList JavaDoc();
87
88     /**
89      *
90      */

91     protected void initialize(ViewDescriptor desc) {
92
93     boolean firstBranch = false;
94
95     // Wizard level parameters...
96
setResourceBundle("" + desc.getParameter(RESOURCE_BUNDLE));
97     setTitle("" + desc.getParameter(WIZARD_TITLE));
98
99     // Page level parameters...
100
List JavaDoc pages = desc.getChildDescriptors();
101     Iterator JavaDoc it = pages.iterator();
102     while (it.hasNext()) {
103         WizardPage wizardPage = new WizardPage((ViewDescriptor) it.next());
104         addWizardPage(wizardPage);
105         //Create the first sequence of mainSteps not including sub steps
106
if (!wizardPage.isSubStep()) {
107         sequence.add(wizardPage);
108         }
109
110         if (wizardPage.isResultsPage()) {
111         showResultsPage = true;
112         }
113     }
114     }
115
116
117     /**
118      * We cannot cache the request context here b/c LH caches this object,
119      * making the request context invalid on subsequent requests.
120      */

121     public RequestContext getRequestContext() {
122     return RequestManager.getRequestContext();
123     }
124
125
126     /**
127      * This method sets the ViewDescriptor for this View. This method also
128      * initializes the Wizard from the ViewDescriptor information.
129      *
130      * @param desc The ViewDescriptor
131      */

132     protected void setViewDescriptor(ViewDescriptor desc) {
133     _viewDesc = desc;
134     initialize(desc);
135     }
136
137
138     /**
139      * This method retrieves this View ViewDescriptor.
140      *
141      * @return This View's ViewDescriptor.
142      */

143     public ViewDescriptor getViewDescriptor() {
144     return _viewDesc;
145     }
146
147
148     /**
149      *
150      */

151     protected void addWizardPage(WizardPage wizardPage) {
152     getWizardPages().add(wizardPage);
153     }
154
155
156     /**
157      *
158      */

159     protected void setWizardPages(List JavaDoc pages) {
160     _wizardPages = pages;
161     }
162
163
164     /**
165      *
166      */

167     public List JavaDoc getWizardPages() {
168     return _wizardPages;
169     }
170
171
172     /**
173      *
174      */

175     public WizardPage getWizardPage(String JavaDoc pageId) {
176     return getWizardPage(pageIdToPage(pageId));
177     }
178
179
180     /**
181      *
182      */

183     public WizardPage getWizardPage(int index) {
184     //return (WizardPage)getWizardPages().get(index);
185
return (WizardPage) sequence.get(index);
186     }
187
188
189
190     ////////////////////////////////////////////////////////////
191
// WizardInterface Methods //
192
////////////////////////////////////////////////////////////
193

194     /**
195      * Factory method.
196      */

197     public static WizardInterface create(RequestContext ctx) {
198     // FIXME: Hack b/c LH does not provide a way to get the WIZARD_NAME
199
// FIXME: Hack b/c LH hard-codes "WizardWindow."
200
String JavaDoc wizardName =
201         ctx.getRequest().getParameter(WIZARD_WINDOW_PARAMETER_NAME);
202
203     return new DescriptorWizardImpl(ctx, wizardName);
204     }
205
206
207     /**
208      * <p>Returns the name of this WizardInterface implementation.</p>
209      *
210      * <p>This method conflicts with View.getName()... however, I don't think
211      * it is very important, so I'm going to return super.getName().</p>
212      */

213     public String JavaDoc getName() {
214     return _wizName;
215     }
216
217
218     /**
219      * This sets the WizardName. NOTE: The wizard name should correspond to
220      * a displayItem entry in the view xml.
221      */

222     public void setName(String JavaDoc name) {
223     _wizName = name;
224     }
225
226
227     /**
228      * <p>Return the Model that the wizard framework should assign to the
229      * WizardPage instance for the given pageId.</p>
230      */

231     public Model getPageModel(String JavaDoc pageId) {
232     WizardPage page = getWizardPage(pageId);
233     return page.getModel();
234     }
235
236
237     /**
238      * <p>Return the Class name of the WizardPage instance to construct for
239      * this pageId.</p>
240      */

241     public Class JavaDoc getPageClass(String JavaDoc pageId) {
242     // I need this to know what ViewDescriptor to use.
243
getRequestContext().getRequest().setAttribute(
244         DescriptorCCWizardPage.VIEW_DESCRIPTOR_NAME,
245         getWizardPage(pageId).getName());
246
247     // All our pages are Descriptor pages
248
return DescriptorCCWizardPage.class;
249     }
250
251
252     /**
253      * Return the View name of the WizardPage instance for this pageId.
254      */

255     public String JavaDoc getPageName(String JavaDoc pageId) {
256     // FIXME: Provide logging API
257
//System.out.println("getPageName("+pageId+")");
258
return getWizardPage(pageId).getName();
259     }
260
261
262     /**
263      * The first page in the sequence of Wizard steps. This returned String
264      * is a internal Wizard identifier and will be used to identify other
265      * required Wizard information, such as a step's instructional text.
266      */

267     public String JavaDoc getFirstPageId() {
268     // FIXME: Provide logging API
269
//System.out.println("getFirstPageId(): "+pageToPageId(firstPage));
270
return pageToPageId(0);
271     }
272
273
274     /**
275      * The next page in the Wizard's defined sequence relative to pageId.
276      */

277     public String JavaDoc getNextPageId(String JavaDoc pageId) {
278     // FIXME: Provide logging API
279
//System.out.println("getNextPageId("+pageId+")");
280
if (isFinishPageId(pageId) && !showResultsPage) {
281         return null;
282     }
283     return pageToPageId(pageIdToPage(pageId) + 1);
284     }
285
286
287     /**
288      * The path to a resource properties file. The path should define String
289      * keys to support I18N translations. Strings such as a steps instructions
290      * are expected to be keys defined in this file.
291      */

292     public String JavaDoc getResourceBundle() {
293     // FIXME: Provide logging API
294
//System.out.println("getResourceBundle()");
295
return _resourceBundle;
296     }
297
298
299     /**
300      * Method to set the resource bundle.
301      */

302     public void setResourceBundle(String JavaDoc resBundle) {
303     _resourceBundle = resBundle;
304     }
305
306     /**
307      * The overall title for the wizard window.
308      */

309     public String JavaDoc getTitle() {
310     return _title;
311     }
312
313
314     /**
315      * Setter for the overall title for the wizard window.
316      */

317     public void setTitle(String JavaDoc title) {
318     _title = title;
319     }
320
321
322     /**
323      * <p>The title for this step. It appears above the page contect with the
324      * "Step N" label. For example:</p>
325      *
326      * <p><B>Step 1: Entering the User's Name</B></p>
327      */

328     public String JavaDoc getStepTitle(String JavaDoc pageId) {
329     return getWizardPage(pageId).getStepText();
330     }
331
332
333     /**
334      * The expected future page id's from the specified page id. If there are
335      * branches in the future sequence only those page id's up to the page id
336      * before the branch are returned. For example assuming currentPageId is
337      * 2, if the the future page id's are 3, 4, 5a, 5b, only page id's 3, and
338      * 4 would be returned.
339      */

340     public String JavaDoc[] getFuturePages(String JavaDoc currentPageId) {
341     // Add 1 to skip this page
342
if (isResultsPage(currentPageId)) {
343         return null;
344     }
345
346     int page = pageIdToPage(currentPageId) + 1;
347     int howMany = sequence.size() - page;
348     //String[] futurePages = new String[howMany];
349
/*List futurePages = new ArrayList();
350     for (int i = 0; i < howMany; ++i, ++page) {
351         // No conversion
352         if (((WizardPage)pages.get(page)).isSubStep())
353         break;
354         futurePages.add(i, pageToPageId(page));
355     }
356     return (String[])futurePages.toArray(new String[futurePages.size()]);*/

357
358     String JavaDoc [] futurePages = new String JavaDoc[howMany];
359     for (int cnt = 0; cnt < howMany; ++cnt, ++page) {
360         futurePages[cnt] = pageToPageId(page);
361     }
362     return futurePages;
363     }
364
365     /**
366      * The step instructions for the future pages in the same sequence as the
367      * page id's from getFuturePages.
368      */

369     public String JavaDoc[] getFutureSteps(String JavaDoc currentPageId) {
370     // Add 1 to skip this page
371
int page = pageIdToPage(currentPageId) + 1;
372     //List pages = getWizardPages();
373
int howMany = sequence.size() - page;
374     //List futureSteps = new ArrayList();
375
String JavaDoc[] futureSteps = new String JavaDoc[howMany];
376     for (int i = 0; i < howMany; ++i, ++page) {
377         /*if (((WizardPage)pages.get(page)).isSubStep())
378         break;
379         futureSteps.add(i, ((WizardPage)pages.get(page)).getStepText());*/

380         futureSteps[i] = ((WizardPage) sequence.get(page)).getStepText();
381     }
382     //return (String[])futureSteps.toArray(new String[futureSteps.size()]);
383
return futureSteps;
384     }
385
386
387     /**
388      * <p>The instructions that describe the step identified by pageId.</p>
389      */

390     public String JavaDoc getStepInstruction(String JavaDoc pageId) {
391     // FIXME: Provide logging API
392
//System.out.println("getStepInstructions("+pageId+")");
393
return getWizardPage(pageId).getStepInstructions();
394     }
395
396
397     /**
398      * The step summary for the step specified by pageId.
399      */

400     public String JavaDoc getStepText(String JavaDoc pageId) {
401     return getWizardPage(pageId).getStepText();
402     }
403
404
405     /**
406      * Help text for the step identified by pageId. Each array element will
407      * appear as an html para.
408      */

409     public String JavaDoc[] getStepHelp(String JavaDoc pageId) {
410     return getWizardPage(pageId).getStepHelp();
411     }
412
413
414     /**
415      * Returning true indicates that pageId identifies the last step in the
416      * sequence.
417      */

418     public boolean isFinishPageId(String JavaDoc pageId) {
419     //return (pageIdToPage(pageId) == (getWizardPages().size()-1));
420
//return pageId.equals(finishPageId);
421
int currentPage = pageIdToPage(pageId);
422     return ((WizardPage) sequence.get(currentPage)).isFinishPage();
423     }
424
425
426     /**
427      * This method returns false if step is reached such that the user cannot
428      * return to the previous step. If this message returns true the user will
429      * not be able to return to any visited steps. If the user can return to
430      * the previous step this method returns true.
431      */

432     public boolean hasPreviousPageId(String JavaDoc pageId) {
433     return !(getFirstPageId().equals(pageId));
434     }
435
436
437     /**
438      * This method returns a context sensitive message relative to the
439      * specified pageId. The String is usually a resource key. The returned
440      * String will be used as the message displayed in the cancel prompt.
441      */

442     public String JavaDoc getCancelPrompt(String JavaDoc pageId) {
443     return getWizardPage(pageId).getCancelPrompt();
444     }
445
446
447     /**
448      * A String that identifies the wizard.
449      */

450     public String JavaDoc toString() {
451     return this.getClass().getName() + "(" + getName() + ") with "
452         + getWizardPages().size() + " pages.";
453     }
454
455
456     /**
457      * This method is called when the framework has determined that the user
458      * is through using the wizard application. If the method returns true the
459      * framework will remove the wizard from its cache. It is up to wizard to
460      * ensure that no other applications are referencing this wizard at this
461      * time. (For statelss wizards)
462      */

463     public boolean done(String JavaDoc wizardName) {
464     /*RequestContext rc = getRequestContext();
465     WizardEvent event = new WizardEvent(rc, null, null, null, wizardName);
466     try {
467         return DescriptorViewHelper.endWizard(getViewDescriptor(), event);
468     } catch (Exception ex) {
469         throw new FrameworkError(ex, getViewDescriptor(), event.getView());
470     }*/

471     ViewDescriptor viewDesc = getViewDescriptor();
472     EventObject JavaDoc event = new EventObject JavaDoc(wizardName);
473     Object JavaDoc result = null;
474     try {
475         // Dispatch Begin Display Event Handlers (and mappings)
476
result = DescriptorViewHelper.dispatchEvent(getRequestContext(),
477             null, viewDesc,
478             viewDesc.getEventDescriptor(
479             EventDescriptor.TYPES.END_WIZARD),
480             event);
481     } catch (FrameworkException ex) {
482         // Change to an error
483
throw new FrameworkError(
484             ex,
485             ex.getResponsibleViewDescriptor(),
486             ex.getResponsibleView());
487     } catch (Exception JavaDoc ex) {
488         throw new FrameworkError(ex, viewDesc, (View) null);
489     }
490
491     boolean retVal = true;
492     if (result instanceof Boolean JavaDoc) {
493         retVal = ((Boolean JavaDoc) result).booleanValue();
494     }
495     return retVal;
496     }
497
498
499     /**
500      * <p>This method is called when the user clicks the next button. If true
501      * is returned the next page for the next step is displayed.</p>
502      *
503      * <p>If false is returned the framework will expect that a message has
504      * been set in in wizardEvent that will appear in a popup window. A
505      * severity must also be indicated. The severity can be informational
506      * requiring the user acknowledge and dismiss the popup window, a question
507      * indicating that the user can cancel or continue, and fatal where the
508      * user must acknowledge and dismiss the popup window and the wizard will
509      * quit.</p>
510      */

511     public boolean nextStep(WizardEvent wizardEvent) {
512     // FIXME: Provide logging API
513
//((DefaultModel)getPageModel(wizardEvent.getPageId())).
514
// dumpValues(System.out);
515
RequestContext rc = getRequestContext();
516     try {
517         boolean continueWizard = DescriptorViewHelper.nextWizardStep(
518         (DescriptorContainerView) wizardEvent.getView(), wizardEvent);
519         String JavaDoc pageId = wizardEvent.getPageId();
520         WizardPage wizPage = getWizardPage(pageId);
521         Model model = wizPage.getModel();
522
523         if (!continueWizard) {
524         //There is an error and the model should contain the error
525
String JavaDoc errorMessage = (String JavaDoc) model.getValue(ERROR_MESSAGE);
526         int severity = ((Integer JavaDoc) model.getValue(SEVERITY)).intValue();
527         wizardEvent.setErrorMessage(errorMessage);
528         wizardEvent.setSeverity(severity);
529         return false;
530         }
531
532         if (wizPage.isBranchStep()) {
533         /* The branchStep should define a boolean displayField that
534          * will cause the display of the sub steps*/

535
536         boolean showSteps = new Boolean JavaDoc(
537             (String JavaDoc) model.getValue(SHOW_STEPS)).booleanValue();
538         if (showSteps) {
539             // Recreate sequence to show the steps for this branch only
540
List JavaDoc pages = getWizardPages();
541             int currentPage = pageIdToPage(pageId);
542             sequence.subList(currentPage + 1, sequence.size()).clear();
543             int startIdx = currentPage + 1;
544             for (int i = startIdx; i < pages.size(); i++, startIdx++) {
545             WizardPage page = (WizardPage) pages.get(i);
546             if (page.isSubStep()) {
547                 sequence.add(page);
548             } else {
549                 break;
550             }
551             }
552             for (int i = startIdx; i < pages.size(); i++) {
553             WizardPage page = (WizardPage) pages.get(i);
554             if (!page.isSubStep()) {
555                 sequence.add(page);
556             }
557             }
558         } else {
559             //need to clear the substeps if they have been added
560
//only immediate substeps will be removed
561
int startIdx = pageIdToPage(pageId) + 1;
562             List JavaDoc removes = new ArrayList JavaDoc();
563             for (int i = startIdx; i < sequence.size(); i++) {
564             WizardPage page = (WizardPage) sequence.get(i);
565             if (page.isSubStep()) {
566                 removes.add(page);
567             } else {
568                 break;
569             }
570             }
571             sequence.removeAll(removes);
572         }
573         }
574         return continueWizard;
575     } catch (Exception JavaDoc ex) {
576         throw new FrameworkError(
577             ex,
578             getViewDescriptor(),
579             wizardEvent.getView());
580     }
581     }
582
583
584     /**
585      * <p>This method is called when the user clicks the previos button. If
586      * true is returned the previous page for the next step is displayed.</p>
587      *
588      * <p>If false is returned the framework will expect that a message has
589      * been set in in wizardEvent that will appear in a popup window. A
590      * severity must also be indicated. The severity can be informational
591      * requiring the user acknowledge and dismiss the popup window, a question
592      * indicating that the user can cancel or continue, and fatal where the
593      * user must acknowledge and dismiss the popup window and the wizard will
594      * quit.</p>
595      */

596     public boolean previousStep(WizardEvent wizardEvent) {
597     // FIXME: Provide logging API
598
//((DefaultModel)getPageModel(wizardEvent.getPageId())).
599
// dumpValues(System.out);
600
RequestContext rc = getRequestContext();
601     try {
602         return DescriptorViewHelper.prevWizardStep(
603             (DescriptorContainerView) wizardEvent.getView(),
604             wizardEvent);
605     } catch (Exception JavaDoc ex) {
606         throw new FrameworkError(
607             ex,
608             getViewDescriptor(),
609             wizardEvent.getView());
610     }
611     }
612
613
614     /**
615      * <p>This method is called when the user clicks a link to a previously
616      * seen page. If true is returned the wizard will proceed to the linked
617      * location.</p>
618      *
619      * <p>If false is returned the framework will expect that a message has
620      * been set in in wizardEvent that will appear in a popup window. A
621      * severity must also be indicated. The severity can be informational
622      * requiring the user acknowledge and dismiss the popup window, a question
623      * indicating that the user can cancel or continue, and fatal where the
624      * user must acknowledge and dismiss the popup window and the wizard will
625      * quit.</p>
626      *
627      * <p>The window event will include the target page id.</P.
628      */

629     public boolean gotoStep(WizardEvent wizardEvent) {
630     RequestContext rc = getRequestContext();
631     try {
632         return DescriptorViewHelper.goToWizardStep(
633             (DescriptorContainerView) wizardEvent.getView(),
634             wizardEvent);
635     } catch (Exception JavaDoc ex) {
636         throw new FrameworkError(
637             ex,
638             getViewDescriptor(),
639             wizardEvent.getView());
640     }
641     }
642
643
644     /**
645      * <p>This method is called when the user clicks the finish button. The
646      * return value from the the wizard is ignored and on return the wizard
647      * framework will dismiss the remaining window.</p>
648      *
649      * <p>The framework assumes that the wizard application will never allow
650      * the finish step to occur if it is not ready to end interacting with the
651      * user.</p>
652      *
653      * <p>The framework will call the getFinishPrompt method before a page is
654      * displayed. The wizard must return a context sensitive message relative
655      * to the specified page. The message will be used as the finish prompt
656      * message. A finish prompt is always a WizardEvent.ACKNOWLEDGE
657      * severity.</p>
658      */

659     public boolean finishStep(WizardEvent wizardEvent) {
660     RequestContext rc = getRequestContext();
661     try {
662         boolean result = DescriptorViewHelper.finishWizardStep(
663         (DescriptorContainerView) wizardEvent.getView(), wizardEvent);
664         if (!result) {
665         stopWizardFromClosing(wizardEvent.getView().getParent());
666         }
667         return result;
668     } catch (Throwable JavaDoc ex) {
669         stopWizardFromClosing(wizardEvent.getView().getParent());
670         throw new FrameworkError(
671             ex,
672             getViewDescriptor(),
673             wizardEvent.getView());
674     }
675     }
676
677
678     /**
679      * Hack to fix LH bug. This method sets the CCWizard.isFinishRequest to
680      * false. It uses reflection to do this in order to access this private
681      * variable.
682      */

683     private void stopWizardFromClosing(View view) {
684     if (!(view instanceof com.sun.web.ui.view.wizard.CCWizard)) {
685         return;
686     } try {
687         Field JavaDoc [] fields = view.getClass().getDeclaredFields();
688         int idx;
689         for (idx = 0; idx < fields.length; idx++) {
690         if (fields[idx].getName().equals("isFinishRequest")) {
691             break;
692         }
693         }
694         fields[idx].setAccessible(true);
695         fields[idx].setBoolean(view, false);
696     } catch (Exception JavaDoc ex) {
697         // Ignore
698
}
699     }
700
701
702     /**
703      * <p>This method is called when the user clicks the cancel button. The
704      * return value from the the wizard is ignored and on return the wizard
705      * framework will dismiss the remaining window.</p>
706      *
707      * <p>The framework will call the getCancelPrompt method before a page is
708      * displayed. The wizard must return a context sensitive message relative
709      * to the specified page. The message will be used as the cancel prompt
710      * message. A cacel prompt is always a WizardEvent.QUERY severity.</p>
711      */

712     public boolean cancelStep(WizardEvent wizardEvent) {
713     RequestContext rc = getRequestContext();
714     try {
715         return DescriptorViewHelper.cancelWizardStep(
716             (DescriptorContainerView) wizardEvent.getView(),
717             wizardEvent);
718     } catch (Exception JavaDoc ex) {
719         throw new FrameworkError(
720             ex,
721             getViewDescriptor(),
722             wizardEvent.getView());
723     }
724     }
725
726
727     /**
728      * Return true to warn the user once when revisiting a
729      * previous page as follows.
730      *<p>
731      * In wizards, if you change entries on pages that you<br>
732      * have already visited, you will likely lose information<br>
733      * that you entered on later pages.
734      *<p>
735      * Return false to never warn the user.
736      * If your wizard implementation does not have dependecies
737      * as inferred by the warning, return false.
738      * <p>
739      * This method is called once after creating the WizardInterface
740      * instance.
741      */

742     public boolean warnOnRevisitStep() {
743     return false;
744     }
745
746
747     /**
748      *
749      */

750     private String JavaDoc pageToPageId(int page) {
751     return Integer.toString(page + 1);
752     }
753
754
755     /**
756      *
757      */

758     private int pageIdToPage(String JavaDoc pageId) {
759     return Integer.parseInt(pageId) - 1;
760     }
761
762     public boolean canBeStepLink(String JavaDoc pageId) {
763     return true;
764     }
765
766     public void closeStep(WizardEvent wizardEvent) {
767     }
768
769     public String JavaDoc getPlaceholderText(String JavaDoc pageId) {
770     /*if (showResultsPage) {
771         return null;
772     }
773     return "PlaceHolderText";*/

774     if (isResultsPage(pageId)) {
775         return null;
776     }
777     return getWizardPage(pageId).getPlaceHolderText();
778     }
779
780     public String JavaDoc getResultsPageId(String JavaDoc pageId) {
781     if (showResultsPage) {
782         return (new Integer JavaDoc(sequence.size())).toString();
783     }
784     return null;
785     }
786
787     public boolean helpTab(WizardEvent wizardEvent) {
788     return true;
789     }
790
791     public boolean isSubstep(String JavaDoc pageId) {
792     //TODO Check if this is a substep
793
if (isResultsPage(pageId)) {
794         return false;
795     }
796     return getWizardPage(pageId).isSubStep();
797     }
798
799     public boolean stepTab(WizardEvent wizardEvent) {
800     return true;
801     }
802
803     ///////////////////////////////////////////////////////////
804

805     protected boolean isResultsPage(String JavaDoc pageId) {
806     return ((WizardPage) sequence.get(
807             pageIdToPage(pageId))).isResultsPage();
808     }
809     /**
810      * Inner class to hold WizardPage information.
811      */

812     protected class WizardPage implements java.io.Serializable JavaDoc {
813     public WizardPage(ViewDescriptor viewDesc) {
814         initialize(viewDesc);
815     }
816
817     protected void initialize(ViewDescriptor viewDesc) {
818         setName(viewDesc.getName());
819         setStepText("" + viewDesc.getParameter(STEP_TEXT));
820         setStepInstructions("" + viewDesc.getParameter(STEP_INSTRUCTIONS));
821         setCancelPrompt("" + viewDesc.getParameter(CANCEL_PROMPT));
822         setPageModelName((String JavaDoc) viewDesc.getParameter(PAGE_MODEL_NAME));
823         setPageModelClass((String JavaDoc) viewDesc.getParameter(PAGE_MODEL_CLASS));
824
825         // Step help needs to be an array of String
826
List JavaDoc stepHelp = (List JavaDoc) viewDesc.getParameter(STEP_HELP);
827         if (stepHelp != null) {
828         setStepHelp((String JavaDoc []) stepHelp.toArray(
829                 new String JavaDoc[stepHelp.size()]));
830         }
831
832         String JavaDoc resultsPage = (String JavaDoc) viewDesc.getParameter(RESULTS_PAGE);
833         if ((resultsPage != null) && resultsPage.equalsIgnoreCase("true")) {
834         _resultsPage = true;
835         }
836
837         String JavaDoc finishPage = (String JavaDoc) viewDesc.getParameter(FINISH_PAGE);
838         if ((finishPage != null) && finishPage.equalsIgnoreCase("true")) {
839         _finishPage = true;
840         }
841
842         String JavaDoc branchStep = (String JavaDoc) viewDesc.getParameter(BRANCH_STEP);
843         if ((branchStep != null) && branchStep.equalsIgnoreCase("true")) {
844         _branchStep = true;
845         String JavaDoc placeHolderText =
846             (String JavaDoc) viewDesc.getParameter(PLACE_HOLDER_TEXT);
847         setPlaceHolderText(placeHolderText);
848         }
849
850         String JavaDoc subStep = (String JavaDoc) viewDesc.getParameter(SUB_STEP);
851         if ((subStep != null) && subStep.equalsIgnoreCase("true")) {
852         if (_branchStep) {
853             throw new FrameworkException(
854                 viewDesc.getName()
855                 + " cannot be a branchStep as well as a subStep");
856         }
857         _subStep = true;
858         }
859     }
860
861
862     /**
863      * @param name The wizard page name
864      */

865     public void setName(String JavaDoc name) {
866         _name = name;
867     }
868
869
870     /**
871      * @return The wizard page name
872      */

873     public String JavaDoc getName() {
874         return _name;
875     }
876
877
878     /**
879      * @param stepText The wizard page step text
880      */

881     public void setStepText(String JavaDoc stepText) {
882         _stepText = stepText;
883     }
884
885
886     /**
887      * @return The wizard page step text
888      */

889     public String JavaDoc getStepText() {
890         return _stepText;
891     }
892
893
894     /**
895      * @param stepInstructions The wizard page step instructions
896      */

897     public void setStepInstructions(String JavaDoc stepInstructions) {
898         _stepInstructions = stepInstructions;
899     }
900
901
902     /**
903      * @return The wizard page step instructions
904      */

905     public String JavaDoc getStepInstructions() {
906         return _stepInstructions;
907     }
908
909
910     /**
911      * @param stepHelp The wizard page step help
912      */

913     public void setStepHelp(String JavaDoc [] stepHelp) {
914         _stepHelp = stepHelp;
915     }
916
917
918     /**
919      * @return The wizard page step help
920      */

921     public String JavaDoc[] getStepHelp() {
922         return _stepHelp;
923     }
924
925
926     /**
927      * @param cancelPrompt The wizard page cancel prompt
928      */

929     public void setCancelPrompt(String JavaDoc cancelPrompt) {
930         _cancelPrompt = cancelPrompt;
931     }
932
933
934     /**
935      * @return The wizard page cancel prompt
936      */

937     public String JavaDoc getCancelPrompt() {
938         return _cancelPrompt;
939     }
940
941
942     /**
943      * @param modelName The wizard page model name used for the
944      * ModelManager calls. Defaults to
945      * DescriptorCCWizardPage.WIZARD_MODEL
946      */

947     public void setPageModelName(String JavaDoc modelName) {
948         if (modelName == null) {
949         return;
950         }
951         _modelName = modelName;
952     }
953
954
955     /**
956      * @return The page model name.
957      */

958     public String JavaDoc getPageModelName() {
959         return _modelName;
960     }
961
962
963     /**
964      * @param modelClass The wizard page model class name to use during
965      * ModelManager calls. Defaults to
966      * com.iplanet.jato.model.DefaultModel.
967      */

968     public void setPageModelClass(String JavaDoc modelClass) {
969         if (modelClass == null) {
970         return;
971         }
972         _modelClass = modelClass;
973     }
974
975
976     /**
977      * @return The page model class.
978      */

979     public String JavaDoc getPageModelClass() {
980         return _modelClass;
981     }
982
983
984     /**
985      * @return The page model
986      */

987     public Model getModel() {
988         try {
989         // FIXME: Provide logging API
990
// System.out.println("getPageModel("+getName()+") = ");
991
return getRequestContext().getModelManager().getModel(
992             getPageModelClass(), getPageModelName(), true, true);
993         } catch (ClassNotFoundException JavaDoc ex) {
994         throw new FrameworkException(
995             "Unable to get to model for wizard '" + this.getName()
996             + "', page '" + getName() + "'.",
997             ex, null, null);
998         }
999     }
1000
1001    /**
1002     * returns true is this is a results page
1003     */

1004    public boolean isResultsPage() {
1005        return _resultsPage;
1006    }
1007
1008    public boolean isFinishPage() {
1009        return _finishPage;
1010    }
1011
1012    public void setPlaceHolderText(String JavaDoc text) {
1013        if ((text == null) || (text.length() == 0)) {
1014        _placeHolderText = "Steps determined by choices";
1015        } else {
1016        _placeHolderText = text;
1017        }
1018    }
1019
1020    public String JavaDoc getPlaceHolderText() {
1021        return _placeHolderText;
1022    }
1023
1024    public boolean isSubStep() {
1025        return _subStep;
1026    }
1027
1028    public boolean isBranchStep() {
1029        return _branchStep;
1030    }
1031
1032    public String JavaDoc toString() {
1033        return _name;
1034    }
1035    /**
1036     * This value is set automatically.
1037     */

1038    public static final String JavaDoc PAGE_NAME = "pageName";
1039
1040    /**
1041     * ViewDescriptor Parameter name ("cancelPrompt")
1042     */

1043    public static final String JavaDoc CANCEL_PROMPT = "cancelPrompt";
1044
1045    /**
1046     * ViewDescriptor Parameter name ("stepHelp"). Note: this parameter
1047     * should be an array of String.
1048     */

1049    public static final String JavaDoc STEP_HELP = "stepHelp";
1050
1051    /**
1052     * ViewDescriptor Parameter name ("stepInstructions")
1053     */

1054    public static final String JavaDoc STEP_INSTRUCTIONS = "stepInstructions";
1055
1056    /**
1057     * ViewDescriptor Parameter name ("stepText")
1058     */

1059    public static final String JavaDoc STEP_TEXT = "stepText";
1060
1061    /**
1062     * ViewDescriptor Parameter name ("wizardPageModelClass")
1063     */

1064    public static final String JavaDoc PAGE_MODEL_CLASS = "wizardPageModelClass";
1065
1066    /**
1067     * ViewDescriptor Parameter name ("wizardPageModelName")
1068     */

1069    public static final String JavaDoc PAGE_MODEL_NAME = "wizardPageModelName";
1070
1071    /**
1072     * ViewDescriptor parameter name "resultsPage"
1073     */

1074    public static final String JavaDoc RESULTS_PAGE = "resultsPage";
1075
1076    /**
1077     * ViewDescriptor parameter name "finishPage"
1078     * If this is true the this is the finishPage
1079     */

1080    public static final String JavaDoc FINISH_PAGE = "finishPage";
1081    public static final String JavaDoc BRANCH_STEP = "branchStep";
1082    public static final String JavaDoc SUB_STEP = "subStep";
1083    public static final String JavaDoc PLACE_HOLDER_TEXT = "placeHolderText";
1084
1085    private String JavaDoc _cancelPrompt = "";
1086    private String JavaDoc _name = "";
1087    private String JavaDoc [] _stepHelp = {""};
1088    private String JavaDoc _stepInstructions = "";
1089    private String JavaDoc _stepText = "";
1090    private String JavaDoc _modelClass = "com.iplanet.jato.model.DefaultModel";
1091    private String JavaDoc _modelName = DescriptorCCWizardPage.WIZARD_MODEL;
1092    private boolean _resultsPage = false;
1093    private boolean _finishPage = false;
1094    private boolean _subStep = false;
1095    private String JavaDoc _placeHolderText = null;
1096    private boolean _branchStep = false;
1097    }
1098
1099
1100    /**
1101     * This defines the parameter name for the resource bundle that should be
1102     * set on the ViewDescriptor for this WizardImpl. "resourceBundle"
1103     */

1104    public static final String JavaDoc RESOURCE_BUNDLE = "resourceBundle";
1105
1106    /**
1107     * This defines the parameter name for the wizard title that should be
1108     * set on the ViewDescriptor for this WizardImpl. "title"
1109     */

1110    public static final String JavaDoc WIZARD_TITLE = "title";
1111
1112
1113    /**
1114     *
1115     */

1116    public static final String JavaDoc WIZARD_WINDOW_PARAMETER_NAME =
1117    "WizardWindow." + CCWizardWindowModelInterface.WIZARD_NAME;
1118
1119    private ViewDescriptor _viewDesc = null;
1120    private String JavaDoc _wizName = null;
1121    private List JavaDoc _wizardPages = new ArrayList JavaDoc();
1122    private boolean showResultsPage = false;
1123
1124    private String JavaDoc _resourceBundle = "test.Resources";
1125    private String JavaDoc _title = "WizardWindow";
1126
1127    public static final String JavaDoc ERROR_MESSAGE = "errorMessage";
1128    public static final String JavaDoc SEVERITY = "severity";
1129    public static final String JavaDoc SHOW_STEPS = "showSteps";
1130}
1131
Popular Tags