|Wizard: Manipulating the flow [message #931503]
||Wed, 03 October 2012 05:11
| Patrick Bänziger
Registered: September 2011
Because I have to re-read the implementation every time I do it and the wiki is still sparse in the wizard area, I'd like to ask to ask you the following:
If I wish to implement a wizard that can do loops, branch or simply have a non-standard flow of steps, where is the right place for such customizations?
- If I wish to have a loop: How (and when/where) do I tell to the last step to return to the first loop step? (Assuming the default would be to end the loop)
- If I wish to have a branch and want to go back to the branch point and choose the other branch direction, do I have to reset the wizard in any way? (Apart from possible effects on the data that is being processed by the wizard.)
- If I wish to jump to an arbitrary step Y, after finishing step X, where is the proper place to implement that? In the step, wizard, ...?
Is there a proper way to do this?
Kind regards, Patrick
|Re: Wizard: Manipulating the flow [message #938357 is a reply to message #931503]
||Tue, 09 October 2012 16:06
| Beat Schwarzentrub
Registered: November 2010
Scout's IWizard/AbstractWizard is a client-only wizard implementation that is kept very simple. Basically it provides a way to sequentially step through a bunch of forms. There is very little logic included out-of-the-box, so there are no default "loop" or "branch" functions.
It's not too hard to create the desired behaviour by yourself, though. (If you check out the code of AbstractWizard, you can see that it's not that complicated.) The wizard holds a list of "steps" that you may freely manipulate, i.e. add, remove or reorder steps. One of those steps is the "active step". The default "execNext" implementation just gets the next step from the step list and sets it as the new active step. But of course, you may change that behaviour by adding or removing steps or activating a step that is "out of the usual order". Steps do not necessarily have to be contained in the set of "available steps", you may introduce new instances at runtime.
If I wish to have a loop: How (and when/where) do I tell to the last step to return to the first loop step? (Assuming the default would be to end the loop)
If your wizard is very specific and is not reused for other purposes, you may code such a logic directly in the wizard. Override the "execNext" method and dynamically add a copy of the first step. For the user this looks like he got "back" to the beginning of the loop, but actually he just got a second time on the same step. The step list would look like this (A = current or past step, b = future step) during the execution of the wizard:
On line 3, steps C and D are inserted dynamically because of some condition of step B. In step 6 this condition does not hold, so step E is finally activated.
For a more generic approach you could create your own abstract subclasses of AbstractWizard and AbstractWizardStep that support the programmer in creating loops and the like.
If I wish to have a branch and want to go back to the branch point and choose the other branch direction, do I have to reset the wizard in any way? (Apart from possible effects on the data that is being processed by the wizard.)
Just update your step list accordingly, i.e. remove the steps that should be discarded.
If I wish to jump to an arbitrary step Y, after finishing step X, where is the proper place to implement that? In the step, wizard, ...?
This depends on your needs and implementation. Both the wizard and the steps (for example in the execDeactivate() method) may alter the wizard state.
Powered by FUDForum
. Page generated in 0.02583 seconds