Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Wizard and getNextPage
Wizard and getNextPage [message #336199] Thu, 28 May 2009 17:35 Go to next message
Andy is currently offline AndyFriend
Messages: 47
Registered: July 2009
Member
I am trying to get a Wizard working but dealing with getNextPage is
proving to be a pain. In my Wizard class I have the following:

public IWizardPage getNextPage(IWizardPage page){
System.out.println("This is the current page: " + page.getName());
if(page instanceof FirstPage){
return secondPage;
}


if(page instanceof SecondPage){
return thirdPage;
}

return page;
} // public IWizardPage

In the example above, if I start the wizard everything works fine. The
output is

This is the current page: My First Page

Great.

Here is the problem. If I press next on the wizard, the output of this
then becomes:

This is the current page: My First Page
This is the current page: My Second Page

So my question is why is getNextPage being called twice? If someone
clicks on "Next >" it should only be called once, or at least that is what
would make logical sense to me. Am I doing something wrong? How can I
assure that when someone presses next I only get a single call to
getNextPage? Thanks,

Andy
Re: Wizard and getNextPage [message #336200 is a reply to message #336199] Thu, 28 May 2009 17:55 Go to previous messageGo to next message
Dann Martens is currently offline Dann MartensFriend
Messages: 65
Registered: July 2009
Member
Hi Andy,

I'm surprised you are working with the API at that level. Aren't you
supposed to simply add the pages and that's it? Sure, then there are the
callback methods to disable the next/finish buttons, but other that that...

If I'm not mistaken, strategically overriding methods here and there is
all that is needed to have everything working as expected.

I do admit, I did my fair share of puzzling to find out what to touch
and what not.

Take a look here:
http://www.eclipse.org/articles/article.php?file=Article-JFa ceWizards/index.html

Best,
Dann

Andy wrote:
> I am trying to get a Wizard working but dealing with getNextPage is
> proving to be a pain. In my Wizard class I have the following:
>
> public IWizardPage getNextPage(IWizardPage page){
> System.out.println("This is the current page: " + page.getName());
> if(page instanceof FirstPage){
> return secondPage;
> }
>
>
> if(page instanceof SecondPage){
> return thirdPage;
> }
>
> return page;
> } // public IWizardPage
>
> In the example above, if I start the wizard everything works fine. The
> output is
>
> This is the current page: My First Page
>
> Great.
>
> Here is the problem. If I press next on the wizard, the output of this
> then becomes:
>
> This is the current page: My First Page
> This is the current page: My Second Page
>
> So my question is why is getNextPage being called twice? If someone
> clicks on "Next >" it should only be called once, or at least that is
> what would make logical sense to me. Am I doing something wrong? How
> can I assure that when someone presses next I only get a single call to
> getNextPage? Thanks,
>
> Andy
>
>
Re: Wizard and getNextPage [message #336201 is a reply to message #336200] Thu, 28 May 2009 19:24 Go to previous messageGo to next message
Andy is currently offline AndyFriend
Messages: 47
Registered: July 2009
Member
I guess I don't understand why you would be surprised. I am simply trying
to process the information on one page and then display a different page
in the wizard depending on the input. Pretty basic wizard functionality,
yet it doesn't apparently work in how I am using the Wizard apparently.

I looked at that example and I tried to do what that example did in terms
of changing the order of pages. It didn't work. Perhaps a bug was
introduced in a later version of Eclipse?

As an example, I put several pages in the addPages() method of the Wizard.
Everything worked fine. Back button, forward button, finish, cancel, you
name it. Since that doesn't solve the problem (because it doesn't allow
me to branch the flow of the wizard), I needed to intercept the Next >
press.

Then the only change I put in was in the first page of the wizard. I
merely overrode the getNextPage method as so (to have it skip to the 3rd
page instead of the second):

public IWizardPage getNextPage(){
IWizardPage nextPage = new ThirdPage("Third Page");
System.out.println("In the page getNextPage. Current page is: " +
this.getName() + " and going to: " + nextPage.getName());
return nextPage;
}

On loading the wizard the first page is displayed correctly and

In the page getNextPage. Current page is: First Page and going to: Third
Page

is shown in the console. Not sure why getNextPage is getting called on
the first page when nothing was pressed.

Anyway, I press Next. No page is changed but I see

In the page getNextPage. Current page is: First Page and going to: Third
Page

in the console again. Why?

So I press Next again. Finally the correct third page is displayed but
the following is shown in the console (for a third time)

In the page getNextPage. Current page is: First Page and going to: Third
Page

And none of the buttons work anymore, not Next, not Back, not Finish, not
cancel requiring a Task Manager kill process type shutdown.

Is there any working example of a simple branching of a wizard? This
would be extremely simple in JSP and very frustrating unfortunately as it
should be working, or so I would think.

Thanks in advance.

Andy


Dann Martens wrote:

> Hi Andy,

> I'm surprised you are working with the API at that level. Aren't you
> supposed to simply add the pages and that's it? Sure, then there are the
> callback methods to disable the next/finish buttons, but other that that...

> If I'm not mistaken, strategically overriding methods here and there is
> all that is needed to have everything working as expected.

> I do admit, I did my fair share of puzzling to find out what to touch
> and what not.

> Take a look here:
>
http://www.eclipse.org/articles/article.php?file=Article-JFa ceWizards/index.html

> Best,
> Dann

> Andy wrote:
>> I am trying to get a Wizard working but dealing with getNextPage is
>> proving to be a pain. In my Wizard class I have the following:
>>
>> public IWizardPage getNextPage(IWizardPage page){
>> System.out.println("This is the current page: " + page.getName());
>> if(page instanceof FirstPage){
>> return secondPage;
>> }
>>
>>
>> if(page instanceof SecondPage){
>> return thirdPage;
>> }
>>
>> return page;
>> } // public IWizardPage
>>
>> In the example above, if I start the wizard everything works fine. The
>> output is
>>
>> This is the current page: My First Page
>>
>> Great.
>>
>> Here is the problem. If I press next on the wizard, the output of this
>> then becomes:
>>
>> This is the current page: My First Page
>> This is the current page: My Second Page
>>
>> So my question is why is getNextPage being called twice? If someone
>> clicks on "Next >" it should only be called once, or at least that is
>> what would make logical sense to me. Am I doing something wrong? How
>> can I assure that when someone presses next I only get a single call to
>> getNextPage? Thanks,
>>
>> Andy
>>
>>
Re: Wizard and getNextPage [message #336204 is a reply to message #336201] Fri, 29 May 2009 05:44 Go to previous messageGo to next message
Dann Martens is currently offline Dann MartensFriend
Messages: 65
Registered: July 2009
Member
Hi Andy,

As you see from this example method, the pages are instantiated, here.

public void addPages() {
holidayPage = new HolidayMainPage(workbench, selection);
addPage(holidayPage);
planePage = new PlanePage("");
addPage(planePage);
carPage = new CarPage("");
addPage(carPage);
}

Yet, in your code, you're also instantiating pages, again. That can't be
right. Each page references native resources and should be disposed. If
you don't dispose, you'll have resource leaks. You're introducing a new
page out of the blue, without 'adding' that page to the Wizard. In the
implementation of 'addPage', you can see 'page.setWizard(this);' - your
new page hasn't even had its parent Wizard set,

This is the source code of getNextPage of the Wizard class:

/*
* (non-Javadoc) Method declared on IWizard. The default behavior is to
* return the page that was added to this wizard after the given page.
*/
public IWizardPage getNextPage(IWizardPage page) {
int index = pages.indexOf(page);
if (index == pages.size() - 1 || index == -1) {
// last page or page not found
return null;
}
return (IWizardPage) pages.get(index + 1);
}

Try to modify the code properly, by determining the proper index based
on your flow conditions.

Best regards,
Dann
Re: Wizard and getNextPage [message #336209 is a reply to message #336204] Fri, 29 May 2009 13:53 Go to previous messageGo to next message
Andy is currently offline AndyFriend
Messages: 47
Registered: July 2009
Member
Thanks for the help. I did change the wizard around so that I was getting
the page out of the wizard class and not instantiating a new one. That
seemed to solve the weird indexing error and I was able to move through
the wizard as normal.

The part that I don't get is why I am still getting a doubling of the
getNextPage method. It seems that when you first start the wizard
getNextPage is called on the displayed page. Then it is called again when
you press the Next button. That just seems very odd to me as getNextPage
is called twice per page, once when the page is loaded and again when the
wizard is leaving the page.

I am guessing it was implemented this way on the load of one of the pages
to see if there was a next page in the wizard and use that answer as to
whether the next button should be greyed out or not so that the wizard
would know it was at the end of the wizard pages when it loaded the next
page. It just seems that if this was indeed the reason it traded that for
the hassle of dealing with a double call on every page.

Is there any way to have a method called just once per page, like a do
Next or doPrevious? Or a way to trap when the page is being loaded as
opposed to when the page is being left to go to another page? Thanks,

Andy


Dann Martens wrote:

> Hi Andy,

> As you see from this example method, the pages are instantiated, here.

> public void addPages() {
> holidayPage = new HolidayMainPage(workbench, selection);
> addPage(holidayPage);
> planePage = new PlanePage("");
> addPage(planePage);
> carPage = new CarPage("");
> addPage(carPage);
> }

> Yet, in your code, you're also instantiating pages, again. That can't be
> right. Each page references native resources and should be disposed. If
> you don't dispose, you'll have resource leaks. You're introducing a new
> page out of the blue, without 'adding' that page to the Wizard. In the
> implementation of 'addPage', you can see 'page.setWizard(this);' - your
> new page hasn't even had its parent Wizard set,

> This is the source code of getNextPage of the Wizard class:

> /*
> * (non-Javadoc) Method declared on IWizard. The default behavior is to
> * return the page that was added to this wizard after the given page.
> */
> public IWizardPage getNextPage(IWizardPage page) {
> int index = pages.indexOf(page);
> if (index == pages.size() - 1 || index == -1) {
> // last page or page not found
> return null;
> }
> return (IWizardPage) pages.get(index + 1);
> }

> Try to modify the code properly, by determining the proper index based
> on your flow conditions.

> Best regards,
> Dann
Re: Wizard and getNextPage [message #336217 is a reply to message #336209] Fri, 29 May 2009 19:41 Go to previous message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

Andy wrote:
> Thanks for the help. I did change the wizard around so that I was
> getting the page out of the wizard class and not instantiating a new
> one. That seemed to solve the weird indexing error and I was able to
> move through the wizard as normal.
> The part that I don't get is why I am still getting a doubling of the
> getNextPage method. It seems that when you first start the wizard
> getNextPage is called on the displayed page. Then it is called again
> when you press the Next button. That just seems very odd to me as
> getNextPage is called twice per page, once when the page is loaded and
> again when the wizard is leaving the page.
> I am guessing it was implemented this way on the load of one of the
> pages to see if there was a next page in the wizard and use that answer
> as to whether the next button should be greyed out or not so that the
> wizard would know it was at the end of the wizard pages when it loaded
> the next page. It just seems that if this was indeed the reason it
> traded that for the hassle of dealing with a double call on every page.
> Is there any way to have a method called just once per page, like a do
> Next or doPrevious? Or a way to trap when the page is being loaded as
> opposed to when the page is being left to go to another page? Thanks,
>
> Andy

Andy,
What you really seem to need is a sequence diagram for the lifetime of a
wizard. but since we don't have one, use the debugger to "construct" one
of your own.
The "extra" call is most likely coming from
org.eclipse.jface.wizard.WizardDialog.updateButtons() where it is
determining enabled/disabled state for the buttons. A couple of
strategically placed breakpoints should reveal more detail if you need it.
I know you can basically do what you seem to be trying, as I've done
similar before. I was simply trying to enable/disable an entire page
based on the content of a previous page.
Another option you have is to use a single page (instead of different
pages) but use a org.eclipse.swt.custom.StackLayout on that page to
allow you to control what is visible on that page.
In any case, the debugger and Open Call Hierarchy (Ctrl+Alt+H) are your
best friends in this kind of exploratory situation.

Hope this helps,
Eric


> Dann Martens wrote:
>
>> Hi Andy,
>
>> As you see from this example method, the pages are instantiated, here.
>
>> public void addPages() {
>> holidayPage = new HolidayMainPage(workbench, selection);
>> addPage(holidayPage);
>> planePage = new PlanePage("");
>> addPage(planePage);
>> carPage = new CarPage("");
>> addPage(carPage);
>> }
>
>> Yet, in your code, you're also instantiating pages, again. That can't
>> be right. Each page references native resources and should be
>> disposed. If you don't dispose, you'll have resource leaks. You're
>> introducing a new page out of the blue, without 'adding' that page to
>> the Wizard. In the implementation of 'addPage', you can see
>> 'page.setWizard(this);' - your new page hasn't even had its parent
>> Wizard set,
>
>> This is the source code of getNextPage of the Wizard class:
>
>> /*
>> * (non-Javadoc) Method declared on IWizard. The default behavior is to
>> * return the page that was added to this wizard after the given page.
>> */
>> public IWizardPage getNextPage(IWizardPage page) {
>> int index = pages.indexOf(page);
>> if (index == pages.size() - 1 || index == -1) {
>> // last page or page not found
>> return null;
>> }
>> return (IWizardPage) pages.get(index + 1);
>> }
>
>> Try to modify the code properly, by determining the proper index based
>> on your flow conditions.
>
>> Best regards,
>> Dann
>
>
Previous Topic:Unsatisfied version constraint
Next Topic:No more Activator.getDefault().getBundle().getLocation() and Activator.getDefault().getStateLocation
Goto Forum:
  


Current Time: Thu Apr 25 10:38:07 GMT 2024

Powered by FUDForum. Page generated in 0.03503 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top