Search in sources :

Example 56 with IPhonenumber

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

the class AbstractFilterManager method getFiltersToLabelText.

public String getFiltersToLabelText(IFilter[] f, int shorten) {
    if (f != null && f.length > 0) {
        boolean processedCaller = false;
        StringBuffer sb = new StringBuffer();
        sb.append(this.getI18nManager().getString(this.getNamespace(), "view_limit", "label", this.getLanguage()));
        for (int i = 0; i < f.length; i++) {
            IFilter f1 = f[i];
            if (f1.getType().equals(FilterType.CIP)) {
                sb.append(this.getI18nManager().getString(this.getNamespace(), "view_cip", "label", this.getLanguage()));
                sb.append(this.getRuntime().getCipManager().getCipLabel(((CipFilter) f1).getCip(), this.getLanguage()));
                if ((i + 1) < f.length)
                    sb.append(", ");
            }
            if (f1.getType().equals(FilterType.MSN)) {
                sb.append(this.getI18nManager().getString(this.getNamespace(), "view_msn", "label", this.getLanguage()));
                IMsn[] m = ((MsnFilter) f1).getMsn();
                for (int k = 0, l = m.length; k < l; k++) {
                    sb.append(m[k].getMSN());
                    m[k].setAdditional(this.getRuntime().getMsnManager().getMsnLabel(m[k]));
                    if (m[k].getAdditional().length() > 0) {
                        sb.append(" (" + m[k].getAdditional() + ")");
                    }
                    if ((k + 1) < l)
                        sb.append(", ");
                }
                if ((i + 1) < f.length)
                    sb.append(", ");
            }
            if (f1.getType().equals(FilterType.DATE)) {
                sb.append(this.getI18nManager().getString(this.getNamespace(), "view_date", "label", this.getLanguage()));
                if (((DateFilter) f1).getTimeframe() == -1) {
                    Date d1 = ((DateFilter) f1).getDateFrom();
                    Date d2 = ((DateFilter) f1).getDateTo();
                    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
                    sb.append("[");
                    sb.append(sdf.format(d2));
                    sb.append(" - ");
                    if (d1 != null)
                        sb.append(sdf.format(d1));
                    else {
                        sb.append(this.getI18nManager().getString(this.getNamespace(), "today", "label", this.getLanguage()));
                    }
                    sb.append("]");
                    if ((i + 1) < f.length)
                        sb.append(", ");
                } else {
                    sb.append("[");
                    sb.append(this.getI18nManager().getString(this.getNamespace(), Long.toString(((DateFilter) f1).getTimeframe()), "label", this.getLanguage()));
                    sb.append("]");
                    if ((i + 1) < f.length)
                        sb.append(", ");
                }
            }
            if (f1.getType().equals(FilterType.YEAR)) {
                sb.append(this.getI18nManager().getString(this.getNamespace(), "view_date", "label", this.getLanguage()));
                sb.append("[");
                sb.append(((YearFilter) f1).getYear());
                sb.append("]");
                if ((i + 1) < f.length)
                    sb.append(", ");
            }
            if (f1.getType().equals(FilterType.MONTH_YEAR)) {
                sb.append(this.getI18nManager().getString(this.getNamespace(), "view_date", "label", this.getLanguage()));
                sb.append("[");
                sb.append(((MonthYearFilter) f1).getYear());
                sb.append(".");
                sb.append((((MonthYearFilter) f1).getMonth() > 9 ? ((MonthYearFilter) f1).getMonth() : "0" + ((MonthYearFilter) f1).getMonth()));
                sb.append("]");
                if ((i + 1) < f.length)
                    sb.append(", ");
            }
            if (f1.getType().equals(FilterType.CALLER) && !processedCaller) {
                sb.append(this.getI18nManager().getString(this.getNamespace(), "view_caller", "label", this.getLanguage()));
                if ((i + 1) < f.length && !processedCaller)
                    sb.append(", ");
                processedCaller = true;
            }
            if (f1.getType().equals(FilterType.PHONENUMBER)) {
                PhonenumberFilter cf = ((PhonenumberFilter) f1);
                IPhonenumber pnc = getRuntime().getCallerFactory().createPhonenumber(cf.getPhonenumber().getIntAreaCode(), cf.getPhonenumber().getAreaCode(), "0000000000");
                ICaller c = Identifier.identifyDefault(getRuntime(), pnc);
                if (c != null) {
                    IAttribute city = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CITY);
                    if (city != null && city.getValue().trim().length() > 0) {
                        sb.append(this.getI18nManager().getString(this.getNamespace(), "view_area", "label", this.getLanguage()).substring(2));
                        sb.append(city.getValue().trim());
                        sb.append(" (0");
                        sb.append(cf.getPhonenumber().getAreaCode());
                        sb.append(")");
                        if ((i + 1) < f.length)
                            sb.append(", ");
                        continue;
                    }
                }
                sb.append(this.getI18nManager().getString(this.getNamespace(), "view_intarea", "label", this.getLanguage()));
                sb.append("00" + cf.getPhonenumber().getIntAreaCode());
                if (cf.getPhonenumber().getAreaCode().trim().length() > 0) {
                    sb.append(this.getI18nManager().getString(this.getNamespace(), "view_area", "label", this.getLanguage()));
                    sb.append("0" + cf.getPhonenumber().getAreaCode().trim());
                }
                if ((i + 1) < f.length)
                    sb.append(", ");
            }
            if (f1.getType().equals(FilterType.ITEMCOUNT)) {
                ItemCountFilter cf = ((ItemCountFilter) f1);
                sb.append(this.getI18nManager().getString(this.getNamespace(), "view_itemcount", "label", this.getLanguage()));
                sb.append(cf.getLimit());
                if ((i + 1) < f.length)
                    sb.append(", ");
            }
            if (f1.getType().equals(FilterType.ATTRIBUTE)) {
                AttributeFilter cf = ((AttributeFilter) f1);
                IAttributeMap m = cf.getAttributeMap();
                if (m != null && m.size() > 0) {
                    Iterator it = m.iterator();
                    IAttribute a = null;
                    while (it.hasNext()) {
                        a = (IAttribute) it.next();
                        if (a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS)) {
                            sb.append(this.getI18nManager().getString(this.getNamespace(), a.getValue(), "label", this.getLanguage()));
                        } else if (a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
                            sb.append(this.getI18nManager().getString(this.getNamespace(), a.getName(), "label", this.getLanguage()));
                            sb.append(a.getValue());
                        } else {
                            sb.append(this.getI18nManager().getString(this.getNamespace(), a.getName(), "label", this.getLanguage()));
                        }
                        if (it.hasNext())
                            sb.append(", ");
                    }
                }
                if ((i + 1) < f.length)
                    sb.append(", ");
            }
            if (f1.getType().equals(FilterType.CHARACTER)) {
                CharacterFilter cf = ((CharacterFilter) f1);
                sb.append(this.getI18nManager().getString(this.getNamespace(), "view_" + cf.getAttributeName(), "label", this.getLanguage()));
                sb.append("[");
                sb.append(cf.getCharacter().toUpperCase());
                sb.append("...]");
                if ((i + 1) < f.length)
                    sb.append(", ");
            }
        }
        String s = sb.toString();
        if (s.trim().endsWith(","))
            s = s.trim().substring(0, s.trim().length() - 1);
        if (shorten > -1 && shorten < s.length()) {
            return s.substring(0, Math.min(shorten, s.length())) + "...";
        }
        if (s.trim().length() > 0)
            return s;
    }
    return this.getI18nManager().getString(this.getNamespace(), "view_all", "label", this.getLanguage());
}
Also used : CharacterFilter(de.janrufmonitor.repository.filter.CharacterFilter) CipFilter(de.janrufmonitor.repository.filter.CipFilter) Date(java.util.Date) ICaller(de.janrufmonitor.framework.ICaller) IFilter(de.janrufmonitor.repository.filter.IFilter) ItemCountFilter(de.janrufmonitor.repository.filter.ItemCountFilter) MsnFilter(de.janrufmonitor.repository.filter.MsnFilter) IAttribute(de.janrufmonitor.framework.IAttribute) AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) Iterator(java.util.Iterator) PhonenumberFilter(de.janrufmonitor.repository.filter.PhonenumberFilter) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IMsn(de.janrufmonitor.framework.IMsn) DateFilter(de.janrufmonitor.repository.filter.DateFilter) SimpleDateFormat(java.text.SimpleDateFormat) MonthYearFilter(de.janrufmonitor.repository.filter.MonthYearFilter) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 57 with IPhonenumber

use of de.janrufmonitor.framework.IPhonenumber 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 58 with IPhonenumber

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

the class TreeContentProvider method getChildren.

public Object[] getChildren(Object o) {
    if (o instanceof IMultiPhoneCaller) {
        List items = new ArrayList();
        List pns = ((IMultiPhoneCaller) o).getPhonenumbers();
        for (int i = 0, j = pns.size(); i < j; i++) {
            items.add(new TreeItemCallerData(((IMultiPhoneCaller) o), ((IMultiPhoneCaller) o).getAttributes(), (IPhonenumber) pns.get(i)));
        }
        if (items.size() > 1)
            items.remove(0);
        return items.toArray();
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) List(java.util.List) ArrayList(java.util.ArrayList) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 59 with IPhonenumber

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

the class ProviderLogo method renderAsImage.

public Image renderAsImage() {
    if (this.m_o != null) {
        if (this.m_o instanceof ICall) {
            this.m_o = ((ICall) this.m_o).getCaller().getPhoneNumber();
        }
        if (this.m_o instanceof ICaller) {
            this.m_o = ((ICaller) this.m_o).getPhoneNumber();
        }
        if (this.m_o instanceof ITreeItemCallerData) {
            this.m_o = ((ITreeItemCallerData) this.m_o).getPhone();
        }
        if (this.m_o instanceof IPhonenumber) {
            if (((IPhonenumber) this.m_o).isClired())
                return null;
            String key = "provider/" + ((IPhonenumber) this.m_o).getIntAreaCode() + "_" + ((IPhonenumber) this.m_o).getAreaCode() + ".jpg";
            File logoFile = new File(PathResolver.getInstance(PIMRuntime.getInstance()).getImageDirectory() + key);
            if (!logoFile.exists() || !logoFile.isFile()) {
                key = "provider/" + ((IPhonenumber) this.m_o).getIntAreaCode() + ".jpg";
                logoFile = new File(PathResolver.getInstance(PIMRuntime.getInstance()).getImageDirectory() + key);
                if (!logoFile.exists() || !logoFile.isFile())
                    return null;
            }
            Image logo = SWTImageManager.getInstance(PIMRuntime.getInstance()).get(key);
            if (logo == null) {
                SWTImageManager.getInstance(PIMRuntime.getInstance()).loadImage(key, 40, 40);
                logo = SWTImageManager.getInstance(PIMRuntime.getInstance()).get(key);
                return logo;
            }
            return logo;
        }
    }
    return null;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICall(de.janrufmonitor.framework.ICall) Image(org.eclipse.swt.graphics.Image) File(java.io.File) ITreeItemCallerData(de.janrufmonitor.ui.jface.application.ITreeItemCallerData) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 60 with IPhonenumber

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

the class NumberType method renderAsText.

public String renderAsText() {
    if (this.m_o != null) {
        if (this.m_o instanceof ICall) {
            this.m_o = ((ICall) this.m_o).getCaller();
        }
        if (this.m_o instanceof ICaller) {
            this.m_o = new TreeItemCallerData(((ICaller) this.m_o).getAttributes(), ((ICaller) this.m_o).getPhoneNumber());
        }
        if (this.m_o instanceof ITreeItemCallerData) {
            IAttributeMap m = ((ITreeItemCallerData) m_o).getAttributes();
            IPhonenumber pn = ((ITreeItemCallerData) m_o).getPhone();
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber())) {
                IAttribute type = m.get(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber());
                if (type != null) {
                    return PIMRuntime.getInstance().getI18nManagerFactory().getI18nManager().getString(NAMESPACE, type.getValue(), "label", getLanguage());
                }
            }
        }
    }
    return "";
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICall(de.janrufmonitor.framework.ICall) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ITreeItemCallerData(de.janrufmonitor.ui.jface.application.ITreeItemCallerData) ITreeItemCallerData(de.janrufmonitor.ui.jface.application.ITreeItemCallerData) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

IPhonenumber (de.janrufmonitor.framework.IPhonenumber)99 ICaller (de.janrufmonitor.framework.ICaller)62 List (java.util.List)49 ArrayList (java.util.ArrayList)44 IAttribute (de.janrufmonitor.framework.IAttribute)38 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)37 ICallerList (de.janrufmonitor.framework.ICallerList)36 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)26 ICall (de.janrufmonitor.framework.ICall)19 SQLException (java.sql.SQLException)19 IMsn (de.janrufmonitor.framework.IMsn)17 Date (java.util.Date)17 IOException (java.io.IOException)16 ICip (de.janrufmonitor.framework.ICip)13 IName (de.janrufmonitor.framework.IName)13 File (java.io.File)13 Iterator (java.util.Iterator)13 ITreeItemCallerData (de.janrufmonitor.ui.jface.application.ITreeItemCallerData)9 UUID (de.janrufmonitor.util.uuid.UUID)9 FileInputStream (java.io.FileInputStream)9