Search in sources :

Example 1 with SWTExecuter

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

the class IsdnMoniCallImporter method doImport.

public ICallList doImport() {
    this.m_callerList = null;
    boolean doNotShowmessage = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty(this.getNamespace(), CFG_SHOW_ENTRY_WARNING).equalsIgnoreCase("true");
    if (!doNotShowmessage) {
        new SWTExecuter() {

            protected void execute() {
                String message = getI18nManager().getString(getNamespace(), "message", "description", getLanguage());
                MessageDialogWithToggle d = MessageDialogWithToggle.openYesNoQuestion(new Shell(DisplayManager.getDefaultDisplay()), getI18nManager().getString(getNamespace(), "message", "label", getLanguage()), message, getI18nManager().getString(getNamespace(), "confirmmessage", "label", getLanguage()), false, null, null);
                if (d.getReturnCode() == 2) {
                    m_callerList = getRuntime().getCallerFactory().createCallerList();
                }
                getRuntime().getConfigManagerFactory().getConfigManager().setProperty(getNamespace(), CFG_SHOW_ENTRY_WARNING, (d.getToggleState() ? "true" : "false"));
                getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
                isDialogFinished = true;
            }
        }.start();
    } else {
        isDialogFinished = true;
    }
    while (!isDialogFinished) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
        }
    }
    Date startDate = new Date();
    File db = new File(m_filename);
    int size = (int) db.length() / 64;
    size = Math.abs(size);
    ThreadGroup g = new ThreadGroup("JAM- HeuerMigrator-ThreadGroup");
    m_callList = getRuntime().getCallFactory().createCallList(size);
    m_pnList = new ArrayList(size);
    try {
        FileReader dbReader = new FileReader(db);
        BufferedReader bufReader = new BufferedReader(dbReader);
        int i = 0;
        while (bufReader.ready()) {
            String line = bufReader.readLine();
            if (line.indexOf("->") > 0) {
                try {
                    Thread t = new Thread(g, new MigratorThread(this.m_callList, (this.m_callerList != null ? this.m_callerList : null), line, this.m_pnList));
                    t.setName("JAM-HeuerMigrator#" + (i++) + "-Thread-(non-deamon)");
                    t.start();
                    if (g.activeCount() > 100) {
                        Thread.sleep(1000);
                    }
                } catch (Exception ex) {
                    this.m_logger.severe("Unexpected error during migration: " + ex);
                }
            }
        }
        bufReader.close();
        dbReader.close();
    } catch (FileNotFoundException ex) {
        this.m_logger.warning("Cannot find call backup file " + m_filename);
        return this.m_callList;
    } catch (IOException ex) {
        this.m_logger.severe("IOException on file " + m_filename);
        return this.m_callList;
    }
    while (g.activeCount() > 0) {
        try {
            Thread.sleep(1000);
            this.m_logger.info("Waiting for " + g.activeCount() + " Migrator threads.");
        } catch (InterruptedException e) {
            this.m_logger.severe(e.getMessage());
        }
    }
    if (this.m_callerList != null) {
        this.m_logger.info("Commiting detected callers to default caller manager.");
        String cm = getRuntime().getConfigManagerFactory().getConfigManager().getProperty("ui.jface.application.editor.Editor", "repository");
        ICallerManager cmg = this.getRuntime().getCallerManagerFactory().getCallerManager(cm);
        if (cmg != null && cmg.isActive() && cmg.isSupported(IWriteCallerRepository.class)) {
            ((IWriteCallerRepository) cmg).setCaller(this.m_callerList);
        }
    }
    Date endDate = new Date();
    this.m_logger.info("Successfully imported call file " + m_filename);
    this.m_logger.info("Found " + new Integer(this.m_callList.size()).toString() + " call items in " + new Float((endDate.getTime() - startDate.getTime()) / 1000).toString() + " secs.");
    return m_callList;
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Date(java.util.Date) ParseException(java.text.ParseException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ICallerManager(de.janrufmonitor.repository.ICallerManager) Shell(org.eclipse.swt.widgets.Shell) IWriteCallerRepository(de.janrufmonitor.repository.types.IWriteCallerRepository) BufferedReader(java.io.BufferedReader) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) FileReader(java.io.FileReader) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter) File(java.io.File)

Example 2 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.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 3 with SWTExecuter

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

the class TrayIcon method startup.

public void startup() {
    super.startup();
    // register as a receiver
    this.getRuntime().getEventBroker().register(this, this.getRuntime().getEventBroker().createEvent(IEventConst.EVENT_TYPE_IDENTIFIED_CALL));
    this.getRuntime().getEventBroker().register(this, this.getRuntime().getEventBroker().createEvent(IEventConst.EVENT_TYPE_APPLICATION_READY));
    this.m_iconPool = new HashMap();
    new SWTExecuter(this.getID()) {

        protected void execute() {
            m_logger.info("Creating new tray ...");
            createTray();
            // set default wizard icons
            WizardDialog.setDefaultImage(SWTImageManager.getInstance(getRuntime()).get(IJAMConst.IMAGE_KEY_PIM_ICON));
        }
    }.start();
    boolean isTrayitemEnabled = Boolean.parseBoolean(System.getProperty(IJAMConst.SYSTEM_UI_TRAYITEM, "true"));
    if (isTrayitemEnabled) {
        this.m_trayPropagator = new TrayIconPropagator();
        PropagationFactory.getInstance().add(this.m_trayPropagator);
    }
    this.m_logger.info("Running new TrayCreator Thread.");
}
Also used : SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter)

Example 4 with SWTExecuter

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

the class AbstractTreeTableApplication method updateViews.

public synchronized void updateViews(Object[] controllerdata, boolean reload) {
    // refresh controll data
    refreshController(reload);
    if (controllerdata != null)
        this.m_controller.generateElementArray(controllerdata);
    final IFilterManager fm = this.getFilterManager();
    if (fm != null) {
        IFilter[] f = fm.getFiltersFromString(this.getConfiguration().getProperty(CFG_FILTER, ""));
        String activeFilter = this.getFilterManager().getFiltersToLabelText(f, 45);
        // get all defined Filters from configuration
        List l = new ArrayList();
        l.add(new IFilter[0]);
        final IFilterManager jfm = getFilterManager();
        Properties c = this.getConfiguration();
        Iterator iter = c.keySet().iterator();
        String key = null;
        while (iter.hasNext()) {
            key = (String) iter.next();
            if (key.startsWith("filter_")) {
                String filter = c.getProperty(key);
                l.add(jfm.getFiltersFromString(filter));
            }
        }
        // 2009/01/10: added sorting of filters
        Collections.sort(l, new Comparator() {

            public int compare(Object o1, Object o2) {
                if (o1 instanceof IFilter[] && o2 instanceof IFilter[]) {
                    return jfm.getFiltersToLabelText((IFilter[]) o1, 45).compareToIgnoreCase(jfm.getFiltersToLabelText((IFilter[]) o2, 45));
                }
                return 0;
            }
        });
        String[] filters = new String[l.size()];
        int select = -1;
        String filterAlias = null;
        for (int i = 0; i < l.size(); i++) {
            filterAlias = jfm.getFiltersToLabelText((IFilter[]) l.get(i), 45);
            if (filterAlias.equalsIgnoreCase(activeFilter)) {
                select = i;
            }
            filters[i] = filterAlias;
            this.currentView.setData(filterAlias, (IFilter[]) l.get(i));
        }
        this.currentView.setItems(filters);
        if (select == -1) {
            getApplication().getConfiguration().setProperty(CFG_FILTER, jfm.getFiltersToString((IFilter[]) l.get(0)));
            getApplication().storeConfiguration();
            select = 0;
        }
        this.currentView.select(select);
        this.currentView.setVisibleItemCount((this.currentView.getItemCount() > 16 ? 16 : this.currentView.getItemCount()));
        this.currentView.pack();
        this.currentView.getParent().pack();
    }
    // update menu bar
    Menu m = this.getMenuBarManager().getMenu();
    this.setMenuItemStatus(m);
    new SWTExecuter(false, getID() + "-BuildTableThread") {

        protected void execute() {
            final ThreadStatus ts = new ThreadStatus();
            class WorkerSWTExecuter extends SWTExecuter {

                public WorkerSWTExecuter(boolean sync, String name) {
                    super(sync, name);
                }

                public void execute() {
                    try {
                        Cursor c = new Cursor(((TreeViewer) viewer).getTree().getDisplay(), SWT.CURSOR_WAIT);
                        Tree tree = ((TreeViewer) viewer).getTree();
                        AbstractMenuBuilder mb = getMenuBuilder();
                        if (mb != null)
                            tree.setMenu(mb.createPopupMenu(tree));
                        tree.getShell().setCursor(c);
                        long start = System.currentTimeMillis();
                        viewer.setInput(null);
                        viewer.setInput(m_controller);
                        // added: 2007/03/17: avoid dead lock in journal...
                        ts.setFinished(true);
                        tree.setFocus();
                        tree.setLinesVisible(getConfiguration().getProperty(CFG_SHOW_GRID, "true").equalsIgnoreCase("true"));
                        TreeColumn[] columns = tree.getColumns();
                        for (int i = 0; i < columns.length; i++) {
                            columns[i].setImage(null);
                        }
                        int sortcolumn = getOrderColumn(Integer.parseInt(getConfiguration().getProperty(CFG_ORDER, "0")));
                        if (sortcolumn > -1 && sortcolumn < columns.length) {
                            tree.setSortColumn(columns[sortcolumn]);
                            if (getConfiguration().getProperty(CFG_DIRECTION, "false").equalsIgnoreCase("false")) {
                                tree.setSortDirection(SWT.DOWN);
                            } else {
                                tree.setSortDirection(SWT.UP);
                            }
                        }
                        IAction action = getColoringAction();
                        if (action != null)
                            action.run();
                        action = getHightlightAction();
                        if (action != null)
                            action.run();
                        // set new title text...
                        String title_ext = getTitleExtension();
                        if (title_ext == null || title_ext.length() == 0)
                            tree.getShell().setText(getI18nManager().getString(getNamespace(), "title", "label", getLanguage()));
                        else
                            tree.getShell().setText(getI18nManager().getString(getNamespace(), "title", "label", getLanguage()) + " - " + title_ext);
                        tree.getShell().setCursor(null);
                        c.dispose();
                        ts.setFinished(true);
                        if (lastMarkedTreeItem > -1 && tree.getItemCount() > 0) {
                            TreeItem item = tree.getItem(Math.min(lastMarkedTreeItem, tree.getItemCount() - 1));
                            if (item != null) {
                                tree.setSelection(item);
                                tree.showSelection();
                            }
                        }
                        checkAmountOfEntries(start, System.currentTimeMillis());
                    } catch (Exception e) {
                        m_logger.log(Level.SEVERE, e.getMessage(), e);
                        if (ts != null)
                            ts.setFinished(true);
                        PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "refresherror", e));
                    }
                }
            }
            ;
            final WorkerSWTExecuter workerThread = new WorkerSWTExecuter(false, getID() + "-SetDataToTableThread");
            if (getConfiguration().getProperty(AbstractTableApplication.CFG_SHOW_REFRESH_POPUP, "true").equalsIgnoreCase("true")) {
                ProgressMonitorDialog pmd = new ProgressMonitorDialog(getShell());
                try {
                    IRunnableWithProgress r = new IRunnableWithProgress() {

                        public void run(IProgressMonitor progressMonitor) {
                            progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "refreshprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                            Thread t = new Thread() {

                                public void run() {
                                    // preload data
                                    try {
                                        m_controller.getElementArray();
                                    } catch (Exception ex) {
                                        m_logger.log(Level.SEVERE, ex.getMessage(), ex);
                                    }
                                }
                            };
                            t.setName("JAM-" + getID() + "#Preloader-Thread-(non-deamon)");
                            t.start();
                            Object repository = m_controller.getRepository();
                            do {
                                try {
                                    Thread.sleep(500);
                                } catch (InterruptedException e) {
                                }
                                if (repository instanceof ITracker) {
                                    String msg = getI18nManager().getString(getNamespace(), "tracking", "label", getLanguage());
                                    int leftover = Math.max(0, (((ITracker) repository).getTotal() - ((ITracker) repository).getCurrent()));
                                    msg = StringUtils.replaceString(msg, "{%1}", Integer.toString(leftover));
                                    progressMonitor.subTask(msg);
                                }
                            } while (t.isAlive());
                            workerThread.start();
                            while (!ts.isFinished()) {
                                try {
                                    progressMonitor.worked(1);
                                    Thread.sleep(100);
                                } catch (InterruptedException e) {
                                    m_logger.log(Level.SEVERE, e.getMessage(), e);
                                }
                            }
                            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);
                }
            } else {
                workerThread.execute();
            }
            // refresh status line
            String message = m_controller.countElements() + getI18nManager().getString(getNamespace(), "items", "label", getLanguage());
            if (fm != null) {
                IFilter[] f = fm.getFiltersFromString(getConfiguration().getProperty(CFG_FILTER, ""));
                if (f != null && f.length > 0) {
                    message += getI18nManager().getString(getNamespace(), "items_filtered", "label", getLanguage());
                }
                getStatusLineManager().setMessage(message);
            }
        }
    }.start();
}
Also used : Message(de.janrufmonitor.exception.Message) TreeItem(org.eclipse.swt.widgets.TreeItem) ArrayList(java.util.ArrayList) Properties(java.util.Properties) Cursor(org.eclipse.swt.graphics.Cursor) Comparator(java.util.Comparator) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Iterator(java.util.Iterator) Tree(org.eclipse.swt.widgets.Tree) List(java.util.List) ArrayList(java.util.ArrayList) Menu(org.eclipse.swt.widgets.Menu) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter) ITracker(de.janrufmonitor.repository.imexport.ITracker) IAction(de.janrufmonitor.ui.jface.application.action.IAction) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Point(org.eclipse.swt.graphics.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFilter(de.janrufmonitor.repository.filter.IFilter)

Example 5 with SWTExecuter

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

the class AbstractTableApplication method updateViews.

public synchronized void updateViews(Object[] controllerdata, boolean reload) {
    // refresh controll data
    refreshController(reload);
    if (controllerdata != null)
        this.m_controller.generateElementArray(controllerdata);
    final IFilterManager fm = this.getFilterManager();
    if (fm != null && this.getConfiguration().getProperty(CFG_ENABLE_FILTER_VIEW, "true").equalsIgnoreCase("true")) {
        IFilter[] f = fm.getFiltersFromString(this.getConfiguration().getProperty(CFG_FILTER, ""));
        String activeFilter = this.getFilterLabel(fm, f);
        // get all defined Filters from configuration
        List l = new ArrayList();
        l.add(new IFilter[0]);
        IFilterManager jfm = getFilterManager();
        Properties c = this.getConfiguration();
        Iterator iter = c.keySet().iterator();
        String key = null;
        while (iter.hasNext()) {
            key = (String) iter.next();
            if (key.startsWith("filter_")) {
                String filter = c.getProperty(key);
                l.add(jfm.getFiltersFromString(filter));
            }
        }
        // added 2015/04/03: added runtime filters
        if (jfm.hasRuntimeFilters()) {
            IFilter[][] rf = jfm.getRuntimeFilters();
            if (rf != null && rf.length > 0) {
                for (int i = 0; i < rf.length; i++) l.add(rf[i]);
            }
        }
        // added 2015/04/01: sort filter list
        Collections.sort(l, new Comparator() {

            public int compare(Object f1, Object f2) {
                if (f1 != null && f2 != null && f1 instanceof IFilter[] && f2 instanceof IFilter[]) {
                    return getFilterLabel(getFilterManager(), ((IFilter[]) f1)).toLowerCase().compareTo(getFilterLabel(getFilterManager(), ((IFilter[]) f2)).toLowerCase());
                // if (((IFilter[])f1).length==((IFilter[])f2).length) {
                // return (((IFilter[])f2)[0].toString().compareTo(((IFilter[])f1)[0].toString()));
                // }
                // if (((IFilter[])f1).length<((IFilter[])f2).length) return -1;
                // return 1;
                }
                return 0;
            }
        });
        String[] filters = new String[l.size()];
        int select = -1;
        String filterAlias = null;
        for (int i = 0; i < l.size(); i++) {
            // this.getFilterManager().getFiltersToLabelText((IFilter[]) l.get(i),45);
            filterAlias = this.getFilterLabel(fm, (IFilter[]) l.get(i));
            if (filterAlias.equalsIgnoreCase(activeFilter)) {
                select = i;
            }
            filters[i] = filterAlias;
            this.currentView.setData(filterAlias, (IFilter[]) l.get(i));
        }
        this.currentView.setItems(filters);
        if (select == -1) {
            getApplication().getConfiguration().setProperty(CFG_FILTER, fm.getFiltersToString((IFilter[]) l.get(0)));
            getApplication().storeConfiguration();
            select = 0;
        }
        this.currentView.select(select);
        this.currentView.setVisibleItemCount((this.currentView.getItemCount() > 16 ? 16 : this.currentView.getItemCount()));
        this.currentView.pack();
        this.currentView.getParent().pack();
    }
    // update menu bar
    if (this.getMenuBarManager() != null) {
        Menu m = this.getMenuBarManager().getMenu();
        this.setMenuItemStatus(m);
    }
    new SWTExecuter(false, getID() + "-BuildTableThread") {

        protected void execute() {
            final ThreadStatus ts = new ThreadStatus();
            class WorkerSWTExecuter extends SWTExecuter {

                public WorkerSWTExecuter(boolean sync, String name) {
                    super(sync, name);
                }

                public void execute() {
                    try {
                        Cursor c = new Cursor(((TableViewer) viewer).getTable().getDisplay(), SWT.CURSOR_WAIT);
                        Table table = ((TableViewer) viewer).getTable();
                        AbstractMenuBuilder mb = getMenuBuilder();
                        if (mb != null)
                            table.setMenu(mb.createPopupMenu(table));
                        table.getShell().setCursor(c);
                        long start = System.currentTimeMillis();
                        viewer.setInput(null);
                        viewer.setInput(m_controller);
                        // added: 2007/03/17: avoid dead lock in journal...
                        ts.setFinished(true);
                        table.setFocus();
                        table.setLinesVisible(getConfiguration().getProperty(CFG_SHOW_GRID, "true").equalsIgnoreCase("true"));
                        TableColumn[] columns = table.getColumns();
                        for (int i = 0; i < columns.length; i++) {
                            columns[i].setImage(null);
                        }
                        int sortcolumn = getOrderColumn(Integer.parseInt(getConfiguration().getProperty(CFG_ORDER, "0")));
                        if (sortcolumn > -1 && sortcolumn < columns.length) {
                            table.setSortColumn(columns[sortcolumn]);
                            if (getConfiguration().getProperty(CFG_DIRECTION, "false").equalsIgnoreCase("false")) {
                                table.setSortDirection(SWT.DOWN);
                            } else {
                                table.setSortDirection(SWT.UP);
                            }
                        }
                        // IAction action = getColoringAction();
                        // if (action!=null)
                        // action.run();
                        IAction action = getHightlightAction();
                        if (action != null)
                            action.run();
                        // set new title text...
                        String title_ext = getTitleExtension();
                        if (title_ext == null || title_ext.length() == 0)
                            table.getShell().setText(getI18nManager().getString(getNamespace(), "title", "label", getLanguage()));
                        else
                            table.getShell().setText(getI18nManager().getString(getNamespace(), "title", "label", getLanguage()) + " - " + title_ext);
                        table.getShell().setCursor(null);
                        c.dispose();
                        ts.setFinished(true);
                        if (lastMarkedRow > -1) {
                            table.setSelection(Math.min(lastMarkedRow, table.getItemCount()));
                        }
                        checkAmountOfEntries(start, System.currentTimeMillis());
                    } catch (Exception e) {
                        m_logger.log(Level.SEVERE, e.getMessage(), e);
                        if (ts != null)
                            ts.setFinished(true);
                        PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "refresherror", e));
                    }
                }
            }
            ;
            final WorkerSWTExecuter workerThread = new WorkerSWTExecuter(false, getID() + "-SetDataToTableThread");
            if (getConfiguration().getProperty(AbstractTableApplication.CFG_SHOW_REFRESH_POPUP, "true").equalsIgnoreCase("true")) {
                ProgressMonitorDialog pmd = new ProgressMonitorDialog(getShell());
                try {
                    IRunnableWithProgress r = new IRunnableWithProgress() {

                        public void run(IProgressMonitor progressMonitor) {
                            progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "refreshprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                            Thread t = new Thread() {

                                public void run() {
                                    // preload data
                                    try {
                                        m_controller.getElementArray();
                                    } catch (Exception ex) {
                                        m_logger.log(Level.SEVERE, ex.getMessage(), ex);
                                    }
                                }
                            };
                            t.setName("JAM-" + getID() + "#Preloader-Thread-(non-deamon)");
                            t.start();
                            Object repository = m_controller.getRepository();
                            do {
                                try {
                                    Thread.sleep(500);
                                } catch (InterruptedException e) {
                                }
                                if (repository instanceof ITracker) {
                                    String msg = getI18nManager().getString(getNamespace(), "tracking", "label", getLanguage());
                                    int leftover = Math.max(0, (((ITracker) repository).getTotal() - ((ITracker) repository).getCurrent()));
                                    msg = StringUtils.replaceString(msg, "{%1}", Integer.toString(leftover));
                                    progressMonitor.subTask(msg);
                                }
                            } while (t.isAlive());
                            workerThread.start();
                            while (!ts.isFinished()) {
                                try {
                                    progressMonitor.worked(1);
                                    Thread.sleep(100);
                                } catch (InterruptedException e) {
                                    m_logger.log(Level.SEVERE, e.getMessage(), e);
                                }
                            }
                            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);
                }
            } else {
                workerThread.execute();
            }
            // refresh status line
            String message = m_controller.countElements() + getI18nManager().getString(getNamespace(), "items", "label", getLanguage());
            if (fm != null) {
                IFilter[] f = fm.getFiltersFromString(getConfiguration().getProperty(CFG_FILTER, ""));
                if (f != null && f.length > 0 && getConfiguration().getProperty(CFG_ENABLE_FILTER_VIEW, "true").equalsIgnoreCase("true")) {
                    message += getI18nManager().getString(getNamespace(), "items_filtered", "label", getLanguage());
                }
                getStatusLineManager().setMessage(message);
            }
        }
    }.start();
}
Also used : Message(de.janrufmonitor.exception.Message) ArrayList(java.util.ArrayList) Properties(java.util.Properties) Comparator(java.util.Comparator) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter) ITracker(de.janrufmonitor.repository.imexport.ITracker) IAction(de.janrufmonitor.ui.jface.application.action.IAction) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFilter(de.janrufmonitor.repository.filter.IFilter)

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