use of eu.esdihumboldt.hale.ui.util.components.PasswordFieldEditor in project hale by halestudio.
the class HaleConnectPreferencePage method createFieldEditors.
/**
* Creates the field editors. Field editors are abstractions of the common
* GUI blocks needed to manipulate various types of preferences. Each field
* editor knows how to save and restore itself.
*/
@Override
public void createFieldEditors() {
final HaleConnectService hcs = HaleUI.getServiceProvider().getService(HaleConnectService.class);
StringFieldEditor usernameEditor = new StringFieldEditor(PreferenceConstants.HALE_CONNECT_USERNAME, "&User name:", getFieldEditorParent());
addField(usernameEditor);
usernameEditor.getTextControl(getFieldEditorParent()).addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
clearResult();
}
});
PasswordFieldEditor passwordEditor = new PasswordFieldEditor(PreferenceConstants.SECURE_NODE_NAME, PreferenceConstants.HALE_CONNECT_PASSWORD, // $NON-NLS-1$
"&Password:", getFieldEditorParent());
addField(passwordEditor);
passwordEditor.getTextControl().addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
clearResult();
}
});
Link link = new Link(getFieldEditorParent(), SWT.NONE);
link.setText("Not registered yet? <a href=\"https://www.haleconnect.com\">Create an account.</a>");
link.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(e.text));
} catch (PartInitException | MalformedURLException e1) {
setResultError("Error opening external browser. Please visit https://www.haleconnect.com to register.");
}
}
});
link.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
resultLabel = new Label(getFieldEditorParent(), SWT.NONE);
resultLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
clearResult();
Button validate = new Button(getFieldEditorParent(), SWT.NONE);
validate.setText("Validate credentials");
Button clear = new Button(getFieldEditorParent(), SWT.NONE);
clear.setText("Clear credentials");
validate.addSelectionListener(new SelectionAdapter() {
/**
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
performApply();
try {
String username = HaleConnectUIPlugin.getStoredUsername();
String password = HaleConnectUIPlugin.getStoredPassword();
if (hcs.verifyCredentials(username, password)) {
setResultSuccess("Credentials are valid.");
} else {
setResultError("Credentials were rejected.");
}
} catch (HaleConnectException ex) {
log.userError("Error accessing hale connect", ex);
} catch (StorageException ex) {
log.userError("Error accessing secure storage", ex);
}
}
});
clear.addSelectionListener(new SelectionAdapter() {
/**
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
if (MessageDialog.openConfirm(getShell(), "Remove credentials", "This will remove the stored credentials and log you out.")) {
usernameEditor.setStringValue("");
passwordEditor.getTextControl().setText("");
performApply();
clearResult();
hcs.clearSession();
log.userInfo("Credentials removed.");
}
}
});
if (hcs.isLoggedIn()) {
setResult(MessageFormat.format("Logged in as \"{0}\"", hcs.getSession().getUsername()));
}
}
use of eu.esdihumboldt.hale.ui.util.components.PasswordFieldEditor in project hale by halestudio.
the class ProxyPreferencePage method createFieldEditors.
/**
* @see FieldEditorPreferencePage#createFieldEditors()
*/
@Override
protected void createFieldEditors() {
// proxy host
addField(new StringFieldEditor(PreferenceConstants.CONNECTION_PROXY_HOST, // $NON-NLS-1$
Messages.ProxyPreferencePage_1, getFieldEditorParent()));
// proxy port
addField(new IntegerFieldEditor(PreferenceConstants.CONNECTION_PROXY_PORT, // $NON-NLS-1$
Messages.ProxyPreferencePage_2, getFieldEditorParent()));
// proxy user name
addField(new StringFieldEditor(PreferenceConstants.CONNECTION_PROXY_USER, // $NON-NLS-1$
Messages.ProxyPreferencePage_5, getFieldEditorParent()));
// proxy password
addField(new PasswordFieldEditor(PreferenceConstants.SECURE_NODE_NAME, // $NON-NLS-1$
PreferenceConstants.CONNECTION_PROXY_PASSWORD, // $NON-NLS-1$
Messages.ProxyPreferencePage_6, getFieldEditorParent()));
// non proxy hosts
addField(new StringFieldEditor(PreferenceConstants.CONNECTION_NON_PROXY_HOSTS, // $NON-NLS-1$
Messages.ProxyPreferencePage_3, getFieldEditorParent()));
// placeholder
Composite ph = new Composite(getFieldEditorParent(), SWT.NONE);
ph.setLayoutData(GridDataFactory.swtDefaults().hint(0, 0).create());
// info label
Label info = new Label(getFieldEditorParent(), SWT.NONE);
// $NON-NLS-1$
info.setText(Messages.ProxyPreferencePage_4);
info.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false, 1, 1));
}
Aggregations