Search in sources :

Example 1 with ICommentCaller

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

the class PDFHistoryAction method run.

public void run() {
    FileDialog dialog = new FileDialog(new Shell(DisplayManager.getDefaultDisplay()), SWT.SAVE);
    dialog.setFilterExtensions(new String[] { "*.pdf" });
    dialog.setFilterNames(new String[] { getI18nManager().getString(getNamespace(), "pdffilter", "label", getLanguage()) });
    dialog.setText(getI18nManager().getString(getNamespace(), "pdf", "label", getLanguage()));
    String filename = dialog.open();
    if (filename != null && filename.length() > 0) {
        if (this.m_app.getApplication() instanceof Comment) {
            ICaller c = ((Comment) this.m_app.getApplication()).getCurrentCaller();
            IService srv = getRuntime().getServiceFactory().getService("CommentService");
            if (srv != null && srv instanceof CommentService) {
                CommentCallerHandler cch = ((CommentService) srv).getHandler();
                if (cch.hasCommentCaller(c)) {
                    ICommentCaller cc = cch.getCommentCaller(c);
                    try {
                        Class pdfclass = Thread.currentThread().getContextClassLoader().loadClass("de.janrufmonitor.ui.jface.application.comment.action.PDFCreator");
                        Constructor con = pdfclass.getConstructor(new Class[] { ICommentCaller.class, String.class });
                        Object pdfcreator = con.newInstance(new Object[] { cc, filename });
                        Method m = pdfclass.getMethod("createPdf", (Class) null);
                        m.invoke(pdfcreator, (Object) null);
                    } catch (ClassNotFoundException e) {
                        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                    } catch (SecurityException e) {
                        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                    } catch (NoSuchMethodException e) {
                        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                    } catch (IllegalArgumentException e) {
                        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                    } catch (InstantiationException e) {
                        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                    } catch (IllegalAccessException e) {
                        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                    } catch (InvocationTargetException e) {
                        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                    }
                }
            }
        }
    }
}
Also used : Comment(de.janrufmonitor.ui.jface.application.comment.Comment) ICommentCaller(de.janrufmonitor.service.comment.api.ICommentCaller) Constructor(java.lang.reflect.Constructor) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) ICaller(de.janrufmonitor.framework.ICaller) Shell(org.eclipse.swt.widgets.Shell) CommentService(de.janrufmonitor.service.comment.CommentService) CommentCallerHandler(de.janrufmonitor.service.comment.CommentCallerHandler) FileDialog(org.eclipse.swt.widgets.FileDialog) IService(de.janrufmonitor.service.IService)

Example 2 with ICommentCaller

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

use of de.janrufmonitor.service.comment.api.ICommentCaller 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)

Aggregations

ICommentCaller (de.janrufmonitor.service.comment.api.ICommentCaller)3 ICaller (de.janrufmonitor.framework.ICaller)2 IComment (de.janrufmonitor.service.comment.api.IComment)2 File (java.io.File)2 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)1 IService (de.janrufmonitor.service.IService)1 CommentCallerHandler (de.janrufmonitor.service.comment.CommentCallerHandler)1 CommentService (de.janrufmonitor.service.comment.CommentService)1 Comment (de.janrufmonitor.ui.jface.application.comment.Comment)1 FileFilter (java.io.FileFilter)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Date (java.util.Date)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 Shell (org.eclipse.swt.widgets.Shell)1