Skip to content
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

Open
wants to merge 10 commits into
base: vaadin7
Choose a base branch
from

Conversation

javydreamercsw
Copy link

  1. Fixed some Maven warnings.
  2. Shared common versions with parent pom.
  3. Limit the amount of steps displayed on top bar (default -1 which means show all which is the current behavior).
  4. Add getter/setter method for this new parameter.

@javydreamercsw
Copy link
Author

This is related to issue #27.

@@ -54,10 +54,16 @@ private void updateProgressBar() {
private void updateStepCaptions() {

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++;
            }
        }

    }

}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me!

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();
}

Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants