Search in sources :

Example 1 with ICallerExporter

use of de.janrufmonitor.repository.imexport.ICallerExporter in project janrufmonitor by tbrandt77.

the class ExportAction method run.

public void run() {
    try {
        FileDialog dialog = new FileDialog(new Shell(DisplayManager.getDefaultDisplay()), SWT.SAVE);
        dialog.setText(this.getI18nManager().getString(this.getNamespace(), "title", "label", this.getLanguage()));
        List ids = ImExportFactory.getInstance().getAllExporterIds(IImExporter.CALLER_MODE);
        String[] filternames = new String[ids.size()];
        String[] extensions = new String[ids.size()];
        IImExporter ie = null;
        for (int i = 0; i < ids.size(); i++) {
            ie = ImExportFactory.getInstance().getExporter((String) ids.get(i));
            filternames[i] = ie.getFilterName();
            extensions[i] = ie.getExtension();
        }
        dialog.setFilterNames(filternames);
        dialog.setFilterExtensions(extensions);
        String filter = getRuntime().getConfigManagerFactory().getConfigManager().getProperty(getNamespace(), "lastopeneddir");
        if (filter == null || filter.length() == 0 || !new File(filter).exists())
            filter = PathResolver.getInstance(getRuntime()).getDataDirectory();
        dialog.setFilterPath(filter);
        final String filename = dialog.open();
        if (filename == null)
            return;
        filter = new File(filename).getParentFile().getAbsolutePath();
        getRuntime().getConfigManagerFactory().getConfigManager().setProperty(getNamespace(), "lastopeneddir", filter);
        String ext = "";
        for (int i = 0; i < ids.size(); i++) {
            final IImExporter exp = ImExportFactory.getInstance().getExporter((String) ids.get(i));
            ext = exp.getExtension().substring(1);
            if (filename.toLowerCase().endsWith(ext) && exp.getMode() == IImExporter.CALLER_MODE) {
                try {
                    ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
                    IRunnableWithProgress r = new IRunnableWithProgress() {

                        public void run(IProgressMonitor progressMonitor) {
                            progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "exportprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                            ((ICallerExporter) exp).setCallerList(((EditorController) m_app.getController()).getCallerList());
                            exp.setFilename(filename);
                            if (((ICallerExporter) exp).doExport()) {
                                progressMonitor.done();
                                PropagationFactory.getInstance().fire(new Message(Message.INFO, getI18nManager().getString(Editor.NAMESPACE, "title", "label", getLanguage()), new Exception(getI18nManager().getString(getNamespace(), "success", "description", getLanguage()))), "Tray");
                            } else {
                                progressMonitor.done();
                                new SWTExecuter() {

                                    protected void execute() {
                                        MessageDialog.openError(DisplayManager.getDefaultDisplay().getActiveShell(), getI18nManager().getString(getNamespace(), "error", "label", getLanguage()), getI18nManager().getString(getNamespace(), "error", "description", getLanguage()));
                                        m_logger.warning("Export of contacts failed.");
                                    }
                                }.start();
                            }
                        }
                    };
                    pmd.setBlockOnOpen(false);
                    pmd.run(true, false, r);
                } catch (InterruptedException e) {
                    throw e;
                } catch (InvocationTargetException e) {
                    throw e;
                }
            // m_app.updateViews(false);
            }
        }
    } catch (Exception ex) {
        this.m_logger.log(Level.SEVERE, ex.getMessage(), ex);
        PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "error", ex));
    }
}
Also used : Message(de.janrufmonitor.exception.Message) ICallerExporter(de.janrufmonitor.repository.imexport.ICallerExporter) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IImExporter(de.janrufmonitor.repository.imexport.IImExporter) List(java.util.List) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter)

Example 2 with ICallerExporter

use of de.janrufmonitor.repository.imexport.ICallerExporter in project janrufmonitor by tbrandt77.

the class SingleVcfExportAction method run.

public void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null && v instanceof Viewer) {
        final IStructuredSelection selection = (IStructuredSelection) v.getSelection();
        if (!selection.isEmpty()) {
            Iterator it = selection.iterator();
            final ICallerList list = this.getRuntime().getCallerFactory().createCallerList(selection.size());
            Object o = null;
            while (it.hasNext()) {
                o = it.next();
                if (o instanceof ICaller) {
                    list.add((ICaller) o);
                }
            }
            try {
                FileDialog dialog = new FileDialog(new Shell(DisplayManager.getDefaultDisplay()), SWT.SAVE);
                dialog.setText(this.getI18nManager().getString(this.getNamespace(), "title", "label", this.getLanguage()));
                if (list.size() == 1) {
                    dialog.setFileName(((ICaller) list.get(0)).getName().getFirstname() + " " + ((ICaller) list.get(0)).getName().getLastname());
                }
                if (ImExportFactory.getInstance().getExporter("VcfFileCallerExporter") == null)
                    return;
                List ids = new ArrayList();
                ids.add("VcfFileCallerExporter");
                String[] filternames = new String[ids.size()];
                String[] extensions = new String[ids.size()];
                IImExporter ie = null;
                for (int i = 0; i < ids.size(); i++) {
                    ie = ImExportFactory.getInstance().getExporter((String) ids.get(i));
                    filternames[i] = ie.getFilterName();
                    extensions[i] = ie.getExtension();
                }
                dialog.setFilterNames(filternames);
                dialog.setFilterExtensions(extensions);
                String filter = getRuntime().getConfigManagerFactory().getConfigManager().getProperty(getNamespace(), "lastopeneddir");
                if (filter == null || filter.length() == 0 || !new File(filter).exists())
                    filter = PathResolver.getInstance(getRuntime()).getDataDirectory();
                dialog.setFilterPath(filter);
                final String filename = dialog.open();
                if (filename == null)
                    return;
                filter = new File(filename).getParentFile().getAbsolutePath();
                getRuntime().getConfigManagerFactory().getConfigManager().setProperty(getNamespace(), "lastopeneddir", filter);
                String ext = "";
                for (int i = 0; i < ids.size(); i++) {
                    final IImExporter exp = ImExportFactory.getInstance().getExporter((String) ids.get(i));
                    ext = exp.getExtension().substring(1);
                    if (filename.toLowerCase().endsWith(ext) && exp.getMode() == IImExporter.CALLER_MODE) {
                        try {
                            ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
                            IRunnableWithProgress r = new IRunnableWithProgress() {

                                public void run(IProgressMonitor progressMonitor) {
                                    progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "exportprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                                    ((ICallerExporter) exp).setCallerList(list);
                                    exp.setFilename(filename);
                                    if (((ICallerExporter) exp).doExport()) {
                                        progressMonitor.done();
                                        PropagationFactory.getInstance().fire(new Message(Message.INFO, getI18nManager().getString(Editor.NAMESPACE, "title", "label", getLanguage()), new Exception(getI18nManager().getString(getNamespace(), "success", "description", getLanguage()))), "Tray");
                                    } else {
                                        progressMonitor.done();
                                        new SWTExecuter() {

                                            protected void execute() {
                                                MessageDialog.openError(DisplayManager.getDefaultDisplay().getActiveShell(), getI18nManager().getString(getNamespace(), "error", "label", getLanguage()), getI18nManager().getString(getNamespace(), "error", "description", getLanguage()));
                                                m_logger.warning("Export of contacts failed.");
                                            }
                                        }.start();
                                    }
                                }
                            };
                            pmd.setBlockOnOpen(false);
                            pmd.run(true, false, r);
                        } catch (InterruptedException e) {
                            throw e;
                        } catch (InvocationTargetException e) {
                            throw e;
                        }
                    // m_app.updateViews(false);
                    }
                }
            } catch (Exception ex) {
                this.m_logger.log(Level.SEVERE, ex.getMessage(), ex);
                PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "error", ex));
            }
        }
    }
}
Also used : Message(de.janrufmonitor.exception.Message) ICallerExporter(de.janrufmonitor.repository.imexport.ICallerExporter) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ICaller(de.janrufmonitor.framework.ICaller) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ICallerList(de.janrufmonitor.framework.ICallerList) IImExporter(de.janrufmonitor.repository.imexport.IImExporter) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter)

Aggregations

Message (de.janrufmonitor.exception.Message)2 ICallerExporter (de.janrufmonitor.repository.imexport.ICallerExporter)2 IImExporter (de.janrufmonitor.repository.imexport.IImExporter)2 SWTExecuter (de.janrufmonitor.ui.swt.SWTExecuter)2 File (java.io.File)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 List (java.util.List)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 FileDialog (org.eclipse.swt.widgets.FileDialog)2 Shell (org.eclipse.swt.widgets.Shell)2 ICaller (de.janrufmonitor.framework.ICaller)1 ICallerList (de.janrufmonitor.framework.ICallerList)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Viewer (org.eclipse.jface.viewers.Viewer)1