Search in sources :

Example 6 with IComment

use of de.janrufmonitor.service.comment.api.IComment in project janrufmonitor by tbrandt77.

the class OldImportAction method doImport.

private synchronized void doImport(List fileList) {
    this.m_logger.info("Starting import of " + fileList.size() + " comments.");
    for (int i = 0; i < fileList.size(); i++) {
        File f = (File) fileList.get(i);
        String number = f.getName().substring(1, f.getName().indexOf("."));
        IPhonenumber pn = this.getRuntime().getCallerFactory().createPhonenumber(number);
        try {
            ICaller c = Identifier.identifyDefault(PIMRuntime.getInstance(), pn);
            ICommentCaller cc = null;
            if (this.getHandler().hasCommentCaller(c)) {
                cc = this.getHandler().getCommentCaller(c);
            } else {
                cc = this.getHandler().createCommentCaller(c);
            }
            IComment comment = this.getHandler().createComment();
            String content = this.getCommentContent(new FileInputStream(f));
            comment.setText(content);
            comment.setDate(new Date(f.lastModified()));
            cc.addComment(comment);
            this.getHandler().setCommentCaller(cc);
        } catch (FileNotFoundException e) {
            this.m_logger.severe(e.toString() + ": " + e.getMessage());
        } catch (IOException e) {
            this.m_logger.severe(e.toString() + ": " + e.getMessage());
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) IComment(de.janrufmonitor.service.comment.api.IComment) ICommentCaller(de.janrufmonitor.service.comment.api.ICommentCaller) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) Date(java.util.Date) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 7 with IComment

use of de.janrufmonitor.service.comment.api.IComment 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 8 with IComment

use of de.janrufmonitor.service.comment.api.IComment in project janrufmonitor by tbrandt77.

the class CommentCallerHandler method getCommentCallerFromHierarchy.

private ICommentCaller getCommentCallerFromHierarchy(ICaller caller) {
    String callerDirectoryName = this.getCommentRoot() + this.getCommentLocation(caller.getPhoneNumber());
    File callerDir = new File(callerDirectoryName);
    if (callerDir.exists()) {
        ICommentCaller commentCaller = this.createCommentCaller(caller);
        File[] comments = callerDir.listFiles(new FileFilter() {

            public boolean accept(File pathname) {
                if (pathname.getAbsolutePath().endsWith(getCommentFilenameExtension())) {
                    return true;
                }
                return false;
            }
        });
        for (int i = 0; i < comments.length; i++) {
            IComment comment = this.createComment(comments[i]);
            // TODO: removed due to performance reasons
            // File attachmentFolder = new File(callerDirectoryName + comment.getID());
            // if (attachmentFolder.exists()) {
            // File[] attachments = attachmentFolder.listFiles();
            // for (int j=0;j<attachments.length;j++) {
            // IAttachment attachment = this.createAttachment(attachments[j]);
            // comment.addAttachment(attachment);
            // }
            // }
            commentCaller.addComment(comment);
        }
        return commentCaller;
    }
    this.m_logger.info("Comments for caller " + caller.toString() + " does not exist.");
    return null;
}
Also used : IComment(de.janrufmonitor.service.comment.api.IComment) ICommentCaller(de.janrufmonitor.service.comment.api.ICommentCaller) FileFilter(java.io.FileFilter) File(java.io.File)

Example 9 with IComment

use of de.janrufmonitor.service.comment.api.IComment in project janrufmonitor by tbrandt77.

the class ChangeAction method run.

public void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null) {
        IStructuredSelection selection = (IStructuredSelection) v.getSelection();
        if (!selection.isEmpty()) {
            Object o = selection.getFirstElement();
            if (o instanceof IComment) {
                Object callableObject = null;
                if (this.m_app instanceof Comment) {
                    callableObject = ((Comment) this.m_app).getCallableObject();
                }
                CommentDialog cd = new CommentDialog(DisplayManager.getDefaultDisplay().getActiveShell(), ((IComment) o), callableObject);
                int result = cd.open();
                if (result == CommentDialog.OK) {
                    IComment c = cd.getResult();
                    this.m_app.getController().updateElement(c);
                    this.m_app.updateViews(true);
                }
            }
        }
    }
}
Also used : IComment(de.janrufmonitor.service.comment.api.IComment) Comment(de.janrufmonitor.ui.jface.application.comment.Comment) IComment(de.janrufmonitor.service.comment.api.IComment) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CommentDialog(de.janrufmonitor.ui.jface.dialogs.CommentDialog)

Aggregations

IComment (de.janrufmonitor.service.comment.api.IComment)9 File (java.io.File)5 IOException (java.io.IOException)5 FileNotFoundException (java.io.FileNotFoundException)4 IAttribute (de.janrufmonitor.framework.IAttribute)3 FileOutputStream (java.io.FileOutputStream)3 List (java.util.List)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 Viewer (org.eclipse.jface.viewers.Viewer)3 ICommentCaller (de.janrufmonitor.service.comment.api.ICommentCaller)2 Comment (de.janrufmonitor.ui.jface.application.comment.Comment)2 CommentDialog (de.janrufmonitor.ui.jface.dialogs.CommentDialog)2 FileFilter (java.io.FileFilter)2 FileInputStream (java.io.FileInputStream)2 Date (java.util.Date)2 Iterator (java.util.Iterator)2 Properties (java.util.Properties)2 Shell (org.eclipse.swt.widgets.Shell)2 Chunk (com.lowagie.text.Chunk)1 Document (com.lowagie.text.Document)1