Search in sources :

Example 1 with PasswordFieldEditor

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()));
    }
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) PasswordFieldEditor(eu.esdihumboldt.hale.ui.util.components.PasswordFieldEditor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException) URL(java.net.URL) StringFieldEditor(org.eclipse.jface.preference.StringFieldEditor) ModifyEvent(org.eclipse.swt.events.ModifyEvent) HaleConnectService(eu.esdihumboldt.hale.io.haleconnect.HaleConnectService) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) StorageException(org.eclipse.equinox.security.storage.StorageException) Link(org.eclipse.swt.widgets.Link)

Example 2 with PasswordFieldEditor

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));
}
Also used : StringFieldEditor(org.eclipse.jface.preference.StringFieldEditor) PasswordFieldEditor(eu.esdihumboldt.hale.ui.util.components.PasswordFieldEditor) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) IntegerFieldEditor(org.eclipse.jface.preference.IntegerFieldEditor)

Aggregations

PasswordFieldEditor (eu.esdihumboldt.hale.ui.util.components.PasswordFieldEditor)2 StringFieldEditor (org.eclipse.jface.preference.StringFieldEditor)2 GridData (org.eclipse.swt.layout.GridData)2 Label (org.eclipse.swt.widgets.Label)2 HaleConnectException (eu.esdihumboldt.hale.io.haleconnect.HaleConnectException)1 HaleConnectService (eu.esdihumboldt.hale.io.haleconnect.HaleConnectService)1 URL (java.net.URL)1 StorageException (org.eclipse.equinox.security.storage.StorageException)1 IntegerFieldEditor (org.eclipse.jface.preference.IntegerFieldEditor)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Link (org.eclipse.swt.widgets.Link)1