1 11 package org.eclipse.jsch.internal.ui; 12 13 14 import org.eclipse.jface.dialogs.*; 15 import org.eclipse.jface.dialogs.Dialog; 16 import org.eclipse.jface.resource.ImageDescriptor; 17 import org.eclipse.jface.window.Window; 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.ui.PlatformUI; 26 27 30 public class UserValidationDialog extends TrayDialog { 31 protected Text usernameField; 33 protected Text passwordField; 34 protected Button allowCachingButton; 35 36 protected String domain; 37 protected String defaultUsername; 38 protected String password = null; 39 protected boolean allowCaching = false; 40 protected Image keyLockImage; 41 42 protected boolean isUsernameMutable = true; 44 protected String username = null; 45 protected String message = null; 46 47 55 public UserValidationDialog(Shell parentShell, String location, String defaultName, String message) { 56 super(parentShell); 57 setShellStyle(getShellStyle() | SWT.RESIZE); 58 this.defaultUsername = defaultName; 59 this.domain = location; 60 this.message = message; 61 } 62 65 protected void configureShell(Shell newShell) { 66 super.configureShell(newShell); 67 newShell.setText(Messages.UserValidationDialog_0); 68 PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IHelpContextIds.USER_VALIDATION_DIALOG); 70 } 71 74 public void create() { 75 super.create(); 76 usernameField.setText(defaultUsername); 78 79 if (isUsernameMutable) { 80 usernameField.selectAll(); 82 usernameField.setFocus(); 83 } else { 84 usernameField.setEditable(false); 85 passwordField.setFocus(); 86 } 87 } 88 89 92 protected Control createDialogArea(Composite parent) { 93 Composite top = new Composite(parent, SWT.NONE); 94 GridLayout layout = new GridLayout(); 95 layout.numColumns = 2; 96 97 top.setLayout(layout); 98 top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 99 100 Composite imageComposite = new Composite(top, SWT.NONE); 101 layout = new GridLayout(); 102 imageComposite.setLayout(layout); 103 imageComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL)); 104 105 Composite main = new Composite(top, SWT.NONE); 106 layout = new GridLayout(); 107 layout.numColumns = 3; 108 main.setLayout(layout); 109 main.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 110 111 Label imageLabel = new Label(imageComposite, SWT.NONE); 112 keyLockImage = ImageDescriptor.createFromURL(JSchUIPlugin.getPlugin().getImageUrl(IUIConstants.IMG_KEY_LOCK)).createImage(); 113 imageLabel.setImage(keyLockImage); 114 GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); 115 imageLabel.setLayoutData(data); 116 117 if (message != null) { 118 Label messageLabel = new Label(main, SWT.WRAP); 119 messageLabel.setText(message); 120 data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); 121 data.horizontalSpan = 3; 122 data.widthHint = 300; 123 messageLabel.setLayoutData(data); 124 } 125 if (domain != null) { 126 Label d = new Label(main, SWT.WRAP); 127 d.setText(Messages.UserValidationDialog_1); 128 data = new GridData(); 129 d.setLayoutData(data); 130 Label label = new Label(main, SWT.WRAP); 131 label.setText(domain); 132 data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); 133 data.horizontalSpan = 2; 134 data.widthHint = 300; 135 label.setLayoutData(data); 136 } 137 createUsernameFields(main); 138 createPasswordFields(main); 139 140 if(domain != null) { 141 allowCachingButton = new Button(main, SWT.CHECK); 142 allowCachingButton.setText(Messages.UserValidationDialog_2); 143 data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); 144 data.horizontalSpan = 3; 145 allowCachingButton.setLayoutData(data); 146 allowCachingButton.addSelectionListener(new SelectionAdapter() { 147 public void widgetSelected(SelectionEvent e) { 148 allowCaching = allowCachingButton.getSelection(); 149 } 150 }); 151 Composite warningComposite = new Composite(main, SWT.NONE); 152 layout = new GridLayout(); 153 layout.numColumns = 2; 154 layout.marginHeight = 0; 155 layout.marginHeight = 0; 156 warningComposite.setLayout(layout); 157 data = new GridData(GridData.FILL_HORIZONTAL); 158 data.horizontalSpan = 3; 159 warningComposite.setLayoutData(data); 160 Label warningLabel = new Label(warningComposite, SWT.NONE); 161 warningLabel.setImage(getImage(DLG_IMG_MESSAGE_WARNING)); 162 warningLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING)); 163 Label warningText = new Label(warningComposite, SWT.WRAP); 164 warningText.setText(Messages.UserValidationDialog_3); 165 data = new GridData(GridData.FILL_HORIZONTAL); 166 data.widthHint = 300; 167 warningText.setLayoutData(data); 168 } 169 170 Dialog.applyDialogFont(parent); 171 172 return main; 173 } 174 175 180 protected void createPasswordFields(Composite parent) { 181 new Label(parent, SWT.NONE).setText(Messages.UserValidationDialog_4); 182 183 passwordField = new Text(parent, SWT.BORDER | SWT.PASSWORD); 184 GridData data = new GridData(GridData.FILL_HORIZONTAL); 185 data.horizontalSpan = 2; 186 data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); 187 passwordField.setLayoutData(data); 188 } 189 194 protected void createUsernameFields(Composite parent) { 195 new Label(parent, SWT.NONE).setText(Messages.UserValidationDialog_5); 196 197 usernameField = new Text(parent, SWT.BORDER); 198 GridData data = new GridData(GridData.FILL_HORIZONTAL); 199 data.horizontalSpan = 2; 200 data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); 201 usernameField.setLayoutData(data); 202 } 203 204 210 public String getPassword() { 211 return password; 212 } 213 214 220 public String getUsername() { 221 return username; 222 } 223 224 229 public boolean getAllowCaching() { 230 return allowCaching; 231 } 232 233 241 protected void okPressed() { 242 password = passwordField.getText(); 243 username = usernameField.getText(); 244 245 super.okPressed(); 246 } 247 248 protected void cancelPressed(){ 249 password = null; 250 username = null; 251 super.cancelPressed(); 252 } 253 254 261 public void setUsernameMutable(boolean value) { 262 isUsernameMutable = value; 263 } 264 265 268 public boolean close() { 269 if(keyLockImage != null) { 270 keyLockImage.dispose(); 271 } 272 return super.close(); 273 } 274 } 275 | Popular Tags |