Search in sources :

Example 1 with II18nManager

use of de.janrufmonitor.framework.i18n.II18nManager 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)

Example 2 with II18nManager

use of de.janrufmonitor.framework.i18n.II18nManager in project janrufmonitor by tbrandt77.

the class JournalBuilder method translate.

private static String translate(String text) {
    II18nManager i18n = PIMRuntime.getInstance().getI18nManagerFactory().getI18nManager();
    String prefix = "<!-- start_translate:";
    String postfix = ":end_translate-->";
    while (text.indexOf(prefix) >= 0) {
        String token = text.substring(text.indexOf(prefix) + prefix.length(), text.indexOf(postfix));
        String[] elements = token.split(",");
        if (elements.length == 4) {
            String translation = i18n.getString(elements[0], elements[1], elements[2], elements[3]);
            text = StringUtils.replaceString(text, prefix + token + postfix, translation);
        }
        if (elements.length == 3) {
            String translation = i18n.getString(elements[0], elements[1], "label", elements[2]);
            text = StringUtils.replaceString(text, prefix + token + postfix, translation);
        }
        if (elements.length == 2) {
            String translation = i18n.getString(IJAMConst.GLOBAL_NAMESPACE, elements[0], "label", elements[1]);
            text = StringUtils.replaceString(text, prefix + token + postfix, translation);
        }
    }
    return text;
}
Also used : II18nManager(de.janrufmonitor.framework.i18n.II18nManager)

Example 3 with II18nManager

use of de.janrufmonitor.framework.i18n.II18nManager in project janrufmonitor by tbrandt77.

the class I18nHandler method removeI18nData.

public void removeI18nData(Properties i18nData) {
    try {
        II18nManager i18n = PIMRuntime.getInstance().getI18nManagerFactory().getI18nManager();
        Iterator iter = i18nData.keySet().iterator();
        String key = null;
        while (iter.hasNext()) {
            key = (String) iter.next();
            StringTokenizer st = new StringTokenizer(key, this.NAMESPACE_SEPARATOR);
            String namespace = st.nextToken();
            i18n.removeNamespace(namespace);
        }
        i18n.saveData();
    } catch (NullPointerException ex) {
        this.m_logger.severe("I18n entry is invalid: " + ex.getMessage());
    } catch (NoSuchElementException ex) {
        this.m_logger.severe("I18n entry is invalid: " + ex.getMessage());
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) Iterator(java.util.Iterator) II18nManager(de.janrufmonitor.framework.i18n.II18nManager) NoSuchElementException(java.util.NoSuchElementException)

Example 4 with II18nManager

use of de.janrufmonitor.framework.i18n.II18nManager in project janrufmonitor by tbrandt77.

the class I18nHandler method addI18nData.

public void addI18nData(Properties i18nData) {
    try {
        II18nManager i18n = PIMRuntime.getInstance().getI18nManagerFactory().getI18nManager();
        Iterator iter = i18nData.keySet().iterator();
        String key = null;
        while (iter.hasNext()) {
            key = (String) iter.next();
            StringTokenizer st = new StringTokenizer(key, this.NAMESPACE_SEPARATOR);
            String namespace = st.nextToken();
            String parameter = st.nextToken();
            String identifier = st.nextToken();
            String language = st.nextToken();
            String value = i18nData.getProperty(key);
            i18n.setString(namespace, parameter, identifier, language, value);
        }
        i18n.saveData();
    } catch (NullPointerException ex) {
        this.m_logger.severe("I18n entry is invalid: " + ex.getMessage());
    } catch (NoSuchElementException ex) {
        this.m_logger.severe("I18n entry is invalid: " + ex.getMessage());
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) Iterator(java.util.Iterator) II18nManager(de.janrufmonitor.framework.i18n.II18nManager) NoSuchElementException(java.util.NoSuchElementException)

Example 5 with II18nManager

use of de.janrufmonitor.framework.i18n.II18nManager in project janrufmonitor by tbrandt77.

the class AutoUpdate method createFieldEditors.

protected void createFieldEditors() {
    this.noDefaultAndApplyButton();
    super.createFieldEditors();
    FieldEditor bfe = new FieldEditor("check-button", "c", this.getFieldEditorParent()) {

        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;
            new Label(c, SWT.NONE);
            II18nManager i18 = PIMRuntime.getInstance().getI18nManagerFactory().getI18nManager();
            String l = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_LANGUAGE);
            String text = i18.getString("ui.jface.configuration.pages.AutoUpdate", "execute", "label", l);
            Button up = new Button(c, SWT.PUSH);
            up.setText(text);
            up.pack();
            up.addSelectionListener(new SelectionAdapter() {

                public void widgetSelected(SelectionEvent e) {
                    ICommand c = getRuntime().getCommandFactory().getCommand("UpdatesCommand");
                    if (c != null && c.isExecutable()) {
                        try {
                            c.execute();
                        } catch (Exception ex) {
                            m_logger.log(Level.SEVERE, ex.getMessage(), ex);
                        }
                    }
                }
            });
        }

        protected void doLoad() {
        }

        protected void doLoadDefault() {
        }

        protected void doStore() {
        }

        public int getNumberOfControls() {
            return 1;
        }
    };
    addField(bfe);
}
Also used : FieldEditor(org.eclipse.jface.preference.FieldEditor) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) ICommand(de.janrufmonitor.framework.command.ICommand) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) SelectionEvent(org.eclipse.swt.events.SelectionEvent) II18nManager(de.janrufmonitor.framework.i18n.II18nManager)

Aggregations

II18nManager (de.janrufmonitor.framework.i18n.II18nManager)7 Iterator (java.util.Iterator)3 FieldEditor (org.eclipse.jface.preference.FieldEditor)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 GridData (org.eclipse.swt.layout.GridData)3 Button (org.eclipse.swt.widgets.Button)3 Composite (org.eclipse.swt.widgets.Composite)3 NoSuchElementException (java.util.NoSuchElementException)2 StringTokenizer (java.util.StringTokenizer)2 Label (org.eclipse.swt.widgets.Label)2 ICommand (de.janrufmonitor.framework.command.ICommand)1 IConfigManager (de.janrufmonitor.framework.configuration.IConfigManager)1 GoogleContactsLoginException (de.janrufmonitor.repository.GoogleContactsLoginException)1 ICallerManager (de.janrufmonitor.repository.ICallerManager)1 ZipArchive (de.janrufmonitor.repository.zip.ZipArchive)1 ZipArchiveException (de.janrufmonitor.repository.zip.ZipArchiveException)1 BooleanFieldEditor (de.janrufmonitor.ui.jface.configuration.controls.BooleanFieldEditor)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1