| 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.events.ModifyEvent; |
| import org.eclipse.swt.events.ModifyListener; |
| 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; |
| import org.eclipse.swt.widgets.DirectoryDialog; |
| import org.eclipse.swt.widgets.Display; |
| import org.eclipse.swt.widgets.Label; |
| import org.eclipse.swt.widgets.Text; |
| |
| |
| /** |
| * Wizard page prompting the user for an installation location |
| */ |
| public class InstallDirPage extends InstallPage |
| { |
| private static final String DIALOG_TEXT = "Select directory to install software."; |
| private static final String DIALOG_MESSAGE = "Select directory to install software."; |
| private static final String LABEL_TEXT = "To select a destination folder, click Browse. Then click Next to continue."; |
| private static final String BUTTON_TEXT = "Bro&wse..."; |
| |
| private Text text; |
| private Label label; |
| private Label details; |
| private Button uninstallButton; |
| |
| public InstallDirPage(IWizardStep step) { |
| super(step, "Install location"); |
| } |
| |
| /** |
| * Create contents of the wizard |
| * |
| * @param parent |
| */ |
| public void createControl(Composite parent) { |
| Composite container = new Composite(parent, SWT.NULL); |
| final GridLayout gridLayout = new GridLayout(); |
| gridLayout.numColumns = 2; |
| gridLayout.marginHeight = 10; |
| gridLayout.marginWidth = 15; |
| container.setLayout(gridLayout); |
| setControl(container); |
| |
| createTextLabel(container); |
| createSelectDirBar(container); |
| createUninstallButton(container); |
| createDetails(container); |
| |
| updatePageComplete(); |
| } |
| |
| private void createTextLabel(Composite container) { |
| label = new Label(container, SWT.WRAP); |
| label.setText(LABEL_TEXT); |
| GridData data = new GridData(GridData.FILL_HORIZONTAL); |
| data.horizontalSpan = 2; |
| label.setLayoutData(data); |
| } |
| |
| private void createSelectDirBar(Composite container) { |
| text = new Text(container, SWT.BORDER); |
| text.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); |
| text.addModifyListener(new ModifyListener() { |
| public void modifyText(ModifyEvent e) { |
| updatePageComplete(); |
| } |
| }); |
| |
| final Button browseButton = new Button(container, SWT.NONE); |
| browseButton.setText(BUTTON_TEXT); |
| browseButton.addSelectionListener(new SelectionListener() { |
| public void widgetSelected(SelectionEvent e) { |
| String path = browse(); |
| if (path != null) |
| text.setText(path); |
| updatePageComplete(); |
| } |
| |
| public void widgetDefaultSelected(SelectionEvent e) { |
| widgetSelected(e); |
| } |
| }); |
| } |
| |
| private void createDetails(Composite container) { |
| details = new Label(container, SWT.WRAP); |
| details.setText(""); |
| GridData data = new GridData(GridData.FILL_BOTH); |
| data.horizontalSpan = 2; |
| details.setLayoutData(data); |
| } |
| |
| private void createUninstallButton(Composite container) |
| { |
| uninstallButton = new Button(container, SWT.NONE); |
| uninstallButton.setText("Uninstall.."); |
| |
| } |
| |
| public void addUninstallSelectionListener(SelectionListener listener) |
| { |
| uninstallButton.addSelectionListener(listener); |
| } |
| |
| public void setVisibleUninstallButton(boolean visible) |
| { |
| uninstallButton.setVisible(visible); |
| } |
| /** |
| * Set the explainatory text that appears in the wizard page below the select field |
| * |
| * @param text the details |
| */ |
| public void setDetails(String text) { |
| details.setText(text != null ? text : ""); |
| } |
| |
| /** |
| * Answer the installation directory. Cannot be called before controls are created or |
| * after controls are disposed. |
| * |
| * @return the installation directory selected by the user |
| */ |
| public String getInstallDir() { |
| return text.getText().trim(); |
| } |
| |
| /** |
| * Set the installation directory. Cannot be called before controls are created or |
| * after controls are disposed. |
| * |
| * @param pathString the installation directory |
| */ |
| public void setInstallDir(String pathString) { |
| text.setText(pathString != null ? pathString.trim() : ""); |
| } |
| |
| /** |
| * Prompt the user for an installation location. |
| * |
| * @return the installation location or <code>null</code> if canceled by the user |
| */ |
| protected String browse() { |
| DirectoryDialog dialog = new DirectoryDialog(Display.getCurrent().getActiveShell()); |
| dialog.setText(DIALOG_TEXT); |
| dialog.setMessage(DIALOG_MESSAGE); |
| String path = dialog.open(); |
| return path; |
| } |
| |
| public void setVisible(boolean visible) { |
| super.setVisible(visible); |
| if (visible) |
| setDefaultFocus(); |
| } |
| |
| /** |
| * Focus on default element |
| */ |
| public void setDefaultFocus() { |
| text.setFocus(); |
| text.setSelection(0,text.getText().length()); |
| } |
| } |