Search in sources :

Example 76 with ICall

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

the class AbstractTellowsImg method renderAsImage.

public Image renderAsImage() {
    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) {
            if (((ICaller) this.m_o).getAttribute("tellows.scorePath") != null) {
                IAttribute timg = ((ICaller) this.m_o).getAttribute("tellows.scorePath");
                if (timg.getValue().length() > 0) {
                    try {
                        URL url = new URL(timg.getValue());
                        String tellowsImgName = new File(url.getFile()).getName();
                        File tellowsImgDir = new File(PathResolver.getInstance().getImageDirectory(), "tellows");
                        if (!tellowsImgDir.exists())
                            tellowsImgDir.mkdirs();
                        File tellowsImg = new File(tellowsImgDir, tellowsImgName);
                        if (!tellowsImg.exists()) {
                            URLConnection con = url.openConnection();
                            con.setRequestProperty("User-Agent", "jAnrufmonitor " + IJAMConst.VERSION_DISPLAY + " mit tellows Erweiterung");
                            con.connect();
                            Object o = con.getInputStream();
                            if (o instanceof InputStream) {
                                Stream.copy(new BufferedInputStream((InputStream) o), new FileOutputStream(tellowsImg), true);
                            }
                        }
                        if (tellowsImg.exists()) {
                            return this.getTellowsImage(new FileInputStream(tellowsImg));
                        }
                    } catch (MalformedURLException e) {
                    } catch (IOException e) {
                        Logger.getLogger(IJAMConst.DEFAULT_LOGGER).log(Level.WARNING, e.getLocalizedMessage(), e);
                    }
                }
            }
        }
    }
    return null;
}
Also used : MalformedURLException(java.net.MalformedURLException) ICall(de.janrufmonitor.framework.ICall) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection) FileInputStream(java.io.FileInputStream) ICaller(de.janrufmonitor.framework.ICaller) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) IAttribute(de.janrufmonitor.framework.IAttribute) File(java.io.File)

Example 77 with ICall

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

the class XlsFilter method doExport.

public boolean doExport() {
    if (m_filename == null || m_filename.length() == 0)
        return false;
    WritableWorkbook wb = null;
    try {
        wb = Workbook.createWorkbook(new File(m_filename));
        WritableSheet sheet = wb.createSheet("journal", 0);
        // get renderers
        List renderer = new ArrayList();
        String renderer_config = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty("ui.jface.application.journal.Journal", "renderer");
        if (renderer_config != null && renderer_config.length() > 0) {
            StringTokenizer s = new StringTokenizer(renderer_config, ",");
            while (s.hasMoreTokens()) {
                renderer.add(RendererRegistry.getInstance().getRenderer(s.nextToken()));
            }
        }
        ITableCellRenderer t = null;
        Label cell = null;
        for (int i = 0, j = renderer.size(); i < j; i++) {
            t = (ITableCellRenderer) renderer.get(i);
            if (t == null) {
                this.m_logger.severe("No renderer found for ID: " + (String) renderer.get(i));
                this.m_logger.severe("Export to XLS format canceled...");
                return false;
            }
            cell = new Label(i, 0, t.getHeader());
            sheet.addCell(cell);
        }
        int[] widths = new int[renderer.size()];
        ICall c = null;
        String cellContent = null;
        for (int k = 0, i = 0, j = this.m_callList.size(); i < j; i++) {
            try {
                c = this.m_callList.get(i);
                k = 0;
                for (int m = renderer.size(); k < m; k++) {
                    t = (ITableCellRenderer) renderer.get(k);
                    t.updateData(c);
                    cellContent = t.renderAsText();
                    if (cellContent != null && cellContent.length() > 0) {
                        widths[k] = Math.max(widths[k], cellContent.length());
                        cell = new Label(k, i + 1, cellContent);
                        sheet.addCell(cell);
                    } else {
                        cellContent = t.renderAsImageID();
                        if (cellContent != null && cellContent.length() > 0) {
                            if (cellContent.indexOf(".") > -1)
                                cellContent = cellContent.substring(0, cellContent.indexOf("."));
                            widths[k] = Math.max(widths[k], cellContent.length());
                            cell = new Label(k, i + 1, cellContent);
                        } else
                            cell = new Label(k, i + 1, " ");
                        sheet.addCell(cell);
                    }
                    cell = null;
                }
            } catch (JxlWriteException e) {
                this.m_logger.severe(e.getMessage());
                this.m_logger.severe("Ignored data [" + (k + 1) + ", " + (i + 1) + "] for Excel export: " + cellContent);
            }
        }
        // calculate width
        for (int i = 0, j = renderer.size(); i < j; i++) {
            sheet.setColumnView(i, widths[i]);
        }
        wb.write();
    } catch (Exception e) {
        this.m_logger.severe(e.getMessage());
        return false;
    } finally {
        try {
            if (wb != null)
                wb.close();
        } catch (WriteException ex) {
            this.m_logger.severe(ex.getMessage());
            return false;
        } catch (IOException ex) {
            this.m_logger.severe(ex.getMessage());
            return false;
        }
    }
    return true;
}
Also used : ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) WriteException(jxl.write.WriteException) JxlWriteException(jxl.write.biff.JxlWriteException) ICall(de.janrufmonitor.framework.ICall) ArrayList(java.util.ArrayList) Label(jxl.write.Label) WritableSheet(jxl.write.WritableSheet) IOException(java.io.IOException) IOException(java.io.IOException) WriteException(jxl.write.WriteException) JxlWriteException(jxl.write.biff.JxlWriteException) WritableWorkbook(jxl.write.WritableWorkbook) StringTokenizer(java.util.StringTokenizer) JxlWriteException(jxl.write.biff.JxlWriteException) ICallList(de.janrufmonitor.framework.ICallList) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 78 with ICall

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

the class DurationStatsAction method getStatisticItems.

public List getStatisticItems() {
    Properties stat = new Properties();
    if (this.m_cl != null) {
        String msn = null;
        ICall c = null;
        for (int i = 0; i < this.m_cl.size(); i++) {
            c = this.m_cl.get(i);
            msn = c.getMSN().getMSN();
            if (this.m_cl.get(i).getMSN().getAdditional().length() > 0) {
                msn += " (" + this.m_cl.get(i).getMSN().getAdditional() + ")";
            }
            String value = stat.getProperty(msn, "");
            if (value.length() == 0) {
                stat.setProperty(msn, Integer.toString(getDurationTime(c)));
                stat.setProperty(msn + ".string", getDuration(getDurationTime(c)));
            } else {
                int val = new Integer(value).intValue();
                val += getDurationTime(c);
                stat.setProperty(msn, new Integer(val).toString());
                stat.setProperty(msn + ".string", getDuration(val));
                m_maxcount = Math.max(m_maxcount, val);
            }
        }
    }
    Iterator iter = stat.keySet().iterator();
    List items = new ArrayList();
    String msn = null;
    while (iter.hasNext()) {
        msn = (String) iter.next();
        if (!msn.endsWith(".string")) {
            String count = stat.getProperty(msn, "");
            items.add(new String[] { msn, stat.getProperty(msn + ".string"), count });
        }
    }
    Collections.sort(items, new StatisticComparator());
    return items;
}
Also used : ICall(de.janrufmonitor.framework.ICall) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Properties(java.util.Properties)

Example 79 with ICall

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

the class DeleteAction method run.

public void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null && v instanceof TableViewer) {
        IStructuredSelection selection = (IStructuredSelection) v.getSelection();
        if (!selection.isEmpty()) {
            Iterator i = selection.iterator();
            ICallList list = getRuntime().getCallFactory().createCallList();
            Object o = null;
            while (i.hasNext()) {
                o = i.next();
                if (o instanceof ICall) {
                    list.add((ICall) o);
                }
            }
            if (list.size() > 0) {
                if (MessageDialog.openConfirm(new Shell(DisplayManager.getDefaultDisplay()), this.getI18nManager().getString(this.getNamespace(), "delete", "label", this.getLanguage()), this.getI18nManager().getString(this.getNamespace(), "delete", "description", this.getLanguage()))) {
                    this.m_app.getController().deleteElements(list);
                    this.m_app.getApplication().initializeController();
                    this.m_app.updateViews(true);
                }
            }
        }
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ICall(de.janrufmonitor.framework.ICall) ICallList(de.janrufmonitor.framework.ICallList) Iterator(java.util.Iterator) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 80 with ICall

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

the class HighlightAction method run.

public void run() {
    long m_timestamp = -1;
    try {
        m_timestamp = Long.parseLong(this.m_app.getApplication().getConfiguration().getProperty(CFG_HIGHLIGHT_TIME, "0"));
    } catch (Exception e) {
        this.m_logger.warning("Cannot parse long value: " + e.getMessage());
    }
    // highlight is disabled
    if (m_timestamp == -1)
        return;
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null && v instanceof TableViewer) {
        Table t = ((TableViewer) v).getTable();
        ICallList cl = ((JournalController) this.m_app.getController()).getCallList();
        ICall c = null;
        Font itemFont = null;
        for (int i = 0, n = cl.size(); i < n; i++) {
            c = cl.get(i);
            if (this.isHighlight(m_timestamp, c.getDate().getTime())) {
                itemFont = t.getItem(i).getFont();
                t.getItem(i).setFont(this.getBoldFont(itemFont));
            }
        }
        this.m_app.getApplication().getConfiguration().setProperty(CFG_HIGHLIGHT_TIME, Long.toString(System.currentTimeMillis()));
        this.m_app.getApplication().storeConfiguration();
    }
}
Also used : Table(org.eclipse.swt.widgets.Table) ICall(de.janrufmonitor.framework.ICall) ICallList(de.janrufmonitor.framework.ICallList) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) TableViewer(org.eclipse.jface.viewers.TableViewer) Font(org.eclipse.swt.graphics.Font) JournalController(de.janrufmonitor.ui.jface.application.journal.JournalController)

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