Search in sources :

Example 26 with ICall

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

the class CallingStatsAction method getStatisticItems.

public List getStatisticItems() {
    final List items = new ArrayList();
    ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
    try {
        IRunnableWithProgress r = new IRunnableWithProgress() {

            public void run(IProgressMonitor progressMonitor) {
                isCalculating = true;
                progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "calculating", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                progressMonitor.worked(1);
                final Properties stat = new Properties();
                if (m_cl != null) {
                    ICaller caller = null;
                    Formatter formatter = Formatter.getInstance(getRuntime());
                    ICall c = null;
                    for (int i = 0; i < m_cl.size(); i++) {
                        c = m_cl.get(i);
                        if (isOutgoingCall(c)) {
                            caller = c.getCaller();
                            String displayName = formatter.parse("%a:ln%, %a:fn% (%a:add%)", caller);
                            if (displayName.trim().length() == 0)
                                displayName = formatter.parse("%a:city%", caller);
                            String number = formatter.parse(IJAMConst.GLOBAL_VARIABLE_CALLERNUMBER, caller);
                            String key = number;
                            // remove CRLF
                            displayName = StringUtils.replaceString(displayName, IJAMConst.CRLF, " ");
                            if (displayName.length() > 32)
                                displayName = displayName.substring(0, 29) + "...";
                            String value = stat.getProperty(key, "");
                            if (value.length() == 0) {
                                stat.setProperty(key.trim(), "1");
                                stat.setProperty(key + ".name", displayName);
                                stat.setProperty(key + ".number", number);
                            } else {
                                int val = new Integer(value).intValue();
                                val++;
                                stat.setProperty(key.trim(), new Integer(val).toString());
                                m_maxcount = Math.max(m_maxcount, val);
                            }
                        }
                    }
                }
                progressMonitor.worked(1);
                progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "createstatistic", "label", getLanguage()));
                Iterator iter = stat.keySet().iterator();
                String key = null;
                String count = null;
                while (iter.hasNext()) {
                    key = (String) iter.next();
                    if (!(key.endsWith(".name") || key.endsWith(".number"))) {
                        count = stat.getProperty(key, "");
                        items.add(new String[] { stat.getProperty(key + ".name"), stat.getProperty(key + ".number"), count });
                    }
                }
                stat.clear();
                Collections.sort(items, new StatisticComparator());
                progressMonitor.done();
                isCalculating = false;
            }
        };
        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);
        isCalculating = false;
    } catch (InvocationTargetException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
        isCalculating = false;
    }
    while (isCalculating) try {
        Thread.sleep(250);
    } catch (InterruptedException e) {
    }
    return items;
}
Also used : ICall(de.janrufmonitor.framework.ICall) Formatter(de.janrufmonitor.util.formatter.Formatter) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) Properties(java.util.Properties) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ICaller(de.janrufmonitor.framework.ICaller) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 27 with ICall

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

the class DayTimeStatsAction method getStatisticItems.

public List getStatisticItems() {
    final List items = new ArrayList();
    ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
    try {
        IRunnableWithProgress r = new IRunnableWithProgress() {

            public void run(IProgressMonitor progressMonitor) {
                isCalculating = true;
                progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "calculating", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                progressMonitor.worked(1);
                final Properties stat = new Properties();
                for (int i = 0; i < 24; i++) stat.setProperty(getTimeFormat(i), "0");
                if (m_cl != null) {
                    ICall c = null;
                    Date d = null;
                    for (int i = 0; i < m_cl.size(); i++) {
                        c = m_cl.get(i);
                        d = c.getDate();
                        Calendar cal = Calendar.getInstance();
                        cal.setTime(d);
                        int hour = cal.get(Calendar.HOUR_OF_DAY);
                        int val = new Integer(stat.getProperty(getTimeFormat(hour), "0")).intValue();
                        val++;
                        stat.setProperty(getTimeFormat(hour), new Integer(val).toString());
                        m_maxcount = Math.max(m_maxcount, val);
                    }
                }
                progressMonitor.worked(1);
                progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "createstatistic", "label", getLanguage()));
                Iterator iter = stat.keySet().iterator();
                String key = null;
                String count = null;
                while (iter.hasNext()) {
                    key = (String) iter.next();
                    count = stat.getProperty(key, "");
                    items.add(new String[] { getI18nManager().getString(getNamespace(), key, "label", getLanguage()), count });
                }
                Collections.sort(items, new StatisticComparator());
                stat.clear();
                progressMonitor.done();
                isCalculating = false;
            }
        };
        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);
        isCalculating = false;
    } catch (InvocationTargetException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
        isCalculating = false;
    }
    while (isCalculating) try {
        Thread.sleep(550);
    } catch (InterruptedException e) {
    }
    return items;
}
Also used : ICall(de.janrufmonitor.framework.ICall) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Properties(java.util.Properties) Date(java.util.Date) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 28 with ICall

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

the class WeekTimeStatsAction method getStatisticItems.

public List getStatisticItems() {
    final List items = new ArrayList();
    ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
    try {
        IRunnableWithProgress r = new IRunnableWithProgress() {

            public void run(IProgressMonitor progressMonitor) {
                isCalculating = true;
                progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "calculating", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                progressMonitor.worked(1);
                final Properties stat = new Properties();
                if (m_cl != null) {
                    ICall c = null;
                    Date d = null;
                    for (int i = 0; i < m_cl.size(); i++) {
                        c = m_cl.get(i);
                        d = c.getDate();
                        Calendar cal = Calendar.getInstance();
                        cal.setTime(d);
                        int hour = cal.get(Calendar.DAY_OF_WEEK);
                        int val = new Integer(stat.getProperty(getDayFormat(hour), "0")).intValue();
                        val++;
                        stat.setProperty(getDayFormat(hour), new Integer(val).toString());
                        stat.setProperty(getDayFormat(hour) + ".sort", new Integer(hour).toString());
                        m_maxcount = Math.max(m_maxcount, val);
                    }
                }
                progressMonitor.worked(1);
                progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "createstatistic", "label", getLanguage()));
                Iterator iter = stat.keySet().iterator();
                String key = null;
                String count = null;
                while (iter.hasNext()) {
                    key = (String) iter.next();
                    if (!key.endsWith(".sort")) {
                        count = stat.getProperty(key, "");
                        items.add(new String[] { getI18nManager().getString(getNamespace(), key, "label", getLanguage()), count, stat.getProperty(key + ".sort") });
                    }
                }
                Collections.sort(items, new StatisticComparator());
                stat.clear();
                progressMonitor.done();
                isCalculating = false;
            }
        };
        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);
        isCalculating = false;
    } catch (InvocationTargetException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
        isCalculating = false;
    }
    while (isCalculating) try {
        Thread.sleep(550);
    } catch (InterruptedException e) {
    }
    return items;
}
Also used : ICall(de.janrufmonitor.framework.ICall) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Properties(java.util.Properties) Date(java.util.Date) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 29 with ICall

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

the class CallActive method renderAsImage.

public Image renderAsImage() {
    if (this.m_o != null) {
        if (this.m_o instanceof ICall) {
            ICall call = (ICall) this.m_o;
            IAttribute isCallActive = call.getAttribute(IJAMConst.ATTRIBUTE_NAME_CALL_ACTIVE_INDICATOR);
            if (isCallActive != null && isCallActive.getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_YES)) {
                IAttribute att = call.getAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS);
                if (att != null && att.getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_ACCEPTED)) {
                    return SWTImageManager.getInstance(PIMRuntime.getInstance()).get(IJAMConst.IMAGE_KEY_CALL_IN_ACTIVE_PNG);
                }
                if (att != null && att.getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_OUTGOING)) {
                    return SWTImageManager.getInstance(PIMRuntime.getInstance()).get(IJAMConst.IMAGE_KEY_CALL_OUT_ACTIVE_PNG);
                }
            }
            if (isCallActive != null && isCallActive.getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_NO)) {
                IAttribute att = call.getAttribute(IJAMConst.ATTRIBUTE_NAME_CALL_DURATION);
                if (att != null && att.getValue().length() > 0) {
                    try {
                        long duration_in_sec = Long.parseLong(att.getValue());
                        long start = call.getDate().getTime() / 1000;
                        long now = new java.util.Date().getTime() / 1000;
                        long passedTime = now - (start + duration_in_sec);
                        if (passedTime < 300) {
                            return SWTImageManager.getInstance(PIMRuntime.getInstance()).get(IJAMConst.IMAGE_KEY_CALL_END_5MIN_PNG);
                        }
                    } catch (Exception e) {
                    }
                }
            }
        }
    }
    return null;
}
Also used : ICall(de.janrufmonitor.framework.ICall) IAttribute(de.janrufmonitor.framework.IAttribute)

Example 30 with ICall

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

the class BChannel method renderAsImage.

public Image renderAsImage() {
    if (this.m_o != null) {
        if (this.m_o instanceof ICall) {
            ICall call = (ICall) this.m_o;
            IAttribute att = call.getAttribute(IJAMConst.ATTRIBUTE_NAME_BCHANNEL);
            if (att != null) {
                if (att.getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_B1))
                    return SWTImageManager.getInstance(PIMRuntime.getInstance()).get(IJAMConst.IMAGE_KEY_B1_JPG);
                if (att.getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_B2))
                    return SWTImageManager.getInstance(PIMRuntime.getInstance()).get(IJAMConst.IMAGE_KEY_B2_JPG);
            }
        }
    }
    return null;
}
Also used : ICall(de.janrufmonitor.framework.ICall) IAttribute(de.janrufmonitor.framework.IAttribute)

Aggregations

ICall (de.janrufmonitor.framework.ICall)89 ICaller (de.janrufmonitor.framework.ICaller)41 List (java.util.List)23 Viewer (org.eclipse.jface.viewers.Viewer)20 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)19 ArrayList (java.util.ArrayList)19 IAttribute (de.janrufmonitor.framework.IAttribute)18 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)18 ICallList (de.janrufmonitor.framework.ICallList)17 IOException (java.io.IOException)14 Properties (java.util.Properties)14 Date (java.util.Date)13 Iterator (java.util.Iterator)13 Shell (org.eclipse.swt.widgets.Shell)13 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)11 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)11 ICip (de.janrufmonitor.framework.ICip)10 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)10