Search in sources :

Example 16 with ITableCellRenderer

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

the class Dialog method createContents.

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));
    Group g = new Group(composite, SWT.SHADOW_ETCHED_IN);
    g.setLayout(new GridLayout(2, false));
    Label date = new Label(g, SWT.NONE);
    date.setText(this.getI18nManager().getString(this.getNamespace(), "date_label", "label", this.getLanguage()) + this.getParsedDate());
    Font initialFont = date.getFont();
    FontData[] fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
        fontData[i].setHeight(this.getFontSize() - 3);
    }
    Font newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]);
    date.setFont(newFont);
    boolean hasCallerImage = this.hasCallerImage();
    Label image = new Label(g, SWT.BORDER | SWT.RIGHT);
    GridData gd = new GridData();
    gd.verticalSpan = 6;
    image.setVisible(false);
    if (hasCallerImage) {
        gd.widthHint = 92;
        gd.heightHint = 110;
        gd.horizontalIndent = 10;
        image.setVisible(true);
        image.setImage(this.getCallerImage());
    }
    image.setLayoutData(gd);
    Label msn = new Label(g, SWT.NONE);
    msn.setText(this.getI18nManager().getString(this.getNamespace(), "msn_label", "label", this.getLanguage()) + this.getParsedMsn());
    initialFont = msn.getFont();
    fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
        fontData[i].setHeight(this.getFontSize() - 3);
        fontData[i].setStyle(SWT.BOLD);
    }
    newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]);
    msn.setFont(newFont);
    Label callerLabel = new Label(g, SWT.NONE);
    callerLabel.setText(this.getI18nManager().getString(this.getNamespace(), "caller_label", "label", this.getLanguage()));
    initialFont = callerLabel.getFont();
    fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
        fontData[i].setHeight(this.getFontSize() - 3);
    }
    newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]);
    callerLabel.setFont(newFont);
    caller = new Label(g, SWT.WRAP);
    caller.setText(this.getParsedCaller());
    caller.setForeground(new Color(DisplayManager.getDefaultDisplay(), this.getColor()));
    initialFont = caller.getFont();
    fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
        fontData[i].setHeight(this.getFontSize());
        fontData[i].setStyle(SWT.BOLD);
    }
    newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]);
    caller.setFont(newFont);
    caller.pack();
    this.checkCallerLength(caller);
    caller.pack();
    // added 2008/04/08: add provider image if present
    Composite numberbar = new Composite(g, SWT.NONE);
    ITableCellRenderer tr = RendererRegistry.getInstance().getRenderer("ProviderLogo".toLowerCase());
    Image img = null;
    Label l = null;
    if (tr != null && this.m_call != null && !isCliredCaller()) {
        tr.updateData(this.m_call);
        img = tr.renderAsImage();
    }
    numberbar.setLayout(new GridLayout((img != null ? 2 : 1), false));
    if (img != null) {
        l = new Label(numberbar, SWT.LEFT);
        l.setImage(new Image(DisplayManager.getDefaultDisplay(), img.getImageData().scaledTo(32, 32)));
    }
    Label number = new Label(numberbar, SWT.NONE);
    number.setText(this.getParsedNumber());
    number.setForeground(new Color(DisplayManager.getDefaultDisplay(), this.getColor()));
    initialFont = number.getFont();
    fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
        fontData[i].setHeight(this.getFontSize() - 3);
        fontData[i].setStyle(SWT.BOLD);
    }
    newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]);
    number.setFont(newFont);
    new Label(g, SWT.NONE).setText(this.getParsedCip());
    // check for plugins
    List plugins = this.getPlugins(this.getConfiguration().getProperty("pluginlist", ""));
    Composite buttonbar = new Composite(composite, SWT.NONE);
    buttonbar.setLayout(new GridLayout(Math.max(4, (plugins.size() + 2)), false));
    // check for active reject service
    IService rejectService = this.getRuntime().getServiceFactory().getService("Reject");
    if (rejectService != null && rejectService.isEnabled()) {
        reject = new Button(buttonbar, SWT.PUSH);
        reject.setText(this.getI18nManager().getString(this.getNamespace(), "reject", "label", this.getLanguage()));
        reject.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                if (e.widget instanceof Button) {
                    reject.setEnabled(false);
                    IEventBroker eventBroker = getRuntime().getEventBroker();
                    if (getCall() != null)
                        getCall().setAttribute(getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_REJECTED));
                    eventBroker.send(Dialog.this, eventBroker.createEvent(IEventConst.EVENT_TYPE_CALLREJECTED, getCall()));
                }
            }
        });
    }
    // dialog close manually
    if (this.getShowTime() == -2) {
        Button close = new Button(buttonbar, SWT.PUSH);
        close.setText(this.getI18nManager().getString(this.getNamespace(), "close", "label", this.getLanguage()));
        close.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                if (e.widget instanceof Button) {
                    close();
                }
            }
        });
    }
    // name assign is active
    if (this.isAssignement() && !this.isCliredCaller()) {
        Button assign = new Button(buttonbar, SWT.PUSH);
        assign.setText(this.getI18nManager().getString(this.getNamespace(), "assign", "label", this.getLanguage()));
        assign.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                if (e.widget instanceof Button) {
                    Thread thread = new Thread() {

                        public void run() {
                            DisplayManager.getDefaultDisplay().asyncExec(new NameAssignDialog(getCaller()));
                        }
                    };
                    thread.setName(getID());
                    thread.start();
                }
            }
        });
    }
    // add plugins
    String classString = null;
    for (int i = 0, j = plugins.size(); i < j; i++) {
        classString = this.getConfiguration().getProperty((String) plugins.get(i));
        if (classString != null && classString.trim().length() > 0) {
            try {
                Class classObject = Thread.currentThread().getContextClassLoader().loadClass(classString);
                final IDialogPlugin plugin = (IDialogPlugin) classObject.newInstance();
                plugin.setDialog(this);
                plugin.setID((String) plugins.get(i));
                if (plugin.isEnabled()) {
                    Button button = new Button(buttonbar, SWT.PUSH);
                    button.setText(plugin.getLabel());
                    button.pack();
                    button.addSelectionListener(new SelectionAdapter() {

                        public void widgetSelected(SelectionEvent e) {
                            if (e.widget instanceof Button) {
                                plugin.run();
                            }
                        }
                    });
                }
            } catch (ClassNotFoundException e) {
                this.m_logger.warning("Class not found: " + classString);
            } catch (InstantiationException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            } catch (IllegalAccessException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
    }
    if (this.getShowTime() > 0) {
        Timer aTimer = new Timer();
        aTimer.schedule(new TimerTask() {

            public void run() {
                new SWTExecuter(getID()) {

                    protected void execute() {
                        close();
                    }
                }.start();
            }
        }, (long) ((this.getShowDuration() + 1) * 1000));
    }
    gd = new GridData();
    if (!hasCallerImage) {
        gd.widthHint = Math.max(350, this.caller.getBounds().width + 10);
    }
    g.setLayoutData(gd);
    parent.getShell().pack();
    return composite;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter) IService(de.janrufmonitor.service.IService) ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData)

Example 17 with ITableCellRenderer

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

the class PDFCreator method createPdf.

public void createPdf() {
    Document document = new Document(PageSize.A4);
    document.addCreationDate();
    document.addCreator("jAnrufmonitor");
    try {
        PdfWriter.getInstance(document, new FileOutputStream(this.m_file));
        document.open();
        document.add(new Paragraph(this.getI18nManager().getString(getNamespce(), "pdftitle", "label", getLanguage()), FontFactory.getFont(FontFactory.HELVETICA, 16f, Font.BOLD | Font.UNDERLINE)));
        document.add(new Paragraph(" "));
        String msg = "";
        ITableCellRenderer tcr = RendererRegistry.getInstance().getRenderer("name");
        if (tcr != null) {
            tcr.updateData(m_cc.getCaller());
            msg += tcr.renderAsText();
        }
        tcr = RendererRegistry.getInstance().getRenderer("number");
        if (tcr != null) {
            tcr.updateData(m_cc.getCaller());
            msg += "\n" + tcr.renderAsText() + "\n";
        }
        document.add(new Paragraph(msg));
        document.add(new Paragraph(" "));
        List comments = m_cc.getComments();
        Collections.sort(comments, new CommentComparator());
        IComment c = null;
        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(100f);
        PdfPCell cp = null;
        Paragraph pp = null;
        Color iterateColor1 = new Color(0xDD, 0xDD, 0xDD);
        Color iterateColor2 = new Color(0xFF, 0xFF, 0xFF);
        for (int i = 0; i < comments.size(); i++) {
            cp = new PdfPCell();
            cp.setBackgroundColor((i % 2 == 0 ? iterateColor1 : iterateColor2));
            pp = new Paragraph();
            Paragraph p = new Paragraph();
            c = (IComment) comments.get(i);
            IAttribute att = c.getAttributes().get(IComment.COMMENT_ATTRIBUTE_SUBJECT);
            if (att != null && att.getValue().length() > 0) {
                p.add(new Chunk(this.getI18nManager().getString(getNamespce(), "pdfsubject", "label", getLanguage()), FontFactory.getFont(FontFactory.HELVETICA, 14f, Font.BOLD)));
                p.add(new Chunk(att.getValue(), FontFactory.getFont(FontFactory.HELVETICA, 14f, Font.BOLD)));
                pp.add(p);
                p = new Paragraph();
            }
            p.add(new Chunk(this.getI18nManager().getString(getNamespce(), "pdfdate", "label", getLanguage()), FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.BOLD)));
            p.add(new Chunk(getFormatter().parse(IJAMConst.GLOBAL_VARIABLE_CALLTIME, c.getDate())));
            pp.add(p);
            p = new Paragraph();
            p.add(new Chunk(this.getI18nManager().getString(getNamespce(), "pdfstatus", "label", getLanguage()), FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.BOLD)));
            p.add(new Chunk(c.getAttributes().get(IComment.COMMENT_ATTRIBUTE_STATUS).getValue()));
            pp.add(p);
            att = c.getAttributes().get(IComment.COMMENT_ATTRIBUTE_FOLLOWUP);
            if (att != null && att.getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_YES)) {
                p = new Paragraph();
                Chunk cu = new Chunk(this.getI18nManager().getString(getNamespce(), "pdffollowup", "label", getLanguage()), FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.BOLD));
                cu.setBackground(new Color(0xFF, 0xFF, 0x00));
                p.add(cu);
                pp.add(p);
            }
            pp.add(new Paragraph(" "));
            p = new Paragraph(c.getText());
            pp.add(p);
            cp.addElement(pp);
            table.addCell(cp);
        }
        document.add(table);
    } catch (DocumentException de) {
        this.m_logger.severe(de.getMessage());
    } catch (IOException ioe) {
        this.m_logger.severe(ioe.getMessage());
    } finally {
        document.close();
    }
}
Also used : ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) IComment(de.janrufmonitor.service.comment.api.IComment) PdfPCell(com.lowagie.text.pdf.PdfPCell) Color(java.awt.Color) IOException(java.io.IOException) Document(com.lowagie.text.Document) Chunk(com.lowagie.text.Chunk) Paragraph(com.lowagie.text.Paragraph) PdfPTable(com.lowagie.text.pdf.PdfPTable) FileOutputStream(java.io.FileOutputStream) DocumentException(com.lowagie.text.DocumentException) IAttribute(de.janrufmonitor.framework.IAttribute) List(java.util.List)

Example 18 with ITableCellRenderer

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

the class Comment method addRenderBeforeTableHooks.

protected void addRenderBeforeTableHooks(Composite parent) {
    Composite view = new Composite(parent, SWT.NONE);
    view.setLayout(new GridLayout(2, false));
    Label l = new Label(view, SWT.NULL);
    l.setText("     ");
    l = new Label(view, SWT.NULL);
    l.setFont(this.getBoldFont(l.getFont()));
    String msg = "";
    ITableCellRenderer tcr = RendererRegistry.getInstance().getRenderer("name");
    if (tcr != null) {
        tcr.updateData(getCurrentCaller());
        msg += tcr.renderAsText();
    }
    tcr = RendererRegistry.getInstance().getRenderer("number");
    if (tcr != null) {
        tcr.updateData(getCurrentCaller());
        msg += "\n\n" + tcr.renderAsText() + "\n";
    }
    l.setText(msg);
}
Also used : ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label)

Example 19 with ITableCellRenderer

use of de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer 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)

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