Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Handling back and next button in Multiple Page Wizards
Handling back and next button in Multiple Page Wizards [message #605541] Thu, 08 April 2010 11:10 Go to next message
Neha is currently offline NehaFriend
Messages: 12
Registered: December 2009
Junior Member
Hi,
I have a eclipse plugin that has two pages
1st page which takes certain input A
On basis of this input A Second page is to be displayed.

If the user in on 2nd page and goes back to 1st page and changes the input A , a new 2nd page mapping to new inputs needs to be shown.

The eclipse plugin developed by me works fine in normal scenario ie displays the 1st page and according to the input A displays the 2nd page when user uses the plugin for first time.
If the user clicks the back button and changes the input the 2nd page does not change . 2nd pages retains the first input value
How can I achieve this?
This is very urgent.
Please help.
Re: Handling back and next button in Multiple Page Wizards [message #605543 is a reply to message #605541] Thu, 08 April 2010 12:49 Go to previous messageGo to next message
Devi Vara Prasad Bandaru is currently offline Devi Vara Prasad BandaruFriend
Messages: 100
Registered: March 2010
Location: Hyderabad
Senior Member

Here is a sample which updates Second page text value based on the first page combo value.
public class SampleWizard extends Wizard {

@Override
public void addPages() {
addPage(new FirstWizardPage("First Page"));
addPage(new SecondWizardPage("Second Page"));
}

@Override
public boolean performFinish() {
return getPage("Second Page").isPageComplete();
}

class FirstWizardPage extends WizardPage {

private Combo combo;

protected FirstWizardPage(String pageName) {
super(pageName);
setTitle(pageName);
}

public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
Label label = new Label(composite, SWT.NONE);
label.setText("Text");
label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
combo = new Combo(composite, SWT.READ_ONLY);
combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
for (int i = 1; i <= 5; i++) {
combo.add("Option " + i);
}
combo.select(0);

combo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// Updating second page values when first page combo
// selection has changed.
SecondWizardPage secondWizardPage = (SecondWizardPage) getPage("Second Page");
String text = ((Combo) e.getSource()).getText();
secondWizardPage.updateControls(text);
}
});
setControl(composite);
}

protected String getComboValue() {
return combo != null ? combo.getText() : "";
}
}

class SecondWizardPage extends WizardPage {

private Text text;

protected SecondWizardPage(String pageName) {
super(pageName);
setTitle(pageName);
}

public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
Label label = new Label(composite, SWT.NONE);
label.setText("Text");
label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
text = new Text(composite, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
text.setText(((FirstWizardPage) getPage("First Page")).getComboValue());

text.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
setPageComplete(!text.getText().trim().equals(""));
}
});
setControl(composite);
}

protected void updateControls(String string) {
if (text != null) {
text.setText(string);
}
}

@Override
public boolean isPageComplete() {
return !text.getText().trim().equals("");
}

}

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell();
WizardDialog wizardDialog = new WizardDialog(shell, new SampleWizard());
wizardDialog.open();
shell.dispose();
display.dispose();
}

}


--
Regards,
Prasad


Re: Handling back and next button in Multiple Page Wizards [message #605546 is a reply to message #605543] Fri, 09 April 2010 06:16 Go to previous messageGo to next message
Neha is currently offline NehaFriend
Messages: 12
Registered: December 2009
Junior Member
hi,
Thanks for the reply.
In my sccenario there aredata does not change but more controls are added in the next page.
Like if user has selected 1 in the dropdown list then 2nd page will have 1 Text, if he has selected 2 then there would be 2 Text in the 2nd page.

how can this be achieved

Please help.
Re: Handling back and next button in Multiple Page Wizards [message #605549 is a reply to message #605546] Fri, 09 April 2010 09:24 Go to previous message
Devi Vara Prasad Bandaru is currently offline Devi Vara Prasad BandaruFriend
Messages: 100
Registered: March 2010
Location: Hyderabad
Senior Member

Hi,
Here is the modified version of the 'SecondWizardPage' in above sample. When 'Option 1' is selected only first text field will be visible 'Option 2' second text field and when 'Option 3' is selected both fields will be visible. I hope this solves your problem.

class SecondWizardPage extends WizardPage {

private Composite composite;
private Label label1;
private Text text1;
private Label label2;
private Text text2;

protected SecondWizardPage(String pageName) {
super(pageName);
setTitle(pageName);
}

public void createControl(Composite parent) {
composite = new Composite(parent, SWT.BORDER);
composite.setLayout(new GridLayout(2, false));

label1 = new Label(composite, SWT.NONE);
label1.setText("Text1");
label1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
text1 = new Text(composite, SWT.BORDER | SWT.MULTI);
GridData text1Data = new GridData(SWT.FILL, SWT.FILL, true, true);
text1.setLayoutData(text1Data);

label2 = new Label(composite, SWT.NONE);
label2.setText("Text2");
label2.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
text2 = new Text(composite, SWT.BORDER);
text2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

updateControls("Option 1");
setControl(composite);
}

protected void updateControls(String string) {
if (composite != null) {
boolean control1Visible = string.equals("Option 1") || string.equals("Option 3");
boolean control2Visible = string.equals("Option 2") || string.equals("Option 3");

label1.setVisible(control1Visible);// setting the visibility
// excluding from layout so that space occupied by control is
// restored
((GridData) label1.getLayoutData()).exclude = !control1Visible;
text1.setVisible(control1Visible);
((GridData) text1.getLayoutData()).exclude = !control1Visible;
label2.setVisible(control2Visible);
((GridData) label2.getLayoutData()).exclude = !control2Visible;
text2.setVisible(control2Visible);
((GridData) text2.getLayoutData()).exclude = !control2Visible;

composite.layout();
}
}

}

--
Regards,
Prasad


Previous Topic:Plug-in Development help
Next Topic:Re: Handling back and next button in Multiple Page Wizards
Goto Forum:
  


Current Time: Tue Mar 19 04:13:53 GMT 2024

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

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

Back to the top