Home » Eclipse Projects » Plugin Development Environment (PDE) » Handling back and next button in Multiple Page Wizards
|
Re: Handling back and next button in Multiple Page Wizards [message #605543 is a reply to message #605541] |
Thu, 08 April 2010 12:49 |
|
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
Regards,
Prasad
http://marketplace.eclipse.org/user/9964/listings
|
|
| |
Re: Handling back and next button in Multiple Page Wizards [message #605549 is a reply to message #605546] |
Fri, 09 April 2010 09:24 |
|
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
Regards,
Prasad
http://marketplace.eclipse.org/user/9964/listings
|
|
|
Goto Forum:
Current Time: Tue Mar 19 04:13:53 GMT 2024
Powered by FUDForum. Page generated in 0.02842 seconds
|