Search in sources :

Example 96 with ICaller

use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.

the class IdentifyAction method run.

public synchronized void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null && v instanceof Viewer) {
        final IStructuredSelection selection = (IStructuredSelection) v.getSelection();
        if (!selection.isEmpty()) {
            if (selection.getFirstElement() instanceof ICaller) {
                ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
                try {
                    IRunnableWithProgress r = new IRunnableWithProgress() {

                        public void run(IProgressMonitor progressMonitor) {
                            progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "identifyprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                            progressMonitor.worked(1);
                            final ICaller caller = (ICaller) selection.getFirstElement();
                            List phones = new ArrayList();
                            if (caller instanceof IMultiPhoneCaller) {
                                phones.addAll(((IMultiPhoneCaller) caller).getPhonenumbers());
                            } else {
                                phones.add(caller.getPhoneNumber());
                            }
                            String ignoreCM = "";
                            IAttribute att = caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
                            if (att != null) {
                                ignoreCM = att.getValue();
                            }
                            List activeCMs = getAllActiveCallerManagers(getRuntime(), ignoreCM);
                            ICaller identifiedCaller = null;
                            // identification only makes sence if there are active CMs or if there are numbers
                            if (activeCMs.size() > 0 && phones.size() > 0) {
                                IPhonenumber pn = null;
                                for (int i = 0; i < phones.size(); i++) {
                                    pn = (IPhonenumber) phones.get(i);
                                    identifiedCaller = Identifier.identify(getRuntime(), pn, activeCMs);
                                    if (identifiedCaller != null)
                                        break;
                                }
                            }
                            progressMonitor.done();
                            if (identifiedCaller == null) {
                                progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "failedidentify", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                                PropagationFactory.getInstance().fire(new Message(Message.INFO, getNamespace(), "failedidentify", new Exception("Caller with number " + caller.getPhoneNumber() + " not identified...")));
                                return;
                            }
                            // remove repository flag and set all numbers
                            if (!(identifiedCaller instanceof IMultiPhoneCaller)) {
                                identifiedCaller = getRuntime().getCallerFactory().toMultiPhoneCaller(identifiedCaller);
                            }
                            ((IMultiPhoneCaller) identifiedCaller).setPhonenumbers(phones);
                            ((IMultiPhoneCaller) identifiedCaller).setPhoneNumber((IPhonenumber) phones.get(0));
                            IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
                            m.addAll(caller.getAttributes());
                            m.addAll(identifiedCaller.getAttributes());
                            m.remove(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
                            identifiedCaller.setAttributes(m);
                            final ICaller theIdentifiedCaller = identifiedCaller;
                            new SWTExecuter() {

                                protected void execute() {
                                    if (MessageDialog.openConfirm(new Shell(DisplayManager.getDefaultDisplay()), getI18nManager().getString(getNamespace(), "identify", "label", getLanguage()), getI18nManager().getString(getNamespace(), "identify", "description", getLanguage()))) {
                                        ICaller newCaller = openCallerWizard(theIdentifiedCaller);
                                        if (newCaller != null) {
                                            ICallerList list = getRuntime().getCallerFactory().createCallerList(1);
                                            list.add(caller);
                                            m_app.getController().deleteElements(list);
                                            list.clear();
                                            list.add(newCaller);
                                            m_app.getController().addElements(list);
                                            m_app.updateViews(true);
                                        }
                                    }
                                }
                            }.start();
                        }
                    };
                    pmd.setBlockOnOpen(false);
                    pmd.run(true, false, r);
                // ModalContext.run(r, true, pmd.getProgressMonitor(), DisplayManager.getDefaultDisplay());
                } catch (InterruptedException e) {
                    m_logger.log(Level.SEVERE, e.getMessage(), e);
                } catch (InvocationTargetException e) {
                    m_logger.log(Level.SEVERE, e.getMessage(), e);
                }
            }
        }
    }
}
Also used : Message(de.janrufmonitor.exception.Message) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ICaller(de.janrufmonitor.framework.ICaller) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Shell(org.eclipse.swt.widgets.Shell) ICallerList(de.janrufmonitor.framework.ICallerList) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 97 with ICaller

use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.

the class SingleVcfExportAction method run.

public void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null && v instanceof Viewer) {
        final IStructuredSelection selection = (IStructuredSelection) v.getSelection();
        if (!selection.isEmpty()) {
            Iterator it = selection.iterator();
            final ICallerList list = this.getRuntime().getCallerFactory().createCallerList(selection.size());
            Object o = null;
            while (it.hasNext()) {
                o = it.next();
                if (o instanceof ICaller) {
                    list.add((ICaller) o);
                }
            }
            try {
                FileDialog dialog = new FileDialog(new Shell(DisplayManager.getDefaultDisplay()), SWT.SAVE);
                dialog.setText(this.getI18nManager().getString(this.getNamespace(), "title", "label", this.getLanguage()));
                if (list.size() == 1) {
                    dialog.setFileName(((ICaller) list.get(0)).getName().getFirstname() + " " + ((ICaller) list.get(0)).getName().getLastname());
                }
                if (ImExportFactory.getInstance().getExporter("VcfFileCallerExporter") == null)
                    return;
                List ids = new ArrayList();
                ids.add("VcfFileCallerExporter");
                String[] filternames = new String[ids.size()];
                String[] extensions = new String[ids.size()];
                IImExporter ie = null;
                for (int i = 0; i < ids.size(); i++) {
                    ie = ImExportFactory.getInstance().getExporter((String) ids.get(i));
                    filternames[i] = ie.getFilterName();
                    extensions[i] = ie.getExtension();
                }
                dialog.setFilterNames(filternames);
                dialog.setFilterExtensions(extensions);
                String filter = getRuntime().getConfigManagerFactory().getConfigManager().getProperty(getNamespace(), "lastopeneddir");
                if (filter == null || filter.length() == 0 || !new File(filter).exists())
                    filter = PathResolver.getInstance(getRuntime()).getDataDirectory();
                dialog.setFilterPath(filter);
                final String filename = dialog.open();
                if (filename == null)
                    return;
                filter = new File(filename).getParentFile().getAbsolutePath();
                getRuntime().getConfigManagerFactory().getConfigManager().setProperty(getNamespace(), "lastopeneddir", filter);
                String ext = "";
                for (int i = 0; i < ids.size(); i++) {
                    final IImExporter exp = ImExportFactory.getInstance().getExporter((String) ids.get(i));
                    ext = exp.getExtension().substring(1);
                    if (filename.toLowerCase().endsWith(ext) && exp.getMode() == IImExporter.CALLER_MODE) {
                        try {
                            ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
                            IRunnableWithProgress r = new IRunnableWithProgress() {

                                public void run(IProgressMonitor progressMonitor) {
                                    progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "exportprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                                    ((ICallerExporter) exp).setCallerList(list);
                                    exp.setFilename(filename);
                                    if (((ICallerExporter) exp).doExport()) {
                                        progressMonitor.done();
                                        PropagationFactory.getInstance().fire(new Message(Message.INFO, getI18nManager().getString(Editor.NAMESPACE, "title", "label", getLanguage()), new Exception(getI18nManager().getString(getNamespace(), "success", "description", getLanguage()))), "Tray");
                                    } else {
                                        progressMonitor.done();
                                        new SWTExecuter() {

                                            protected void execute() {
                                                MessageDialog.openError(DisplayManager.getDefaultDisplay().getActiveShell(), getI18nManager().getString(getNamespace(), "error", "label", getLanguage()), getI18nManager().getString(getNamespace(), "error", "description", getLanguage()));
                                                m_logger.warning("Export of contacts failed.");
                                            }
                                        }.start();
                                    }
                                }
                            };
                            pmd.setBlockOnOpen(false);
                            pmd.run(true, false, r);
                        } catch (InterruptedException e) {
                            throw e;
                        } catch (InvocationTargetException e) {
                            throw e;
                        }
                    // m_app.updateViews(false);
                    }
                }
            } catch (Exception ex) {
                this.m_logger.log(Level.SEVERE, ex.getMessage(), ex);
                PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "error", ex));
            }
        }
    }
}
Also used : Message(de.janrufmonitor.exception.Message) ICallerExporter(de.janrufmonitor.repository.imexport.ICallerExporter) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ICaller(de.janrufmonitor.framework.ICaller) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ICallerList(de.janrufmonitor.framework.ICallerList) IImExporter(de.janrufmonitor.repository.imexport.IImExporter) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter)

Example 98 with ICaller

use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.

the class EditorController method updateElement.

public synchronized void updateElement(Object element) {
    if (element != null && element instanceof ICallerList) {
        ICallerManager mgr = this._getRepository();
        if (mgr != null) {
            if (mgr.isSupported(IWriteCallerRepository.class)) {
                for (int i = 0, j = ((ICallerList) element).size(); i < j; i++) {
                    ((IWriteCallerRepository) mgr).updateCaller(((ICallerList) element).get(i));
                }
            }
        }
    }
    if (element != null && element instanceof ICaller) {
        List managers = this.getActiveCallerManagers();
        ICallerManager mgr = null;
        IAttribute att = ((ICaller) element).getAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
        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)) {
                    if (att == null || att.getValue().equalsIgnoreCase(mgr.getManagerID()))
                        ((IWriteCallerRepository) mgr).updateCaller((ICaller) element);
                }
            }
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) IWriteCallerRepository(de.janrufmonitor.repository.types.IWriteCallerRepository) IAttribute(de.janrufmonitor.framework.IAttribute) ArrayList(java.util.ArrayList) List(java.util.List) ICallerList(de.janrufmonitor.framework.ICallerList) ICallerManager(de.janrufmonitor.repository.ICallerManager)

Example 99 with ICaller

use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.

the class EditorController method buildControllerData.

private void buildControllerData() {
    ICallerManager cm = this._getRepository();
    if (cm != null && cm.isActive() && cm.isSupported(IReadCallerRepository.class)) {
        if (cm.isSupported(ISearchableCallerRepository.class)) {
            this.m_data = ((ISearchableCallerRepository) cm).getCallers(new IFilter[] { this.getFilter() }, new SearchTermSeriarlizer().getSearchTermsFromString(StringUtils.urlEncode(this.m_configuration.getProperty(CFG_SEARCHTERMS, ""))));
        } else {
            this.m_data = ((IReadCallerRepository) cm).getCallers(this.getFilter());
        }
        if (this.m_data == null)
            this.m_data = this.getRuntime().getCallerFactory().createCallerList();
        this.doSorting();
        List lastnames = new ArrayList(26);
        List cities = new ArrayList(26);
        List pcode = new ArrayList(9);
        List countries = new ArrayList(12);
        ICaller c = null;
        for (int i = 0; i < this.m_data.size(); i++) {
            c = this.m_data.get(i);
            if (c instanceof ICaller) {
                if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_LASTNAME) && c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue().trim().length() > 0) {
                    if (!hasForbiddenFilterChars(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue().substring(0, 1).toUpperCase()))
                        lastnames.add(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue().substring(0, 1).toUpperCase());
                }
                if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_CITY) && c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_CITY).getValue().trim().length() > 0) {
                    if (!hasForbiddenFilterChars(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_CITY).getValue().substring(0, 1).toUpperCase()))
                        cities.add(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_CITY).getValue().substring(0, 1).toUpperCase());
                }
                if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE) && c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE).getValue().trim().length() > 0) {
                    if (!hasForbiddenFilterChars(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE).getValue().substring(0, 1).toUpperCase()))
                        pcode.add(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE).getValue().substring(0, 1).toUpperCase());
                }
                if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_COUNTRY) && c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_COUNTRY).getValue().trim().length() > 0) {
                    if (!hasForbiddenFilterChars(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_COUNTRY).getValue().substring(0, 1).toUpperCase()))
                        countries.add(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_COUNTRY).getValue().substring(0, 1).toUpperCase());
                }
            }
        }
        Collections.sort(lastnames);
        Collections.sort(cities);
        Collections.sort(pcode);
        Collections.sort(countries);
        for (int i = 0; i < lastnames.size(); i++) {
            this.m_configuration.put("filter_" + IJAMConst.ATTRIBUTE_NAME_LASTNAME + "_" + (String) lastnames.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_LASTNAME + "=" + (String) lastnames.get(i) + ")");
            this.getRuntime().getConfigManagerFactory().getConfigManager().setProperty(Editor.NAMESPACE, "filter_" + IJAMConst.ATTRIBUTE_NAME_LASTNAME + "_" + (String) lastnames.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_LASTNAME + "=" + (String) lastnames.get(i) + ")");
        }
        for (int i = 0; i < cities.size(); i++) {
            this.m_configuration.put("filter_" + IJAMConst.ATTRIBUTE_NAME_CITY + "_" + (String) cities.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_CITY + "=" + (String) cities.get(i) + ")");
            this.getRuntime().getConfigManagerFactory().getConfigManager().setProperty(Editor.NAMESPACE, "filter_" + IJAMConst.ATTRIBUTE_NAME_CITY + "_" + (String) cities.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_CITY + "=" + (String) cities.get(i) + ")");
        }
        for (int i = 0; i < pcode.size(); i++) {
            this.m_configuration.put("filter_" + IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE + "_" + (String) pcode.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE + "=" + (String) pcode.get(i) + ")");
            this.getRuntime().getConfigManagerFactory().getConfigManager().setProperty(Editor.NAMESPACE, "filter_" + IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE + "_" + (String) pcode.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_LASTNAME + "=" + (String) pcode.get(i) + ")");
        }
        for (int i = 0; i < countries.size(); i++) {
            this.m_configuration.put("filter_" + IJAMConst.ATTRIBUTE_NAME_COUNTRY + "_" + (String) countries.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_COUNTRY + "=" + (String) countries.get(i) + ")");
            this.getRuntime().getConfigManagerFactory().getConfigManager().setProperty(Editor.NAMESPACE, "filter_" + IJAMConst.ATTRIBUTE_NAME_COUNTRY + "_" + (String) countries.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_COUNTRY + "=" + (String) countries.get(i) + ")");
        }
        this.getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
    }
    if (this.m_data == null)
        this.m_data = this.getRuntime().getCallerFactory().createCallerList();
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) IFilter(de.janrufmonitor.repository.filter.IFilter) ArrayList(java.util.ArrayList) IReadCallerRepository(de.janrufmonitor.repository.types.IReadCallerRepository) ArrayList(java.util.ArrayList) List(java.util.List) ICallerList(de.janrufmonitor.framework.ICallerList) ICallerManager(de.janrufmonitor.repository.ICallerManager) SearchTermSeriarlizer(de.janrufmonitor.repository.search.SearchTermSeriarlizer)

Example 100 with ICaller

use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.

the class CombineAction method run.

public void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null) {
        IStructuredSelection selection = (IStructuredSelection) v.getSelection();
        if (!selection.isEmpty()) {
            Iterator i = selection.iterator();
            ICallerList list = getRuntime().getCallerFactory().createCallerList();
            ICallerList olist = getRuntime().getCallerFactory().createCallerList();
            Object o = null;
            while (i.hasNext()) {
                o = i.next();
                olist.add((ICaller) o);
                if (o instanceof IMultiPhoneCaller) {
                    list.add((IMultiPhoneCaller) o);
                } else if (o instanceof ICaller) {
                    list.add(getRuntime().getCallerFactory().toMultiPhoneCaller((ICaller) o));
                }
            }
            if (list.size() < 2)
                return;
            Display display = DisplayManager.getDefaultDisplay();
            Shell shell = new Shell(display);
            WizardDialog.setDefaultImage(SWTImageManager.getInstance(this.getRuntime()).get(IJAMConst.IMAGE_KEY_PIM_ICON));
            CallerCombineWizard callerWiz = new CallerCombineWizard(list);
            WizardDialog dlg = new WizardDialog(shell, callerWiz);
            dlg.open();
            if (dlg.getReturnCode() == WizardDialog.OK) {
                IMultiPhoneCaller c = callerWiz.getResult();
                if (c != null) {
                    // remove merged contact from olist
                    ICaller ca, rmc = null;
                    for (int j = olist.size() - 1; j >= 0; j--) {
                        ca = olist.get(j);
                        if (ca.getUUID().equalsIgnoreCase(c.getUUID())) {
                            rmc = ca;
                            m_logger.info("Merged user detected: " + rmc);
                        }
                    }
                    if (rmc != null)
                        olist.remove(rmc);
                    this.m_app.getController().deleteElements(olist);
                    this.m_app.getController().updateElement(c);
                    this.m_app.updateViews(true);
                }
            }
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) Shell(org.eclipse.swt.widgets.Shell) ICallerList(de.janrufmonitor.framework.ICallerList) Iterator(java.util.Iterator) Viewer(org.eclipse.jface.viewers.Viewer) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CallerCombineWizard(de.janrufmonitor.ui.jface.wizards.CallerCombineWizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog) Display(org.eclipse.swt.widgets.Display)

Aggregations

ICaller (de.janrufmonitor.framework.ICaller)144 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)62 ICallerList (de.janrufmonitor.framework.ICallerList)49 List (java.util.List)46 IAttribute (de.janrufmonitor.framework.IAttribute)42 ICall (de.janrufmonitor.framework.ICall)41 ArrayList (java.util.ArrayList)40 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)32 SQLException (java.sql.SQLException)26 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)25 IOException (java.io.IOException)25 Viewer (org.eclipse.jface.viewers.Viewer)24 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 File (java.io.File)20 Date (java.util.Date)17 Iterator (java.util.Iterator)17 Shell (org.eclipse.swt.widgets.Shell)17 IMsn (de.janrufmonitor.framework.IMsn)16 Properties (java.util.Properties)15 ICip (de.janrufmonitor.framework.ICip)14