Search in sources :

Example 1 with ICallerManager

use of de.janrufmonitor.repository.ICallerManager 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 ICallerManager

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

the class IsdnMoniCallImporter method doImport.

public ICallList doImport() {
    this.m_callerList = null;
    boolean doNotShowmessage = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty(this.getNamespace(), CFG_SHOW_ENTRY_WARNING).equalsIgnoreCase("true");
    if (!doNotShowmessage) {
        new SWTExecuter() {

            protected void execute() {
                String message = getI18nManager().getString(getNamespace(), "message", "description", getLanguage());
                MessageDialogWithToggle d = MessageDialogWithToggle.openYesNoQuestion(new Shell(DisplayManager.getDefaultDisplay()), getI18nManager().getString(getNamespace(), "message", "label", getLanguage()), message, getI18nManager().getString(getNamespace(), "confirmmessage", "label", getLanguage()), false, null, null);
                if (d.getReturnCode() == 2) {
                    m_callerList = getRuntime().getCallerFactory().createCallerList();
                }
                getRuntime().getConfigManagerFactory().getConfigManager().setProperty(getNamespace(), CFG_SHOW_ENTRY_WARNING, (d.getToggleState() ? "true" : "false"));
                getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
                isDialogFinished = true;
            }
        }.start();
    } else {
        isDialogFinished = true;
    }
    while (!isDialogFinished) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
        }
    }
    Date startDate = new Date();
    File db = new File(m_filename);
    int size = (int) db.length() / 64;
    size = Math.abs(size);
    ThreadGroup g = new ThreadGroup("JAM- HeuerMigrator-ThreadGroup");
    m_callList = getRuntime().getCallFactory().createCallList(size);
    m_pnList = new ArrayList(size);
    try {
        FileReader dbReader = new FileReader(db);
        BufferedReader bufReader = new BufferedReader(dbReader);
        int i = 0;
        while (bufReader.ready()) {
            String line = bufReader.readLine();
            if (line.indexOf("->") > 0) {
                try {
                    Thread t = new Thread(g, new MigratorThread(this.m_callList, (this.m_callerList != null ? this.m_callerList : null), line, this.m_pnList));
                    t.setName("JAM-HeuerMigrator#" + (i++) + "-Thread-(non-deamon)");
                    t.start();
                    if (g.activeCount() > 100) {
                        Thread.sleep(1000);
                    }
                } catch (Exception ex) {
                    this.m_logger.severe("Unexpected error during migration: " + ex);
                }
            }
        }
        bufReader.close();
        dbReader.close();
    } catch (FileNotFoundException ex) {
        this.m_logger.warning("Cannot find call backup file " + m_filename);
        return this.m_callList;
    } catch (IOException ex) {
        this.m_logger.severe("IOException on file " + m_filename);
        return this.m_callList;
    }
    while (g.activeCount() > 0) {
        try {
            Thread.sleep(1000);
            this.m_logger.info("Waiting for " + g.activeCount() + " Migrator threads.");
        } catch (InterruptedException e) {
            this.m_logger.severe(e.getMessage());
        }
    }
    if (this.m_callerList != null) {
        this.m_logger.info("Commiting detected callers to default caller manager.");
        String cm = getRuntime().getConfigManagerFactory().getConfigManager().getProperty("ui.jface.application.editor.Editor", "repository");
        ICallerManager cmg = this.getRuntime().getCallerManagerFactory().getCallerManager(cm);
        if (cmg != null && cmg.isActive() && cmg.isSupported(IWriteCallerRepository.class)) {
            ((IWriteCallerRepository) cmg).setCaller(this.m_callerList);
        }
    }
    Date endDate = new Date();
    this.m_logger.info("Successfully imported call file " + m_filename);
    this.m_logger.info("Found " + new Integer(this.m_callList.size()).toString() + " call items in " + new Float((endDate.getTime() - startDate.getTime()) / 1000).toString() + " secs.");
    return m_callList;
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Date(java.util.Date) ParseException(java.text.ParseException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ICallerManager(de.janrufmonitor.repository.ICallerManager) Shell(org.eclipse.swt.widgets.Shell) IWriteCallerRepository(de.janrufmonitor.repository.types.IWriteCallerRepository) BufferedReader(java.io.BufferedReader) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) FileReader(java.io.FileReader) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter) File(java.io.File)

Example 3 with ICallerManager

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

the class EditorController method _getRepository.

private ICallerManager _getRepository() {
    String managerID = this.m_configuration.getProperty(CFG_REPOSITORY, "");
    if (managerID.length() > 0) {
        ICallerManager cm = this.getRuntime().getCallerManagerFactory().getCallerManager(managerID);
        if (cm != null)
            return cm;
    }
    this.m_logger.severe("CallerManager with ID " + managerID + " does not exist.");
    return null;
}
Also used : ICallerManager(de.janrufmonitor.repository.ICallerManager)

Example 4 with ICallerManager

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

the class EditorController method deleteElements.

public synchronized void deleteElements(Object list) {
    if (list != null && list instanceof ICallerList) {
        Map cms = new HashMap();
        ICallerList tmplist = null;
        ICaller c = null;
        for (int i = 0; i < ((ICallerList) list).size(); i++) {
            c = ((ICallerList) list).get(i);
            IAttribute att = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
            String cname = (att == null ? "all" : att.getValue());
            if (cms.containsKey(cname)) {
                tmplist = (ICallerList) cms.get(cname);
                tmplist.add(c);
            } else {
                tmplist = this.getRuntime().getCallerFactory().createCallerList(1);
                tmplist.add(c);
                cms.put(cname, tmplist);
            }
        }
        List managers = this.getActiveCallerManagers();
        ICallerManager mgr = null;
        for (int i = 0; i < managers.size(); i++) {
            mgr = this.getRuntime().getCallerManagerFactory().getCallerManager((String) managers.get(i));
            if (mgr != null) {
                if (mgr.isSupported(IWriteCallerRepository.class)) {
                    tmplist = (ICallerList) cms.get("all");
                    if (tmplist != null) {
                        this.m_logger.info("removing " + tmplist.size() + " callers to manager: " + mgr.getManagerID());
                        ((IWriteCallerRepository) mgr).removeCaller(tmplist);
                    }
                    tmplist = (ICallerList) cms.get(mgr.getManagerID());
                    if (tmplist != null) {
                        this.m_logger.info("removing " + tmplist.size() + " callers to manager: " + mgr.getManagerID());
                        ((IWriteCallerRepository) mgr).removeCaller(tmplist);
                    }
                }
            }
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) HashMap(java.util.HashMap) IWriteCallerRepository(de.janrufmonitor.repository.types.IWriteCallerRepository) IAttribute(de.janrufmonitor.framework.IAttribute) ArrayList(java.util.ArrayList) List(java.util.List) ICallerList(de.janrufmonitor.framework.ICallerList) HashMap(java.util.HashMap) Map(java.util.Map) ICallerManager(de.janrufmonitor.repository.ICallerManager)

Example 5 with ICallerManager

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

the class IdentifyAction method getAllActiveCallerManagers.

private List getAllActiveCallerManagers(IRuntime r, String ignoreManager) {
    List allManagers = r.getCallerManagerFactory().getAllCallerManagers();
    List activeManager = new ArrayList();
    Object o = null;
    ICallerManager cm = null;
    for (int i = 0; i < allManagers.size(); i++) {
        o = allManagers.get(i);
        if (o != null && o instanceof ICallerManager) {
            cm = (ICallerManager) o;
            if (cm.isActive() && !cm.getManagerID().equalsIgnoreCase(ignoreManager) && !cm.getManagerID().equalsIgnoreCase("CountryDirectory")) {
                activeManager.add(cm);
            }
        }
    }
    Collections.sort(activeManager, new RepositoryManagerComparator());
    return activeManager;
}
Also used : ArrayList(java.util.ArrayList) RepositoryManagerComparator(de.janrufmonitor.repository.RepositoryManagerComparator) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) ICallerManager(de.janrufmonitor.repository.ICallerManager)

Aggregations

ICallerManager (de.janrufmonitor.repository.ICallerManager)31 List (java.util.List)15 ArrayList (java.util.ArrayList)14 ICallerList (de.janrufmonitor.framework.ICallerList)13 ICaller (de.janrufmonitor.framework.ICaller)12 IIdentifyCallerRepository (de.janrufmonitor.repository.types.IIdentifyCallerRepository)11 CallerNotFoundException (de.janrufmonitor.repository.CallerNotFoundException)9 IWriteCallerRepository (de.janrufmonitor.repository.types.IWriteCallerRepository)7 IAttribute (de.janrufmonitor.framework.IAttribute)6 HandlerException (de.janrufmonitor.service.commons.http.handler.HandlerException)6 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)5 IFilter (de.janrufmonitor.repository.filter.IFilter)4 RepositoryManagerComparator (de.janrufmonitor.repository.RepositoryManagerComparator)3 ILocalRepository (de.janrufmonitor.repository.types.ILocalRepository)3 IReadCallerRepository (de.janrufmonitor.repository.types.IReadCallerRepository)3 File (java.io.File)3 OutputStream (java.io.OutputStream)3 StringTokenizer (java.util.StringTokenizer)3 Shell (org.eclipse.swt.widgets.Shell)3 IConfigurable (de.janrufmonitor.framework.configuration.IConfigurable)2