-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix titles for many steps #28
base: vaadin7
Are you sure you want to change the base?
Fix titles for many steps #28
Conversation
javydreamercsw
commented
Apr 10, 2017
- Fixed some Maven warnings.
- Shared common versions with parent pom.
- Limit the amount of steps displayed on top bar (default -1 which means show all which is the current behavior).
- Add getter/setter method for this new parameter.
This is related to issue #27. |
@@ -54,10 +54,16 @@ private void updateProgressBar() { | |||
private void updateStepCaptions() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I merged your functionality in my project but prefered more sofisticated algorithm for choosing the titles to display:
// Rules when advancing: keep right pages after this one as much as possible
// This way, user will see in priority the next pages he is going to navigate
// in this direction (advancing)
// Rules when navigating back: keep left pages as much as possible
// This way, user will see in priority the next pages he is going to navigate
// in this direction (going back)
private void updateStepCaptions()
{
stepCaptions.removeAllComponents();
boolean advancing = (activeStepIndex > activeStepIndexPrevious);
int nbDisplayed=0;
if( advancing )
{
// Rules when advancing: keep right pages after this one as much as possible
// This way, user will see in priority the next pages he is going to navigate
// in this direction (advancing)
int index = 0;
for(WizardStep step : wizard.getSteps())
{
if( index++<activeStepIndex ) continue; // loop until current page
if
(
// No need to test further if there's no limitation
maxStepsDisplayed < 0
||
nbDisplayed<maxStepsDisplayed
)
{
Label label = createCaptionLabel(index, step);
stepCaptions.addComponent(label);
nbDisplayed++;
}
}
// Let's see if we can add pages to the left
for
(
index = activeStepIndex;
index>=0;
index--
)
{
if( index==activeStepIndex ) continue; // current page was done already
if
(
// No need to test further if there's no limitation
maxStepsDisplayed < 0
||
nbDisplayed<maxStepsDisplayed
)
{
WizardStep step=null;
for(WizardStep s : wizard.getSteps())
if(wizard.getSteps().indexOf(s)==index) step=s;
Label label = createCaptionLabel(index+1, step);
// we loop in reverse order... so add on top (e.g. to the left)
stepCaptions.addComponentAsFirst(label);
nbDisplayed++;
}
}
}
else
{
// Rules when navigating back: keep left pages as much as possible
// This way, user will see in priority the next pages he is going to navigate
// in this direction (going back)
int index = 0;
// We first add pages to the left
for
(
index = activeStepIndex;
index>=0;
index--
)
{
if
(
// No need to test further if there's no limitation
maxStepsDisplayed < 0
||
nbDisplayed<maxStepsDisplayed
)
{
WizardStep step=null;
for(WizardStep s : wizard.getSteps())
if(wizard.getSteps().indexOf(s)==index) step=s;
Label label = createCaptionLabel(index+1, step);
// we loop in reverse order... so add on top (e.g. to the left)
stepCaptions.addComponentAsFirst(label);
nbDisplayed++;
}
}
// now let see if we still have room for right pages
index = 0;
for(WizardStep step : wizard.getSteps())
{
if( index++<(activeStepIndex+1) ) continue; // loop until current page + 1 (because it's already done)
if
(
// No need to test further if there's no limitation
maxStepsDisplayed < 0
||
nbDisplayed<maxStepsDisplayed
)
{
Label label = createCaptionLabel(index, step);
stepCaptions.addComponent(label);
nbDisplayed++;
}
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If to be implemented... forgot to mention it requires remembering last navigation step.
WizardProgressBar class must have activeStepIndexPrevious member
private int activeStepIndexPrevious = -1;
private int activeStepIndex = -1;
And backup previous events in it inside activeStepChanged Override
@Override
public void activeStepChanged(WizardStepActivationEvent event)
{
List<WizardStep> allSteps = wizard.getSteps();
activeStepIndexPrevious = activeStepIndex;
activeStepIndex = allSteps.indexOf(event.getActivatedStep());
updateProgressAndCaptions();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it change the API in any way or should it be a drop in replacement?