|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2004, 2007 Mylyn project committers and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
*******************************************************************************/ |
| 8 |
|
| 9 |
package org.eclipse.mylyn.internal.tasks.ui; |
| 10 |
|
| 11 |
import org.eclipse.jface.dialogs.Dialog; |
| 12 |
import org.eclipse.jface.dialogs.IDialogConstants; |
| 13 |
import org.eclipse.jface.window.Window; |
| 14 |
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin; |
| 15 |
import org.eclipse.swt.SWT; |
| 16 |
import org.eclipse.swt.events.SelectionAdapter; |
| 17 |
import org.eclipse.swt.events.SelectionEvent; |
| 18 |
import org.eclipse.swt.graphics.Image; |
| 19 |
import org.eclipse.swt.layout.GridData; |
| 20 |
import org.eclipse.swt.layout.GridLayout; |
| 21 |
import org.eclipse.swt.widgets.Button; |
| 22 |
import org.eclipse.swt.widgets.Composite; |
| 23 |
import org.eclipse.swt.widgets.Control; |
| 24 |
import org.eclipse.swt.widgets.Label; |
| 25 |
import org.eclipse.swt.widgets.Shell; |
| 26 |
import org.eclipse.swt.widgets.Text; |
| 27 |
|
| 28 |
/** |
| 29 |
* This Dialog is used to enter a memory only Password for TaskRepositories. |
| 30 |
* |
| 31 |
* Based on org.eclipse.jsch.internal.ui.UserValidationDialog |
| 32 |
* |
| 33 |
* @author Frank Becker |
| 34 |
* @since 2.2 |
| 35 |
*/ |
| 36 |
public class EnterMemoryPassordDialog extends Dialog { |
| 37 |
// widgets |
| 38 |
protected Text usernameField; |
| 39 |
|
| 40 |
protected Text passwordField; |
| 41 |
|
| 42 |
protected Button allowCachingButton; |
| 43 |
|
| 44 |
protected String domain; |
| 45 |
|
| 46 |
protected String defaultUsername; |
| 47 |
|
| 48 |
protected String password = null; |
| 49 |
|
| 50 |
protected boolean allowCaching = false; |
| 51 |
|
| 52 |
protected boolean defaultAllowCaching; |
| 53 |
|
| 54 |
protected Image keyLockImage; |
| 55 |
|
| 56 |
protected String username = null; |
| 57 |
|
| 58 |
protected String message = null; |
| 59 |
|
| 60 |
/** |
| 61 |
* Creates a new EnterMemoryPassordDialog. |
| 62 |
* |
| 63 |
* @param parentShell the parent shell |
| 64 |
* @param repositoryName the name of the repository |
| 65 |
* @param message a message to display to the user |
| 66 |
* @param defaultName the default user name |
| 67 |
* @param defaultAllowCaching TODO |
| 68 |
*/ |
| 69 |
public EnterMemoryPassordDialog(Shell parentShell, String repositoryName, String message, String defaultName, boolean defaultAllowCaching) { |
| 70 |
super(parentShell); |
| 71 |
setShellStyle(getShellStyle() | SWT.RESIZE); |
| 72 |
this.defaultUsername = defaultName; |
| 73 |
this.domain = repositoryName; |
| 74 |
this.message = message; |
| 75 |
this.defaultAllowCaching = defaultAllowCaching; |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* @see Window#configureShell |
| 80 |
*/ |
| 81 |
protected void configureShell(Shell newShell) { |
| 82 |
super.configureShell(newShell); |
| 83 |
newShell.setText("Password Required"); |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* @see Window#create |
| 88 |
*/ |
| 89 |
public void create() { |
| 90 |
super.create(); |
| 91 |
// add some default values |
| 92 |
usernameField.setText(defaultUsername); |
| 93 |
allowCachingButton.setSelection(defaultAllowCaching); |
| 94 |
|
| 95 |
// give focus to user name field |
| 96 |
usernameField.selectAll(); |
| 97 |
usernameField.setFocus(); |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* @see Dialog#createDialogArea |
| 102 |
*/ |
| 103 |
protected Control createDialogArea(Composite parent) { |
| 104 |
Composite top = new Composite(parent, SWT.NONE); |
| 105 |
GridLayout layout = new GridLayout(); |
| 106 |
layout.numColumns = 2; |
| 107 |
|
| 108 |
top.setLayout(layout); |
| 109 |
top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 110 |
|
| 111 |
Composite imageComposite = new Composite(top, SWT.NONE); |
| 112 |
layout = new GridLayout(); |
| 113 |
imageComposite.setLayout(layout); |
| 114 |
imageComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL)); |
| 115 |
|
| 116 |
Composite main = new Composite(top, SWT.NONE); |
| 117 |
layout = new GridLayout(); |
| 118 |
layout.numColumns = 3; |
| 119 |
main.setLayout(layout); |
| 120 |
main.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 121 |
|
| 122 |
Label imageLabel = new Label(imageComposite, SWT.NONE); |
| 123 |
keyLockImage = TasksUiPlugin.imageDescriptorFromPlugin(TasksUiPlugin.ID_PLUGIN, "icons/wizban/keylock.gif") |
| 124 |
.createImage(); |
| 125 |
imageLabel.setImage(keyLockImage); |
| 126 |
GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); |
| 127 |
imageLabel.setLayoutData(data); |
| 128 |
|
| 129 |
if (message != null) { |
| 130 |
Label messageLabel = new Label(main, SWT.WRAP); |
| 131 |
messageLabel.setText(message); |
| 132 |
data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); |
| 133 |
data.horizontalSpan = 3; |
| 134 |
data.widthHint = 300; |
| 135 |
messageLabel.setLayoutData(data); |
| 136 |
} |
| 137 |
if (domain != null) { |
| 138 |
Label d = new Label(main, SWT.WRAP); |
| 139 |
d.setText("Task Repository:"); |
| 140 |
data = new GridData(); |
| 141 |
d.setLayoutData(data); |
| 142 |
Label label = new Label(main, SWT.WRAP); |
| 143 |
label.setText(domain); |
| 144 |
data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); |
| 145 |
data.horizontalSpan = 2; |
| 146 |
data.widthHint = 300; |
| 147 |
label.setLayoutData(data); |
| 148 |
} |
| 149 |
createUsernameFields(main); |
| 150 |
createPasswordFields(main); |
| 151 |
|
| 152 |
if (domain != null) { |
| 153 |
allowCachingButton = new Button(main, SWT.CHECK); |
| 154 |
allowCachingButton.setText("&Save password"); |
| 155 |
data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); |
| 156 |
data.horizontalSpan = 3; |
| 157 |
allowCachingButton.setLayoutData(data); |
| 158 |
allowCachingButton.addSelectionListener(new SelectionAdapter() { |
| 159 |
public void widgetSelected(SelectionEvent e) { |
| 160 |
allowCaching = allowCachingButton.getSelection(); |
| 161 |
} |
| 162 |
}); |
| 163 |
Composite warningComposite = new Composite(main, SWT.NONE); |
| 164 |
layout = new GridLayout(); |
| 165 |
layout.numColumns = 2; |
| 166 |
layout.marginHeight = 0; |
| 167 |
layout.marginHeight = 0; |
| 168 |
warningComposite.setLayout(layout); |
| 169 |
data = new GridData(GridData.FILL_HORIZONTAL); |
| 170 |
data.horizontalSpan = 3; |
| 171 |
warningComposite.setLayoutData(data); |
| 172 |
Label warningLabel = new Label(warningComposite, SWT.NONE); |
| 173 |
warningLabel.setImage(getImage(DLG_IMG_MESSAGE_WARNING)); |
| 174 |
warningLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING |
| 175 |
| GridData.HORIZONTAL_ALIGN_BEGINNING)); |
| 176 |
Label warningText = new Label(warningComposite, SWT.WRAP); |
| 177 |
warningText.setText("Saved passwords are stored on your computer in a file that is difficult, but not impossible, for an intruder to read."); |
| 178 |
data = new GridData(GridData.FILL_HORIZONTAL); |
| 179 |
data.widthHint = 300; |
| 180 |
warningText.setLayoutData(data); |
| 181 |
} |
| 182 |
|
| 183 |
Dialog.applyDialogFont(parent); |
| 184 |
|
| 185 |
return main; |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* Creates the three widgets that represent the password entry area. |
| 190 |
* |
| 191 |
* @param parent the parent of the widgets |
| 192 |
*/ |
| 193 |
protected void createPasswordFields(Composite parent) { |
| 194 |
new Label(parent, SWT.NONE).setText("&Password:"); |
| 195 |
|
| 196 |
passwordField = new Text(parent, SWT.BORDER | SWT.PASSWORD); |
| 197 |
GridData data = new GridData(GridData.FILL_HORIZONTAL); |
| 198 |
data.horizontalSpan = 2; |
| 199 |
data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); |
| 200 |
passwordField.setLayoutData(data); |
| 201 |
} |
| 202 |
|
| 203 |
/** |
| 204 |
* Creates the three widgets that represent the user name entry area. |
| 205 |
* |
| 206 |
* @param parent the parent of the widgets |
| 207 |
*/ |
| 208 |
protected void createUsernameFields(Composite parent) { |
| 209 |
new Label(parent, SWT.NONE).setText("&User name:"); |
| 210 |
|
| 211 |
usernameField = new Text(parent, SWT.BORDER); |
| 212 |
GridData data = new GridData(GridData.FILL_HORIZONTAL); |
| 213 |
data.horizontalSpan = 2; |
| 214 |
data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); |
| 215 |
usernameField.setLayoutData(data); |
| 216 |
} |
| 217 |
|
| 218 |
/** |
| 219 |
* Returns the password entered by the user, or null |
| 220 |
* if the user canceled. |
| 221 |
* |
| 222 |
* @return the entered password |
| 223 |
*/ |
| 224 |
public String getPassword() { |
| 225 |
return password; |
| 226 |
} |
| 227 |
|
| 228 |
/** |
| 229 |
* Returns the user name entered by the user, or null |
| 230 |
* if the user canceled. |
| 231 |
* |
| 232 |
* @return the entered user name |
| 233 |
*/ |
| 234 |
public String getUsername() { |
| 235 |
return username; |
| 236 |
} |
| 237 |
|
| 238 |
/** |
| 239 |
* Returns <code>true</code> if the save password checkbox was selected. |
| 240 |
* @return <code>true</code> if the save password checkbox was selected and <code>false</code> |
| 241 |
* otherwise. |
| 242 |
*/ |
| 243 |
public boolean getAllowCaching() { |
| 244 |
return allowCaching; |
| 245 |
} |
| 246 |
|
| 247 |
/** |
| 248 |
* Notifies that the ok button of this dialog has been pressed. |
| 249 |
* <p> |
| 250 |
* The default implementation of this framework method sets |
| 251 |
* this dialog's return code to <code>Window.OK</code> |
| 252 |
* and closes the dialog. Subclasses may override. |
| 253 |
* </p> |
| 254 |
*/ |
| 255 |
protected void okPressed() { |
| 256 |
password = passwordField.getText(); |
| 257 |
username = usernameField.getText(); |
| 258 |
|
| 259 |
super.okPressed(); |
| 260 |
} |
| 261 |
|
| 262 |
protected void cancelPressed() { |
| 263 |
password = null; |
| 264 |
username = null; |
| 265 |
super.cancelPressed(); |
| 266 |
} |
| 267 |
|
| 268 |
/* (non-Javadoc) |
| 269 |
* @see org.eclipse.jface.dialogs.Dialog#close() |
| 270 |
*/ |
| 271 |
public boolean close() { |
| 272 |
if (keyLockImage != null) { |
| 273 |
keyLockImage.dispose(); |
| 274 |
} |
| 275 |
return super.close(); |
| 276 |
} |
| 277 |
} |