|
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.dialogs; |
| 10 |
|
| 11 |
import org.eclipse.jface.dialogs.Dialog; |
| 12 |
import org.eclipse.jface.dialogs.IDialogConstants; |
| 13 |
import org.eclipse.jface.layout.GridDataFactory; |
| 14 |
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin; |
| 15 |
import org.eclipse.swt.SWT; |
| 16 |
import org.eclipse.swt.events.ModifyEvent; |
| 17 |
import org.eclipse.swt.events.ModifyListener; |
| 18 |
import org.eclipse.swt.events.SelectionAdapter; |
| 19 |
import org.eclipse.swt.events.SelectionEvent; |
| 20 |
import org.eclipse.swt.graphics.Image; |
| 21 |
import org.eclipse.swt.layout.GridData; |
| 22 |
import org.eclipse.swt.layout.GridLayout; |
| 23 |
import org.eclipse.swt.widgets.Button; |
| 24 |
import org.eclipse.swt.widgets.Composite; |
| 25 |
import org.eclipse.swt.widgets.Control; |
| 26 |
import org.eclipse.swt.widgets.Label; |
| 27 |
import org.eclipse.swt.widgets.Shell; |
| 28 |
import org.eclipse.swt.widgets.Text; |
| 29 |
|
| 30 |
/** |
| 31 |
* @author Frank Becker |
| 32 |
* @author Steffen Pingel |
| 33 |
*/ |
| 34 |
public class EditCredentialsDialog extends Dialog { |
| 35 |
|
| 36 |
private static final String TITLE = "Enter Password"; |
| 37 |
|
| 38 |
private boolean savePassword; |
| 39 |
|
| 40 |
private Image keyLockImage; |
| 41 |
|
| 42 |
private String message; |
| 43 |
|
| 44 |
private String username = ""; |
| 45 |
|
| 46 |
private String password = ""; |
| 47 |
|
| 48 |
private String url; |
| 49 |
|
| 50 |
public EditCredentialsDialog(Shell parentShell) { |
| 51 |
super(parentShell); |
| 52 |
|
| 53 |
setShellStyle(getShellStyle() | SWT.RESIZE); |
| 54 |
} |
| 55 |
|
| 56 |
public String getUserName() { |
| 57 |
return username; |
| 58 |
} |
| 59 |
|
| 60 |
public void setUsername(String username) { |
| 61 |
if (username == null) { |
| 62 |
throw new IllegalArgumentException(); |
| 63 |
} |
| 64 |
this.username = username; |
| 65 |
} |
| 66 |
|
| 67 |
public String getPassword() { |
| 68 |
return password; |
| 69 |
} |
| 70 |
|
| 71 |
public void setPassword(String password) { |
| 72 |
if (password == null) { |
| 73 |
throw new IllegalArgumentException(); |
| 74 |
} |
| 75 |
this.password = password; |
| 76 |
} |
| 77 |
|
| 78 |
public String getMessage() { |
| 79 |
return message; |
| 80 |
} |
| 81 |
|
| 82 |
public void setMessage(String message) { |
| 83 |
this.message = message; |
| 84 |
} |
| 85 |
|
| 86 |
public void setUrl(String url) { |
| 87 |
this.url = url; |
| 88 |
} |
| 89 |
|
| 90 |
public String getUrl() { |
| 91 |
return url; |
| 92 |
} |
| 93 |
|
| 94 |
public boolean getSavePassword() { |
| 95 |
return savePassword; |
| 96 |
} |
| 97 |
|
| 98 |
public void setSavePassword(boolean savePassword) { |
| 99 |
this.savePassword = savePassword; |
| 100 |
} |
| 101 |
|
| 102 |
@Override |
| 103 |
protected Control createDialogArea(Composite parent) { |
| 104 |
getShell().setText(TITLE); |
| 105 |
|
| 106 |
Composite composite = new Composite(parent, SWT.NONE); |
| 107 |
composite.setLayout(new GridLayout(2, false)); |
| 108 |
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 109 |
|
| 110 |
Label label = new Label(composite, SWT.NONE); |
| 111 |
keyLockImage = TasksUiPlugin.imageDescriptorFromPlugin(TasksUiPlugin.ID_PLUGIN, "icons/wizban/keylock.gif") |
| 112 |
.createImage(); |
| 113 |
label.setImage(keyLockImage); |
| 114 |
GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.BEGINNING).applyTo(label); |
| 115 |
|
| 116 |
createCenterArea(composite); |
| 117 |
|
| 118 |
Dialog.applyDialogFont(parent); |
| 119 |
|
| 120 |
return composite; |
| 121 |
} |
| 122 |
|
| 123 |
private void createCenterArea(Composite parent) { |
| 124 |
Composite composite = new Composite(parent, SWT.NONE); |
| 125 |
composite.setLayout(new GridLayout(2, false)); |
| 126 |
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 127 |
|
| 128 |
if (message != null) { |
| 129 |
Label label = new Label(composite, SWT.WRAP); |
| 130 |
label.setText(message); |
| 131 |
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).hint( |
| 132 |
convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH), SWT.DEFAULT).grab(true, |
| 133 |
false).span(2, 1).applyTo(label); |
| 134 |
|
| 135 |
// spacer |
| 136 |
label = new Label(composite, SWT.NONE); |
| 137 |
GridDataFactory.fillDefaults().span(2, 1).applyTo(label); |
| 138 |
} |
| 139 |
|
| 140 |
if (url != null) { |
| 141 |
Label label = new Label(composite, SWT.WRAP); |
| 142 |
label.setText("Repository:"); |
| 143 |
|
| 144 |
label = new Label(composite, SWT.NONE); |
| 145 |
label.setText(url); |
| 146 |
GridDataFactory.fillDefaults().applyTo(label); |
| 147 |
} |
| 148 |
|
| 149 |
new Label(composite, SWT.NONE).setText("&User name:"); |
| 150 |
|
| 151 |
final Text usernameField = new Text(composite, SWT.BORDER); |
| 152 |
usernameField.addModifyListener(new ModifyListener() { |
| 153 |
public void modifyText(ModifyEvent e) { |
| 154 |
username = usernameField.getText(); |
| 155 |
} |
| 156 |
}); |
| 157 |
usernameField.setText(username); |
| 158 |
if (username.length() == 0) { |
| 159 |
usernameField.setFocus(); |
| 160 |
} |
| 161 |
GridDataFactory.fillDefaults() |
| 162 |
.align(SWT.FILL, SWT.CENTER) |
| 163 |
.hint(convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH), SWT.DEFAULT) |
| 164 |
.grab(true, false) |
| 165 |
.applyTo(usernameField); |
| 166 |
|
| 167 |
new Label(composite, SWT.NONE).setText("&Password:"); |
| 168 |
|
| 169 |
final Text passwordField = new Text(composite, SWT.BORDER | SWT.PASSWORD); |
| 170 |
passwordField.addModifyListener(new ModifyListener() { |
| 171 |
public void modifyText(ModifyEvent e) { |
| 172 |
password = passwordField.getText(); |
| 173 |
} |
| 174 |
}); |
| 175 |
passwordField.setText(password); |
| 176 |
if (username.length() > 0) { |
| 177 |
passwordField.setFocus(); |
| 178 |
} |
| 179 |
GridDataFactory.fillDefaults() |
| 180 |
.align(SWT.FILL, SWT.CENTER) |
| 181 |
.hint(convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH), SWT.DEFAULT) |
| 182 |
.grab(true, false) |
| 183 |
.applyTo(passwordField); |
| 184 |
|
| 185 |
final Button savePasswordButton = new Button(composite, SWT.CHECK); |
| 186 |
savePasswordButton.setText("&Save password"); |
| 187 |
savePasswordButton.setSelection(savePassword); |
| 188 |
savePasswordButton.addSelectionListener(new SelectionAdapter() { |
| 189 |
@Override |
| 190 |
public void widgetSelected(SelectionEvent e) { |
| 191 |
savePassword = savePasswordButton.getSelection(); |
| 192 |
} |
| 193 |
}); |
| 194 |
GridDataFactory.fillDefaults().span(2, 1).applyTo(savePasswordButton); |
| 195 |
|
| 196 |
createWarningMessage(composite); |
| 197 |
} |
| 198 |
|
| 199 |
private void createWarningMessage(Composite parent) { |
| 200 |
Composite composite = new Composite(parent, SWT.NONE); |
| 201 |
GridLayout layout = new GridLayout(); |
| 202 |
layout.numColumns = 2; |
| 203 |
layout.marginHeight = 0; |
| 204 |
layout.marginHeight = 0; |
| 205 |
composite.setLayout(layout); |
| 206 |
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(composite); |
| 207 |
|
| 208 |
Label label = new Label(composite, SWT.NONE); |
| 209 |
label.setImage(getImage(DLG_IMG_MESSAGE_WARNING)); |
| 210 |
label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING)); |
| 211 |
|
| 212 |
label = new Label(composite, SWT.WRAP); |
| 213 |
label.setText("Saved passwords are stored on your computer in a file that is difficult, but not impossible, for an intruder to read."); |
| 214 |
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).hint( |
| 215 |
convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH), SWT.DEFAULT).grab(true, |
| 216 |
false).applyTo(label); |
| 217 |
} |
| 218 |
|
| 219 |
@Override |
| 220 |
public boolean close() { |
| 221 |
if (keyLockImage != null) { |
| 222 |
keyLockImage.dispose(); |
| 223 |
} |
| 224 |
return super.close(); |
| 225 |
} |
| 226 |
|
| 227 |
} |