1 11 package org.eclipse.team.internal.ccvs.ui; 12 13 14 import org.eclipse.jface.dialogs.*; 15 import org.eclipse.jface.dialogs.Dialog; 16 import org.eclipse.jface.window.Window; 17 import org.eclipse.osgi.util.NLS; 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.events.SelectionAdapter; 20 import org.eclipse.swt.events.SelectionEvent; 21 import org.eclipse.swt.graphics.Image; 22 import org.eclipse.swt.layout.GridData; 23 import org.eclipse.swt.layout.GridLayout; 24 import org.eclipse.swt.widgets.*; 25 import org.eclipse.team.internal.ui.ITeamUIImages; 26 import org.eclipse.team.ui.TeamImages; 27 import org.eclipse.ui.PlatformUI; 28 29 32 public class UserValidationDialog extends TrayDialog { 33 protected Text usernameField; 35 protected Text passwordField; 36 protected Button allowCachingButton; 37 38 protected String domain; 39 protected String defaultUsername; 40 protected String password = null; 41 protected boolean allowCaching = false; 42 protected Image keyLockImage; 43 44 protected boolean isUsernameMutable = true; 46 protected String username = null; 47 protected String message = null; 48 boolean cachingCheckbox=true; 49 50 58 public UserValidationDialog(Shell parentShell, String location, String defaultName, String message) { 59 this(parentShell, location, defaultName, message, true); 60 } 61 62 71 public UserValidationDialog(Shell parentShell, String location, String defaultName, String message, boolean cachingCheckbox) { 72 super(parentShell); 73 setShellStyle(getShellStyle() | SWT.RESIZE); 74 this.defaultUsername = defaultName; 75 this.domain = location; 76 this.message = message; 77 this.cachingCheckbox=cachingCheckbox; 78 } 79 80 83 protected void configureShell(Shell newShell) { 84 super.configureShell(newShell); 85 newShell.setText(CVSUIMessages.UserValidationDialog_required); 86 PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IHelpContextIds.USER_VALIDATION_DIALOG); 88 } 89 92 public void create() { 93 super.create(); 94 usernameField.setText(defaultUsername); 96 97 if (isUsernameMutable) { 98 usernameField.selectAll(); 100 usernameField.setFocus(); 101 } else { 102 usernameField.setEditable(false); 103 passwordField.setFocus(); 104 } 105 } 106 107 110 protected Control createDialogArea(Composite parent) { 111 Composite top = new Composite(parent, SWT.NONE); 112 GridLayout layout = new GridLayout(); 113 layout.numColumns = 2; 114 115 top.setLayout(layout); 116 top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 117 118 Composite imageComposite = new Composite(top, SWT.NONE); 119 layout = new GridLayout(); 120 imageComposite.setLayout(layout); 121 imageComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL)); 122 123 Composite main = new Composite(top, SWT.NONE); 124 layout = new GridLayout(); 125 layout.numColumns = 3; 126 main.setLayout(layout); 127 main.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 128 129 Label imageLabel = new Label(imageComposite, SWT.NONE); 130 keyLockImage = TeamImages.getImageDescriptor(ITeamUIImages.IMG_KEY_LOCK).createImage(); 131 imageLabel.setImage(keyLockImage); 132 GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); 133 imageLabel.setLayoutData(data); 134 135 if (message != null) { 136 Label messageLabel = new Label(main, SWT.WRAP); 137 messageLabel.setText(message); 138 data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); 139 data.horizontalSpan = 3; 140 data.widthHint = 300; 141 messageLabel.setLayoutData(data); 142 } 143 if (domain != null) { 144 Label d = new Label(main, SWT.WRAP); 145 d.setText(CVSUIMessages.UserValidationDialog_5); 146 data = new GridData(); 147 d.setLayoutData(data); 148 Label label = new Label(main, SWT.WRAP); 149 if (isUsernameMutable) { 150 label.setText(NLS.bind(CVSUIMessages.UserValidationDialog_labelUser, new String [] { domain })); 151 } else { 152 label.setText(NLS.bind(CVSUIMessages.UserValidationDialog_labelPassword, (new Object []{defaultUsername, domain}))); 153 } 154 data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); 155 data.horizontalSpan = 2; 156 data.widthHint = 300; 157 label.setLayoutData(data); 158 } 159 createUsernameFields(main); 160 createPasswordFields(main); 161 162 if(cachingCheckbox && domain != null) { 163 allowCachingButton = new Button(main, SWT.CHECK); 164 allowCachingButton.setText(CVSUIMessages.UserValidationDialog_6); 165 data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); 166 data.horizontalSpan = 3; 167 allowCachingButton.setLayoutData(data); 168 allowCachingButton.addSelectionListener(new SelectionAdapter() { 169 public void widgetSelected(SelectionEvent e) { 170 allowCaching = allowCachingButton.getSelection(); 171 } 172 }); 173 Composite warningComposite = new Composite(main, SWT.NONE); 174 layout = new GridLayout(); 175 layout.numColumns = 2; 176 layout.marginHeight = 0; 177 layout.marginHeight = 0; 178 warningComposite.setLayout(layout); 179 data = new GridData(GridData.FILL_HORIZONTAL); 180 data.horizontalSpan = 3; 181 warningComposite.setLayoutData(data); 182 Label warningLabel = new Label(warningComposite, SWT.NONE); 183 warningLabel.setImage(getImage(DLG_IMG_MESSAGE_WARNING)); 184 warningLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING)); 185 Label warningText = new Label(warningComposite, SWT.WRAP); 186 warningText.setText(CVSUIMessages.UserValidationDialog_7); 187 data = new GridData(GridData.FILL_HORIZONTAL); 188 data.widthHint = 300; 189 warningText.setLayoutData(data); 190 } 191 192 Dialog.applyDialogFont(parent); 193 194 return main; 195 } 196 197 202 protected void createPasswordFields(Composite parent) { 203 new Label(parent, SWT.NONE).setText(CVSUIMessages.UserValidationDialog_password); 204 205 passwordField = new Text(parent, SWT.BORDER | SWT.PASSWORD); 206 GridData data = new GridData(GridData.FILL_HORIZONTAL); 207 data.horizontalSpan = 2; 208 data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); 209 passwordField.setLayoutData(data); 210 } 211 216 protected void createUsernameFields(Composite parent) { 217 new Label(parent, SWT.NONE).setText(CVSUIMessages.UserValidationDialog_user); 218 219 usernameField = new Text(parent, SWT.BORDER); 220 GridData data = new GridData(GridData.FILL_HORIZONTAL); 221 data.horizontalSpan = 2; 222 data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); 223 usernameField.setLayoutData(data); 224 } 225 226 232 public String getPassword() { 233 return password; 234 } 235 236 242 public String getUsername() { 243 return username; 244 } 245 246 251 public boolean getAllowCaching() { 252 return allowCaching; 253 } 254 255 263 protected void okPressed() { 264 password = passwordField.getText(); 265 username = usernameField.getText(); 266 267 super.okPressed(); 268 } 269 276 public void setUsernameMutable(boolean value) { 277 isUsernameMutable = value; 278 } 279 280 283 public boolean close() { 284 if(keyLockImage != null) { 285 keyLockImage.dispose(); 286 } 287 return super.close(); 288 } 289 } 290 | Popular Tags |