Search in sources :

Example 6 with ITableCellRenderer

use of de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer in project janrufmonitor by tbrandt77.

the class ExtendedBalloonDialog method prepareDialog.

private void prepareDialog(Composite c, Shell s) {
    this.validConfiguration();
    ContentMatrix m = null;
    if (this.isCliredCaller()) {
        m = new ContentMatrix(getDialogContentCLIR());
    } else {
        m = new ContentMatrix(getDialogContent());
    }
    String[][] matrix = m.getMatrix();
    this.m_columnCount = m.getColCount(matrix);
    c.setLayout(new GridLayout(this.m_columnCount, false));
    int rowCount = m.getRowCount(matrix);
    int colCount = m.getColCount(matrix);
    for (int i = 0; i < rowCount; i++) {
        for (int j = 0; j < colCount; j++) {
            String element = (matrix[i][j].trim().length() > 0 ? matrix[i][j] : null);
            Image img = null;
            if (element != null) {
                ITableCellRenderer tcr = getRenderer(element);
                if (tcr != null) {
                    tcr.updateData(this.getCall());
                    img = tcr.renderAsImage();
                    if (img == null)
                        element = tcr.renderAsText();
                } else {
                    element = Formatter.getInstance(this.getRuntime()).parse(element, this.getCall());
                }
                if (element.equalsIgnoreCase(matrix[i][j]))
                    element = "";
            }
            createLabel(c, m.getRowSpan(j, i, matrix), element, img, getLabelAttributes(getElementID((matrix[i][j].trim().length() > 0 ? matrix[i][j] : null))));
        }
    }
}
Also used : ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) GridLayout(org.eclipse.swt.layout.GridLayout) Image(org.eclipse.swt.graphics.Image)

Example 7 with ITableCellRenderer

use of de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer in project janrufmonitor by tbrandt77.

the class ClipboardAction method run.

public void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null && v instanceof Viewer) {
        IStructuredSelection selection = (IStructuredSelection) v.getSelection();
        if (!selection.isEmpty()) {
            Object o = selection.getFirstElement();
            ITableCellRenderer tcr = RendererRegistry.getInstance().getRenderer("number");
            if (tcr != null) {
                tcr.updateData(o);
                Clipboard cb = new Clipboard(DisplayManager.getDefaultDisplay());
                String textData = tcr.renderAsText();
                TextTransfer textTransfer = TextTransfer.getInstance();
                cb.setContents(new Object[] { (textData != null ? textData : "") }, new Transfer[] { textTransfer });
            }
        }
    }
}
Also used : ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 8 with ITableCellRenderer

use of de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer in project janrufmonitor by tbrandt77.

the class ClipboardAddressAction method run.

public void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null && v instanceof Viewer) {
        IStructuredSelection selection = (IStructuredSelection) v.getSelection();
        if (!selection.isEmpty()) {
            Object o = selection.getFirstElement();
            ITableCellRenderer tcr = RendererRegistry.getInstance().getRenderer("name");
            if (tcr != null) {
                tcr.updateData(o);
                Clipboard cb = new Clipboard(DisplayManager.getDefaultDisplay());
                String textData = tcr.renderAsText();
                TextTransfer textTransfer = TextTransfer.getInstance();
                cb.setContents(new Object[] { (textData != null ? textData : "") }, new Transfer[] { textTransfer });
            }
        }
    }
}
Also used : ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 9 with ITableCellRenderer

use of de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer in project janrufmonitor by tbrandt77.

the class CsvFilter method doExport.

public boolean doExport() {
    if (m_filename == null || m_filename.length() == 0)
        return false;
    try {
        // 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;
        StringBuffer sb = new StringBuffer();
        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 CSV format canceled...");
                return false;
            }
            sb.append(t.getHeader());
            sb.append(TOKEN);
        }
        sb.append(IJAMConst.CRLF);
        ICall c = null;
        String cellContent = null;
        for (int i = 0, j = this.m_callList.size(); i < j; i++) {
            c = this.m_callList.get(i);
            for (int k = 0, m = renderer.size(); k < m; k++) {
                t = (ITableCellRenderer) renderer.get(k);
                t.updateData(c);
                cellContent = t.renderAsText();
                if (cellContent != null && cellContent.length() > 0) {
                    cellContent = StringUtils.replaceString(cellContent, IJAMConst.CRLF, " ");
                    sb.append(cellContent);
                    sb.append(TOKEN);
                } else {
                    cellContent = t.renderAsImageID();
                    if (cellContent != null && cellContent.length() > 0) {
                        if (cellContent.indexOf(".") > -1)
                            cellContent = cellContent.substring(0, cellContent.indexOf("."));
                    }
                    sb.append(cellContent);
                    sb.append(TOKEN);
                }
            }
            sb.append(IJAMConst.CRLF);
        }
        FileOutputStream fos = new FileOutputStream(m_filename);
        ByteArrayInputStream in = new ByteArrayInputStream(sb.toString().getBytes());
        Stream.copy(in, fos, true);
    } catch (Exception e) {
        this.m_logger.severe(e.getMessage());
        return false;
    } finally {
    }
    return true;
}
Also used : ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) StringTokenizer(java.util.StringTokenizer) ICall(de.janrufmonitor.framework.ICall) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) ICallList(de.janrufmonitor.framework.ICallList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with ITableCellRenderer

use of de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer in project janrufmonitor by tbrandt77.

the class PDFFilter method doExport.

public boolean doExport() {
    Document document = new Document(PageSize.A4.rotate(), 20, 20, 20, 20);
    document.addCreationDate();
    document.addCreator("jAnrufmonitor");
    try {
        PdfWriter.getInstance(document, new FileOutputStream(this.m_filename));
        document.open();
        // 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()));
            }
        }
        // get column width
        float totalWidth = 0;
        String[] cWidth = new String[renderer.size()];
        for (int i = 0, j = renderer.size(); i < j; i++) {
            cWidth[i] = getRuntime().getConfigManagerFactory().getConfigManager().getProperty("ui.jface.application.journal.Journal", "col_size_" + ((ITableCellRenderer) renderer.get(i)).getID());
            if (cWidth[i] != null && cWidth[i].length() > 0) {
                totalWidth += Float.parseFloat(cWidth[i]);
            }
            if (cWidth[i] != null && cWidth[i].length() == 0) {
                cWidth[i] = "0";
            }
        }
        float[] widths = new float[renderer.size()];
        for (int i = 0, j = renderer.size(); i < j; i++) {
            widths[i] = Float.parseFloat(cWidth[i]) / totalWidth;
        }
        PdfPTable table = new PdfPTable(widths);
        table.setHeaderRows(1);
        table.setWidthPercentage(100f);
        ITableCellRenderer t = null;
        PdfPCell 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 PDF format canceled...");
                return false;
            }
            cell = new PdfPCell(new Paragraph(t.getHeader()));
            cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
            table.addCell(cell);
        }
        ICall c = null;
        String cellContent = null;
        for (int i = 0, j = this.m_callList.size(); i < j; i++) {
            c = this.m_callList.get(i);
            for (int k = 0, m = renderer.size(); k < m; k++) {
                t = (ITableCellRenderer) renderer.get(k);
                t.updateData(c);
                cellContent = t.renderAsText();
                if (cellContent != null && cellContent.length() > 0) {
                    table.addCell(cellContent);
                } else {
                    cellContent = t.renderAsImageID();
                    if (cellContent != null && cellContent.length() > 0) {
                        try {
                            if (cellContent.startsWith("db://")) {
                                InputStream in = ImageHandler.getInstance().getImageStream(c.getCaller());
                                if (in != null) {
                                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                                    Stream.copy(in, out, true);
                                    in.close();
                                    out.close();
                                    Image pdfImage = Image.getInstance(out.toByteArray());
                                    // pdfImage.scaleAbsolute(90.0f, 45.0f);
                                    table.addCell(pdfImage);
                                } else {
                                    table.addCell(" ");
                                }
                            } else if (new File(cellContent).exists()) {
                                Image pdfImage = Image.getInstance(cellContent);
                                table.addCell(pdfImage);
                            } else {
                                Image pdfImage = Image.getInstance(SWTImageManager.getInstance(PIMRuntime.getInstance()).getImagePath(cellContent));
                                table.addCell(pdfImage);
                            }
                        } catch (IOException e) {
                            this.m_logger.severe(e.getMessage());
                            table.addCell(" ");
                        }
                    } else
                        table.addCell(" ");
                }
            }
        }
        document.add(table);
    } catch (DocumentException de) {
        this.m_logger.severe(de.getMessage());
        return false;
    } catch (IOException ioe) {
        this.m_logger.severe(ioe.getMessage());
        return false;
    } finally {
        document.close();
    }
    return true;
}
Also used : ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) PdfPCell(com.lowagie.text.pdf.PdfPCell) ICall(de.janrufmonitor.framework.ICall) InputStream(java.io.InputStream) Color(java.awt.Color) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Document(com.lowagie.text.Document) Image(com.lowagie.text.Image) Paragraph(com.lowagie.text.Paragraph) StringTokenizer(java.util.StringTokenizer) PdfPTable(com.lowagie.text.pdf.PdfPTable) FileOutputStream(java.io.FileOutputStream) DocumentException(com.lowagie.text.DocumentException) ICallList(de.janrufmonitor.framework.ICallList) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Aggregations

ITableCellRenderer (de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer)19 List (java.util.List)8 ArrayList (java.util.ArrayList)5 ICall (de.janrufmonitor.framework.ICall)4 FileOutputStream (java.io.FileOutputStream)4 IOException (java.io.IOException)4 StringTokenizer (java.util.StringTokenizer)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 Document (com.lowagie.text.Document)3 DocumentException (com.lowagie.text.DocumentException)3 Paragraph (com.lowagie.text.Paragraph)3 PdfPCell (com.lowagie.text.pdf.PdfPCell)3 PdfPTable (com.lowagie.text.pdf.PdfPTable)3 ICallList (de.janrufmonitor.framework.ICallList)3 Color (java.awt.Color)3 File (java.io.File)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 Viewer (org.eclipse.jface.viewers.Viewer)3 Clipboard (org.eclipse.swt.dnd.Clipboard)3 TextTransfer (org.eclipse.swt.dnd.TextTransfer)3