Search in sources :

Example 21 with SWTExecuter

use of de.janrufmonitor.ui.swt.SWTExecuter 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.CALL_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()).getUserDataDirectory();
        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.endsWith(ext) && exp.getMode() == IImExporter.CALL_MODE) {
                ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
                try {
                    IRunnableWithProgress r = new IRunnableWithProgress() {

                        public void run(IProgressMonitor progressMonitor) {
                            progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "exportprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                            progressMonitor.worked(1);
                            ((ICallExporter) exp).setCallList(((JournalController) m_app.getController()).getCallList());
                            exp.setFilename(filename);
                            if (((ICallExporter) exp).doExport()) {
                                progressMonitor.done();
                                PropagationFactory.getInstance().fire(new Message(Message.INFO, getI18nManager().getString(Journal.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 journal failed.");
                                    }
                                }.start();
                            }
                            progressMonitor.done();
                        }
                    };
                    pmd.setBlockOnOpen(false);
                    pmd.run(true, false, r);
                // ModalContext.run(r, true, pmd.getProgressMonitor(), DisplayManager.getDefaultDisplay());
                } 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 : ICallExporter(de.janrufmonitor.repository.imexport.ICallExporter) Message(de.janrufmonitor.exception.Message) 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 22 with SWTExecuter

use of de.janrufmonitor.ui.swt.SWTExecuter in project janrufmonitor by tbrandt77.

the class ImportAction method run.

public void run(String[] filenames) {
    try {
        String filename = filenames[0];
        TableViewer viewer = (TableViewer) this.m_app.getApplication().getViewer();
        Cursor c = new Cursor(viewer.getTable().getDisplay(), SWT.CURSOR_WAIT);
        if (!filename.endsWith(this.m_app.getApplication().getConfiguration().getProperty(CFG_OLD_JOURNAL, "ajournal.dat"))) {
            File f = new File(filename);
            String ext = f.getName();
            IImExporter ie = ImExportFactory.getInstance().getImporterByExtension(ext);
            if (ie == null && ext.lastIndexOf(".") >= 0) {
                ext = "*" + ext.substring(ext.lastIndexOf("."));
                ie = ImExportFactory.getInstance().getImporterByExtension(ext);
                if (ie == null) {
                    PropagationFactory.getInstance().fire(new Message(Message.ERROR, getI18nManager().getString(Journal.NAMESPACE, "title", "label", getLanguage()), new Exception(getI18nManager().getString(getNamespace(), "error", "description", getLanguage()))), "Tray");
                    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("Import of data failed.");
                        }
                    }.start();
                }
            }
            if (ie != null && ie.getMode() != IImExporter.CALL_MODE)
                return;
            final IImExporter imp = ie;
            imp.setFilename(filename);
            viewer.getTable().getShell().setCursor(c);
            ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
            try {
                IRunnableWithProgress r = new IRunnableWithProgress() {

                    public void run(IProgressMonitor progressMonitor) {
                        progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "importprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                        progressMonitor.worked(1);
                        final ICallList importedCalls = getRuntime().getCallFactory().createCallList();
                        if (imp.getMode() == IImExporter.CALL_MODE) {
                            importedCalls.add(((ICallImporter) imp).doImport());
                            m_app.getController().addElements(importedCalls);
                        }
                        if (importedCalls.size() > 0) {
                            final String msg = StringUtils.replaceString(getI18nManager().getString(getNamespace(), "success", "description", getLanguage()), "{%1}", Integer.toString(importedCalls.size()));
                            PropagationFactory.getInstance().fire(new Message(Message.INFO, getI18nManager().getString(Journal.NAMESPACE, "title", "label", getLanguage()), new Exception(msg)), "Tray");
                            new SWTExecuter() {

                                protected void execute() {
                                    m_app.updateViews(true);
                                }
                            }.start();
                        } else {
                            PropagationFactory.getInstance().fire(new Message(Message.ERROR, getI18nManager().getString(Journal.NAMESPACE, "title", "label", getLanguage()), new Exception(getI18nManager().getString(getNamespace(), "error", "description", getLanguage()))), "Tray");
                            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("Import of data failed.");
                                    // m_app.getController().addElements(importedCalls);
                                    m_app.updateViews(true);
                                }
                            }.start();
                        }
                        progressMonitor.done();
                    }
                };
                pmd.setBlockOnOpen(false);
                pmd.run(true, false, r);
            // ModalContext.run(r, true,
            // pmd.getProgressMonitor(),
            // DisplayManager.getDefaultDisplay());
            } catch (InterruptedException e) {
                throw e;
            } catch (InvocationTargetException e) {
                throw e;
            }
            viewer.getTable().getShell().setCursor(null);
            c.dispose();
        } else {
            // do ajournal.dat migration
            int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
            MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
            messageBox.setMessage(this.getI18nManager().getString(this.getNamespace(), "migrationconfirm", "label", this.getLanguage()));
            if (messageBox.open() == SWT.YES) {
                viewer.getTable().getShell().setCursor(c);
                IImExporter imp = ImExportFactory.getInstance().getImporter("OldDatFileCallImporter");
                if (imp != null && (imp instanceof OldDatFileCallImporter)) {
                    ((OldDatFileCallImporter) imp).setDatePattern(this.m_app.getApplication().getConfiguration().getProperty(CFG_OLD_DATE, "dd.MM.yyyy HH:mm:ss"));
                    ((OldDatFileCallImporter) imp).setFilename(filename);
                    ICallList importedCalls = ((OldDatFileCallImporter) imp).doImport();
                    if (importedCalls != null) {
                        this.m_app.getController().addElements(importedCalls);
                        String msg = getI18nManager().getString(getNamespace(), "success", "description", getLanguage());
                        msg = StringUtils.replaceString(msg, "{%1}", Integer.toString(importedCalls.size()));
                        if (!suppressDialogs)
                            MessageDialog.openInformation(new Shell(DisplayManager.getDefaultDisplay()), getI18nManager().getString(getNamespace(), "success", "label", getLanguage()), msg);
                        m_app.updateViews(true);
                    }
                }
                viewer.getTable().getShell().setCursor(null);
                c.dispose();
            } else {
                return;
            }
        }
    } 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) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) OldDatFileCallImporter(de.janrufmonitor.repository.imexporter.OldDatFileCallImporter) Cursor(org.eclipse.swt.graphics.Cursor) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) MessageBox(org.eclipse.swt.widgets.MessageBox) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Shell(org.eclipse.swt.widgets.Shell) ICallList(de.janrufmonitor.framework.ICallList) IImExporter(de.janrufmonitor.repository.imexport.IImExporter) TableViewer(org.eclipse.jface.viewers.TableViewer) File(java.io.File) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter)

Example 23 with SWTExecuter

use of de.janrufmonitor.ui.swt.SWTExecuter in project janrufmonitor by tbrandt77.

the class AssignAction method run.

public void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null && v instanceof TableViewer) {
        IStructuredSelection selection = (IStructuredSelection) v.getSelection();
        if (!selection.isEmpty()) {
            final ICall call = (ICall) selection.getFirstElement();
            ICaller caller = call.getCaller();
            final ICaller newCaller = openCallerWizard(caller);
            if (newCaller != null) {
                int l_status = SWT.NO;
                if (!newCaller.getPhoneNumber().isClired()) {
                    int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
                    MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
                    messageBox.setMessage(getI18nManager().getString(getNamespace(), "setall", "label", getLanguage()));
                    l_status = messageBox.open();
                }
                final int status = l_status;
                ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
                try {
                    IRunnableWithProgress r = new IRunnableWithProgress() {

                        public void run(IProgressMonitor progressMonitor) {
                            progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "assignprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                            progressMonitor.worked(1);
                            call.setCaller(newCaller);
                            if (status == SWT.NO && m_app.getController() instanceof IExtendedApplicationController) {
                                // added 2009/12/31: only update single entry
                                progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "assignprogress", "label", getLanguage()));
                                ((IExtendedApplicationController) m_app.getController()).updateElement(call, false);
                            } else {
                                progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "assignall", "label", getLanguage()));
                                m_app.getController().updateElement(call);
                            }
                            progressMonitor.done();
                        }
                    };
                    pmd.setBlockOnOpen(false);
                    pmd.run(true, false, r);
                // ModalContext.run(r, true, pmd.getProgressMonitor(),
                // DisplayManager.getDefaultDisplay());
                } catch (InterruptedException e) {
                    m_logger.log(Level.SEVERE, e.getMessage(), e);
                } catch (InvocationTargetException e) {
                    m_logger.log(Level.SEVERE, e.getMessage(), e);
                }
                if (!newCaller.getPhoneNumber().isClired()) {
                    new SWTExecuter() {

                        protected void execute() {
                            int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
                            MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
                            messageBox.setMessage(getI18nManager().getString(getNamespace(), "addressbookconfirm", "label", getLanguage()));
                            if (messageBox.open() == SWT.YES) {
                                List cpms = getRuntime().getCallerManagerFactory().getTypedCallerManagers(IWriteCallerRepository.class);
                                ICallerManager cmgr = null;
                                for (int i = 0; i < cpms.size(); i++) {
                                    cmgr = (ICallerManager) cpms.get(i);
                                    if (cmgr.isActive() && cmgr.isSupported(IWriteCallerRepository.class))
                                        ((IWriteCallerRepository) cmgr).updateCaller(newCaller);
                                }
                            }
                            m_app.updateViews(true);
                        }
                    }.start();
                } else {
                    m_app.updateViews(true);
                }
            // this.m_app.updateViews(true);
            }
        }
    }
}
Also used : ICall(de.janrufmonitor.framework.ICall) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InvocationTargetException(java.lang.reflect.InvocationTargetException) ICallerManager(de.janrufmonitor.repository.ICallerManager) MessageBox(org.eclipse.swt.widgets.MessageBox) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ICaller(de.janrufmonitor.framework.ICaller) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWriteCallerRepository(de.janrufmonitor.repository.types.IWriteCallerRepository) IExtendedApplicationController(de.janrufmonitor.ui.jface.application.IExtendedApplicationController) List(java.util.List) TableViewer(org.eclipse.jface.viewers.TableViewer) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter)

Example 24 with SWTExecuter

use of de.janrufmonitor.ui.swt.SWTExecuter in project janrufmonitor by tbrandt77.

the class ReIdentifyAction method run.

public void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null && v instanceof TableViewer) {
        IStructuredSelection selection = (IStructuredSelection) v.getSelection();
        if (!selection.isEmpty()) {
            final ICall call = (ICall) selection.getFirstElement();
            ICaller caller = call.getCaller();
            if (caller.getPhoneNumber().isClired()) {
                new SWTExecuter() {

                    protected void execute() {
                        int style = SWT.APPLICATION_MODAL | SWT.OK;
                        MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
                        messageBox.setMessage(getI18nManager().getString(getNamespace(), "clir", "label", getLanguage()));
                        messageBox.open();
                    }
                }.start();
                return;
            }
            List cms = getAllActiveCallerManagers(getRuntime());
            if (cms.size() == 0) {
                new SWTExecuter() {

                    protected void execute() {
                        int style = SWT.APPLICATION_MODAL | SWT.OK;
                        MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
                        messageBox.setMessage(getI18nManager().getString(getNamespace(), "nocms", "label", getLanguage()));
                        messageBox.open();
                    }
                }.start();
                return;
            }
            caller = Identifier.identify(getRuntime(), caller.getPhoneNumber(), cms);
            if (caller == null) {
                new SWTExecuter() {

                    protected void execute() {
                        int style = SWT.APPLICATION_MODAL | SWT.OK;
                        MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
                        messageBox.setMessage(getI18nManager().getString(getNamespace(), "notidentified", "label", getLanguage()));
                        messageBox.open();
                    }
                }.start();
                return;
            }
            final ICaller newCaller = openCallerWizard(caller);
            if (newCaller != null) {
                int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
                MessageBox messageBox = new MessageBox(DisplayManager.getDefaultDisplay().getActiveShell(), style);
                messageBox.setMessage(getI18nManager().getString(getNamespace(), "setall", "label", getLanguage()));
                final int status = messageBox.open();
                ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
                try {
                    IRunnableWithProgress r = new IRunnableWithProgress() {

                        public void run(IProgressMonitor progressMonitor) {
                            progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "assignprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                            progressMonitor.worked(1);
                            call.setCaller(newCaller);
                            processModifierServices(call);
                            if (status == SWT.NO && m_app.getController() instanceof IExtendedApplicationController) {
                                // added 2009/12/31: only update single entry
                                progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "assignprogress", "label", getLanguage()));
                                ((IExtendedApplicationController) m_app.getController()).updateElement(call, false);
                            } else {
                                progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "assignall", "label", getLanguage()));
                                m_app.getController().updateElement(call);
                            }
                            progressMonitor.done();
                        }
                    };
                    pmd.setBlockOnOpen(false);
                    pmd.run(true, false, r);
                // ModalContext.run(r, true, pmd.getProgressMonitor(),
                // DisplayManager.getDefaultDisplay());
                } catch (InterruptedException e) {
                    m_logger.log(Level.SEVERE, e.getMessage(), e);
                } catch (InvocationTargetException e) {
                    m_logger.log(Level.SEVERE, e.getMessage(), e);
                }
                this.m_app.updateViews(true);
            }
        }
    }
}
Also used : ICall(de.janrufmonitor.framework.ICall) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InvocationTargetException(java.lang.reflect.InvocationTargetException) MessageBox(org.eclipse.swt.widgets.MessageBox) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ICaller(de.janrufmonitor.framework.ICaller) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayList(java.util.ArrayList) List(java.util.List) IExtendedApplicationController(de.janrufmonitor.ui.jface.application.IExtendedApplicationController) TableViewer(org.eclipse.jface.viewers.TableViewer) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter)

Aggregations

SWTExecuter (de.janrufmonitor.ui.swt.SWTExecuter)24 Shell (org.eclipse.swt.widgets.Shell)14 InvocationTargetException (java.lang.reflect.InvocationTargetException)11 List (java.util.List)11 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)11 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)11 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)11 Message (de.janrufmonitor.exception.Message)9 ICaller (de.janrufmonitor.framework.ICaller)8 ArrayList (java.util.ArrayList)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 ICall (de.janrufmonitor.framework.ICall)6 File (java.io.File)6 Viewer (org.eclipse.jface.viewers.Viewer)6 MessageBox (org.eclipse.swt.widgets.MessageBox)6 IImExporter (de.janrufmonitor.repository.imexport.IImExporter)5 ITracker (de.janrufmonitor.repository.imexport.ITracker)4 Iterator (java.util.Iterator)4 ICallerList (de.janrufmonitor.framework.ICallerList)3 FirmwareManager (de.janrufmonitor.fritzbox.firmware.FirmwareManager)3