Search in sources :

Example 1 with GoogleContactsLoginException

use of de.janrufmonitor.repository.GoogleContactsLoginException in project janrufmonitor by tbrandt77.

the class GoogleContactsCallerManager method createFieldEditors.

protected void createFieldEditors() {
    super.createFieldEditors();
    BooleanFieldEditor bfe = new BooleanFieldEditor(getConfigNamespace() + SEPARATOR + "keepextension", this.m_i18n.getString(this.getNamespace(), "keepextension", "label", this.m_language), this.getFieldEditorParent());
    addField(bfe);
    final StringFieldEditor u = new StringFieldEditor(getConfigNamespace() + SEPARATOR + "user", this.m_i18n.getString(this.getNamespace(), "user", "label", this.m_language), this.getFieldEditorParent());
    u.setEmptyStringAllowed(false);
    addField(u);
    final StringFieldEditor p = new StringFieldEditor(getConfigNamespace() + SEPARATOR + "password", this.m_i18n.getString(this.getNamespace(), "password", "label", this.m_language), this.getFieldEditorParent());
    p.getTextControl(this.getFieldEditorParent()).setEchoChar('*');
    addField(p);
    final FieldEditor ffe = new FieldEditor("check-button", "", this.getFieldEditorParent()) {

        public Button up;

        protected void adjustForNumColumns(int arg0) {
        }

        protected void doFillIntoGrid(Composite c, int numCols) {
            GridData gd = new GridData();
            gd.horizontalAlignment = GridData.FILL;
            gd.grabExcessHorizontalSpace = true;
            gd.horizontalSpan = numCols - 1;
            gd.widthHint = 200;
            final II18nManager i18 = PIMRuntime.getInstance().getI18nManagerFactory().getI18nManager();
            final String l = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_LANGUAGE);
            String text = i18.getString("ui.jface.configuration.pages.GoogleContactsCallerManager", "check", "label", l);
            up = new Button(c, SWT.PUSH);
            // new Label(c, SWT.NONE);
            up.setText(text);
            up.pack();
            up.addSelectionListener(new SelectionAdapter() {

                public void widgetSelected(SelectionEvent e) {
                    ICallerManager cm = getRuntime().getCallerManagerFactory().getCallerManager(de.janrufmonitor.repository.GoogleContactsCallerManager.ID);
                    if (cm != null && cm instanceof de.janrufmonitor.repository.GoogleContactsCallerManager) {
                        try {
                            ((de.janrufmonitor.repository.GoogleContactsCallerManager) cm).checkAuthentication(user, password);
                            MessageDialog.openInformation(new Shell(DisplayManager.getDefaultDisplay()), i18.getString("ui.jface.configuration.pages.GoogleContactsCallerManager", "success", "label", l), i18.getString("ui.jface.configuration.pages.GoogleContactsCallerManager", "success", "description", l));
                            return;
                        } catch (GoogleContactsLoginException ex) {
                        }
                    }
                    MessageDialog.openError(new Shell(DisplayManager.getDefaultDisplay()), i18.getString("ui.jface.configuration.pages.GoogleContactsCallerManager", "error", "label", l), i18.getString("ui.jface.configuration.pages.GoogleContactsCallerManager", "error", "description", l));
                }
            });
        }

        protected void doLoad() {
        }

        protected void doLoadDefault() {
        }

        protected void doStore() {
        }

        public int getNumberOfControls() {
            return 1;
        }

        public void setEnabled(boolean enabled, Composite parent) {
            super.setEnabled(enabled, parent);
            if (up != null)
                up.setEnabled(enabled);
        }
    };
    ffe.setEnabled(false, getFieldEditorParent());
    addField(ffe);
    p.getTextControl(this.getFieldEditorParent()).addKeyListener(new KeyAdapter() {

        public void keyReleased(org.eclipse.swt.events.KeyEvent e) {
            password = p.getStringValue();
            user = u.getStringValue();
            ffe.setEnabled((user != null && password != null && user.length() > 0 && password.length() > 0), getFieldEditorParent());
        }
    });
    u.getTextControl(this.getFieldEditorParent()).addKeyListener(new KeyAdapter() {

        public void keyReleased(org.eclipse.swt.events.KeyEvent e) {
            user = u.getStringValue();
            password = p.getStringValue();
            ffe.setEnabled((user != null && password != null && user.length() > 0 && password.length() > 0), getFieldEditorParent());
        }
    });
    ComboFieldEditor cfe = new ComboFieldEditor(getConfigNamespace() + SEPARATOR + "mode", this.m_i18n.getString(this.getNamespace(), "mode", "label", this.m_language), new String[][] { { this.m_i18n.getString(this.getNamespace(), "mode1", "label", this.m_language), "1" }, { this.m_i18n.getString(this.getNamespace(), "mode2", "label", this.m_language), "2" } }, this.getFieldEditorParent());
    addField(cfe);
    bfe = new BooleanFieldEditor(getConfigNamespace() + SEPARATOR + "syncstart", this.m_i18n.getString(this.getNamespace(), "syncstart", "label", this.m_language), this.getFieldEditorParent());
    addField(bfe);
}
Also used : ComboFieldEditor(org.eclipse.jface.preference.ComboFieldEditor) BooleanFieldEditor(de.janrufmonitor.ui.jface.configuration.controls.BooleanFieldEditor) FieldEditor(org.eclipse.jface.preference.FieldEditor) StringFieldEditor(org.eclipse.jface.preference.StringFieldEditor) GoogleContactsLoginException(de.janrufmonitor.repository.GoogleContactsLoginException) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) KeyAdapter(org.eclipse.swt.events.KeyAdapter) BooleanFieldEditor(de.janrufmonitor.ui.jface.configuration.controls.BooleanFieldEditor) ComboFieldEditor(org.eclipse.jface.preference.ComboFieldEditor) II18nManager(de.janrufmonitor.framework.i18n.II18nManager) ICallerManager(de.janrufmonitor.repository.ICallerManager) StringFieldEditor(org.eclipse.jface.preference.StringFieldEditor) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Aggregations

II18nManager (de.janrufmonitor.framework.i18n.II18nManager)1 GoogleContactsLoginException (de.janrufmonitor.repository.GoogleContactsLoginException)1 ICallerManager (de.janrufmonitor.repository.ICallerManager)1 BooleanFieldEditor (de.janrufmonitor.ui.jface.configuration.controls.BooleanFieldEditor)1 ComboFieldEditor (org.eclipse.jface.preference.ComboFieldEditor)1 FieldEditor (org.eclipse.jface.preference.FieldEditor)1 StringFieldEditor (org.eclipse.jface.preference.StringFieldEditor)1 KeyAdapter (org.eclipse.swt.events.KeyAdapter)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Shell (org.eclipse.swt.widgets.Shell)1