1 11 package org.eclipse.update.internal.ui.security; 12 13 import org.eclipse.jface.dialogs.*; 14 import org.eclipse.jface.dialogs.Dialog; 15 import org.eclipse.swt.*; 16 import org.eclipse.swt.layout.*; 17 import org.eclipse.swt.widgets.*; 18 import org.eclipse.ui.*; 19 import org.eclipse.update.internal.ui.*; 20 21 24 public class UserValidationDialog extends Dialog { 25 protected Text usernameField; 26 protected Text passwordField; 27 28 protected String host; 29 protected String message; 30 protected Authentication userAuthentication = null; 31 37 public static Authentication getAuthentication(final String host, 38 final String message) { 39 class UIOperation implements Runnable { 40 public Authentication authentication; 41 public void run() { 42 authentication = UserValidationDialog.askForAuthentication( 43 host, message); 44 } 45 } 46 47 UIOperation uio = new UIOperation(); 48 if (Display.getCurrent() != null) { 49 uio.run(); 50 } else { 51 Display.getDefault().syncExec(uio); 52 } 53 return uio.authentication; 54 } 55 61 protected static Authentication askForAuthentication(String host, 62 String message) { 63 UserValidationDialog ui = new UserValidationDialog(null, host, message); 64 ui.open(); 65 return ui.getAuthentication(); 66 } 67 73 protected UserValidationDialog(Shell parentShell, String host, 74 String message) { 75 super(parentShell); 76 this.host = host; 77 this.message = message; 78 setBlockOnOpen(true); 79 } 80 82 protected void configureShell(Shell newShell) { 83 super.configureShell(newShell); 84 newShell.setText(UpdateUIMessages.UserVerificationDialog_PasswordRequired); 85 } 86 88 public void create() { 89 super.create(); 90 usernameField.selectAll(); 92 usernameField.setFocus(); 93 } 94 96 protected Control createDialogArea(Composite parent) { 97 Composite main = new Composite(parent, SWT.NONE); 98 GridLayout layout = new GridLayout(); 99 layout.numColumns = 3; 100 main.setLayout(layout); 101 main.setLayoutData(new GridData(GridData.FILL_BOTH)); 102 103 Label label = new Label(main, SWT.WRAP); 104 String text = UpdateUIMessages.UserVerificationDialog_ConnectTo + host; 105 text += "\n\n" + message; label.setText(text); 107 GridData data = new GridData(GridData.FILL_HORIZONTAL); 108 data.horizontalSpan = 3; 109 label.setLayoutData(data); 110 111 createUsernameFields(main); 112 createPasswordFields(main); 113 PlatformUI.getWorkbench().getHelpSystem().setHelp(main, 114 "org.eclipse.update.ui.UserValidationDialog"); return main; 116 } 117 120 protected void createPasswordFields(Composite parent) { 121 new Label(parent, SWT.NONE).setText(UpdateUIMessages.UserVerificationDialog_Password); 122 123 passwordField = new Text(parent, SWT.BORDER | SWT.PASSWORD); 124 GridData data = new GridData(GridData.FILL_HORIZONTAL); 125 data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); 126 passwordField.setLayoutData(data); 127 128 new Label(parent, SWT.NONE); } 130 133 protected void createUsernameFields(Composite parent) { 134 new Label(parent, SWT.NONE).setText(UpdateUIMessages.UserVerificationDialog_UserName); 135 136 usernameField = new Text(parent, SWT.BORDER); 137 GridData data = new GridData(GridData.FILL_HORIZONTAL); 138 data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); 139 usernameField.setLayoutData(data); 140 141 new Label(parent, SWT.NONE); } 143 147 public Authentication getAuthentication() { 148 return userAuthentication; 149 } 150 153 protected void okPressed() { 154 userAuthentication = new Authentication(usernameField.getText(), 155 passwordField.getText()); 156 super.okPressed(); 157 } 158 159 } 160 | Popular Tags |