|
|
|
Re: Next Button Event Listener - JFace Wizard [message #1815779 is a reply to message #1815777] |
Thu, 10 October 2019 13:15 |
Emmanuel Chebbi Messages: 123 Registered: February 2018 |
Senior Member |
|
|
Mihnea-Costache Marin wrote on Thu, 10 October 2019 13:52The principal class is extending from Wizard and implements IImportWizard, IWizard. There I create the two pages: page1 = new Page1();.
The pages are extending the WizardPage.
Is it ok?
Looks good to me.
Mihnea-Costache Marin wrote on Thu, 10 October 2019 13:52
The thing is, I have tried a lot of ways but it's not working
Please explain what you mean by "it's not working": what did you try exactly? Is an exception thrown? Did you browse the class' documentation but did not see any relevant method? Did you manage to execute some code when the user clicks Next but page2's fields are not updating?
Mihnea-Costache Marin wrote on Thu, 10 October 2019 13:52The problem that I'm facing is the fact that the second page is created at the same time the first page is created thus affecting me.
Even if the two pages are created at the same time, that does not prevent you from updating them later on. Here, you have to:
- Determine when the user clicks on Next
- Retrieve the data from the first page
- Update the second page with these data
According to the documentation, the Wizard#getNextPage method is called by the wizard right before a new page is shown, so you can override it to add some preprocessing. That solves point 1).
In your wizard you should have a reference to Page1 and can use it to query your data. That solves point 2).
You should also have a reference to Page2 and can use it to update the fields. That solves point 3).
The corresponding code is the following:
class SecondPage extends WizardPage {
private Text projectNameField;
@Override
public void createControl(Composite parent) {
// Create empty fields
String projectName = previous.getProjectName();
projectNameField = new Text(parent, SWT.SINGLE);
projectNameField.setText("");
}
public void updateProjectName(String newProjectName) {
// Update the text field
projectNameField.setText(newProjectName);
}
class MyWizard extends Wizards {
private Page1 page1;
private Page2 page2;
@Override
public IWizardPage getNextPage(IWizardPage page) {
// This method is called just before showing the second
IWizardPage nextPage = super.getNextPage(page);
// If the wizard is about to show the second page
if (nextPage == page2) {
// We retrieve the data from page1 ...
String projectName = ((Page1) page).getProjectName();
// ... and use it to update page2
page2.updateProjectName(projectName);
}
return nextPage;
}
}
Note: according to this anwser on StackOverflow the getNextPage() method may be called multiple times, so take care not to put long-runtime process there.
This code may even be simplified. Indeed, the createControl() method may be called only when the page is shown. In other words, graphical components (lists, text fields, etc.) of the second page may not be created until the user clicks on Next. In fact I would expect this behavior but I didn't try so I am not sure that's actually the case. I invite you to test because if that's the case then the code can be simplify.
Indeed, you could thus both 1) retrieve the data from the first page and 2) initialize your fields with the expecting values within Page2:
class Page2 extends WizardPage {
private Text projectNameField;
@Override
public void createControl(Composite parent) {
IWizardPage previousPage = getPreviousPage();
Page1 firstPage = (Page1) previous;
String projectName = previous.getProjectName();
projectNameField = new Text(parent, SWT.SINGLE);
projectNameField.setText(projectName);
}
}
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03820 seconds