| package org.eclipse.epp.installer.internal.ui.pages; |
| |
| import org.eclipse.epp.installer.ui.IWizardStep; |
| import org.eclipse.epp.installer.ui.InstallPage; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.custom.StyledText; |
| import org.eclipse.swt.events.SelectionEvent; |
| import org.eclipse.swt.events.SelectionListener; |
| import org.eclipse.swt.layout.GridData; |
| import org.eclipse.swt.layout.GridLayout; |
| import org.eclipse.swt.widgets.Button; |
| import org.eclipse.swt.widgets.Composite; |
| |
| |
| /** |
| * Wizard page displaying a text and two radio buttons. |
| */ |
| public class ChoicePage extends InstallPage |
| { |
| private StyledText agreement; |
| private Button acceptButton; |
| private Button declineButton; |
| private boolean continueOnDecline = true; |
| private boolean choice; |
| |
| public ChoicePage(IWizardStep step) { |
| super(step, "choicePage"); |
| } |
| |
| /** |
| * Create contents of the wizard |
| * |
| * @param Composite parent |
| */ |
| public void createControl(Composite parent) { |
| Composite container = new Composite(parent, SWT.NULL); |
| final GridLayout gridLayout = new GridLayout(); |
| gridLayout.marginHeight = 10; |
| gridLayout.marginWidth = 15; |
| container.setLayout(gridLayout); |
| setControl(container); |
| |
| createAgreement(container); |
| createRadioButtons(container); |
| |
| updatePageComplete(); |
| setPageComplete(continueOnDecline); |
| } |
| |
| private void createAgreement(Composite container) { |
| agreement = new StyledText(container, SWT.V_SCROLL | SWT.BORDER | SWT.WRAP ); |
| agreement.setEditable(false); |
| agreement.setWordWrap(true); |
| agreement.setLayoutData(new GridData( GridData.FILL, GridData.FILL, true, true)); |
| } |
| |
| private void createRadioButtons(Composite container) { |
| acceptButton = new Button(container, SWT.RADIO); |
| acceptButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| acceptButton.addSelectionListener(new SelectionListener() { |
| public void widgetDefaultSelected(SelectionEvent e) { |
| widgetSelected(e); |
| } |
| |
| public void widgetSelected(SelectionEvent e) { |
| choice = true; |
| updatePageComplete(); |
| setPageComplete(true); |
| } |
| }); |
| |
| declineButton = new Button(container, SWT.RADIO); |
| declineButton.setSelection(true); |
| declineButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| declineButton.addSelectionListener(new SelectionListener() { |
| public void widgetDefaultSelected(SelectionEvent e) { |
| widgetSelected(e); |
| } |
| |
| public void widgetSelected(SelectionEvent e) { |
| choice = false; |
| updatePageComplete(); |
| setPageComplete(continueOnDecline); |
| } |
| }); |
| } |
| |
| /** |
| * Set the text to be displayed. |
| * |
| * Must be called after the wizard page content has been created. |
| * |
| * @param String choiceText |
| */ |
| public void setChoiceText(String choiceText) { |
| agreement.setText(choiceText); |
| } |
| |
| /** |
| * Set the text for 'accept' option. |
| * |
| * Must be called after the wizard page content has been created. |
| * |
| * @param String acceptText |
| */ |
| public void setAcceptText(String acceptText) { |
| acceptButton.setText(acceptText); |
| } |
| |
| /** |
| * Set the text for 'decline' option. |
| * |
| * Must be called after the wizard page content has been created. |
| * |
| * @param String declineText |
| */ |
| public void setDeclineText(String declineText) { |
| declineButton.setText(declineText); |
| } |
| |
| /** |
| * Triggers behaivior of dialog page if 'decline' option selected. |
| * |
| * Must be called after the wizard page content has been created. |
| * |
| * @param boolean flag |
| */ |
| public void setContinueOnDecline(boolean flag) { |
| continueOnDecline = flag; |
| setPageComplete(continueOnDecline); |
| } |
| |
| /** |
| * Defines which button will be selected by default, 'Accept' if <code>true</code>, |
| * 'decline' if <code>false</code>. |
| * |
| * @param boolean flag |
| */ |
| public void setDefaultChoice(boolean flag) { |
| choice = flag; |
| acceptButton.setSelection(flag); |
| declineButton.setSelection(!flag); |
| } |
| |
| /** |
| * Return the choice made. <code>true</code> for 'accept', <code>false</code> for 'decline'. |
| * |
| * @return boolean |
| */ |
| public boolean getChoice() { |
| return choice; |
| } |
| |
| public void setVisible(boolean visible) { |
| super.setVisible(visible); |
| if (visible) |
| setDefaultFocus(); |
| } |
| |
| /** |
| * Focus on default element |
| */ |
| public void setDefaultFocus() { |
| if (getChoice()) { |
| acceptButton.setFocus(); |
| } else { |
| declineButton.setFocus(); |
| } |
| } |
| } |