Example usage for org.eclipse.jface.dialogs ProgressMonitorDialog run

List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog run

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs ProgressMonitorDialog run.

Prototype

@Override
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
        throws InvocationTargetException, InterruptedException 

Source Link

Document

This implementation of IRunnableContext#run(boolean, boolean, IRunnableWithProgress) runs the given IRunnableWithProgress using the progress monitor for this progress dialog and blocks until the runnable has been run, regardless of the value of fork.

Usage

From source file:ch.elexis.core.ui.actions.ReadOnceTreeLoader.java

License:Open Source License

@Override
public IStatus work(IProgressMonitor monitor, HashMap<String, Object> params) {
    UiDesk.asyncExec(new Runnable() {

        @Override//from  w  w  w  .  j av a  2s .c o m
        public void run() {
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(
                    cv.getViewerWidget().getControl().getShell());
            try {
                dialog.run(false, false, new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                        monitor.beginTask("Durchsuche Tarmed....", -1);
                        tv.refresh(false);
                        if (slp.isEmpty()) {
                            if (expanded != null) {
                                tv.setExpandedElements(expanded);
                                expanded = null;
                            }
                        } else {
                            if (expanded == null) {
                                expanded = tv.getExpandedElements();
                            }
                            tv.expandAll();
                        }
                        monitor.done();
                    }
                });
            } catch (InvocationTargetException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });
    return Status.OK_STATUS;
}

From source file:ch.elexis.core.ui.commands.BillingProposalViewCreateBillsHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    List<Konsultation> kons = getToBill(event);
    final List<Konsultation> toBill = BillingUtil.getKonsultationsFromSameYear(kons);
    if (toBill.size() > 0 && toBill.size() != kons.size()) {
        if (!MessageDialog.openQuestion(HandlerUtil.getActiveShell(event), "Rechnung Validierung",
                "Eine Rechnung kann nur Leistungen innerhalb eines Jahres beinhalten.\n\nWollen Sie mit der Erstellung der Rechnung fr das Jahr "
                        + new TimeTool(toBill.get(0).getDatum()).get(TimeTool.YEAR) + " fortsetzen ?")) {
            LoggerFactory.getLogger(BillingProposalViewCreateBillsHandler.class)
                    .warn("Invoice creation canceled by user");
            return null;
        }// ww  w  .  j a va2  s .  co  m
    }

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(HandlerUtil.getActiveShell(event));
    try {
        dialog.run(true, false, new IRunnableWithProgress() {

            private int successful = 0;
            private int errorneous = 0;
            private StringBuilder errorneousInfo = new StringBuilder();

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Rechnungen erstellen", 3);
                List<Konsultation> billable = BillingUtil.filterNotBillable(toBill);
                monitor.worked(1);
                Map<Rechnungssteller, Map<Fall, List<Konsultation>>> toBillMap = BillingUtil
                        .getGroupedBillable(billable);
                monitor.worked(1);
                // create all bills
                List<Result<Rechnung>> results = BillingUtil.createBills(toBillMap);
                // build information to show
                for (Result<Rechnung> result : results) {
                    if (result.isOK()) {
                        successful++;
                    } else {
                        errorneousInfo.append(result.getSeverity()).append(" -> ");
                        List<Result<Rechnung>.msg> messages = result.getMessages();
                        for (int i = 0; i < messages.size(); i++) {
                            if (i > 0) {
                                errorneousInfo.append(" / ");
                            }
                            errorneousInfo.append(messages.get(i).getText());
                        }
                        errorneousInfo.append("\n");
                        errorneous++;
                    }
                }
                monitor.worked(1);
                monitor.done();
                // show information
                Display.getDefault().syncExec(new Runnable() {
                    @Override
                    public void run() {
                        MessageDialog.openInformation(HandlerUtil.getActiveShell(event), "Info",
                                MessageFormat.format(
                                        "Es wurden {0} Rechnungen erfolgreich erstellt.\nBei {1} Rechnungen traten Fehler auf.\n{2}",
                                        successful, errorneous, errorneousInfo.toString()));
                    }
                });
            }
        });
    } catch (InvocationTargetException | InterruptedException e) {
        MessageDialog.openError(HandlerUtil.getActiveShell(event), "Fehler",
                "Fehler beim Ausfhren der Rechnungserstelltung. Details siehe Log.");
        LoggerFactory.getLogger(BillingProposalViewCreateBillsHandler.class).error("Error creating bills", e);
        return null;
    }

    return null;
}

From source file:ch.elexis.core.ui.CoreOperationAdvisor.java

License:Open Source License

@Override
public void showProgress(IRunnableWithProgress irwp) {
    try {//  w  w w .ja  v  a  2  s.  c om
        if (isDisplayAvailable()) {
            Display.getDefault().asyncExec(new Runnable() {
                @Override
                public void run() {
                    ProgressMonitorDialog pmd = new ProgressMonitorDialog(Hub.getActiveShell());
                    org.eclipse.jface.operation.IRunnableWithProgress irpwAdapter = new org.eclipse.jface.operation.IRunnableWithProgress() {

                        @Override
                        public void run(IProgressMonitor monitor)
                                throws InvocationTargetException, InterruptedException {
                            irwp.run(monitor);
                        }
                    };
                    try {
                        pmd.run(false, true, irpwAdapter);
                    } catch (InvocationTargetException | InterruptedException e) {
                        log.error("Execution error", e);
                    }
                }
            });
        } else {
            irwp.run(new NullProgressMonitor());
        }
    } catch (InvocationTargetException | InterruptedException e) {
        log.error("Execution error", e);
    }
}

From source file:ch.elexis.core.ui.dialogs.BillingProposalWizardDialog.java

License:Open Source License

@Override
protected void okPressed() {
    ProgressMonitorDialog progress = new ProgressMonitorDialog(getShell());
    QueryProposalRunnable runnable = new QueryProposalRunnable();
    try {//w w w . ja v  a2 s .c  om
        progress.run(true, true, runnable);
        if (runnable.isCanceled()) {
            return;
        } else {
            proposal = runnable.getProposal();
        }
    } catch (InvocationTargetException | InterruptedException e) {
        LoggerFactory.getLogger(BillingProposalWizardDialog.class).error("Error running proposal query", e);
        MessageDialog.openError(getShell(), "Fehler", "Fehler beim Ausfhren des Rechnungs-Vorschlags.");
        return;
    }

    super.okPressed();
}

From source file:ch.elexis.core.ui.stock.dialogs.ImportArticleDialog.java

License:Open Source License

private void runImport(StringBuffer buf, final List<String> storeIds, final Stock stock, ExcelWrapper xl,
        boolean overrideStockEntries) {
    ProgressMonitorDialog progress = new ProgressMonitorDialog(getShell());
    try {//from   w  w w  . j a  v  a2  s  .c o m
        progress.run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) {

                int importCount = 0;
                int articleNotFoundByGtin = 0;
                int articleNotFoundInStock = 0;
                int unexpectedErrors = 0;
                int lastRow = xl.getLastRow();
                int firstRow = xl.getFirstRow() + 1; //header offset
                monitor.beginTask("Artikel in Lager Import", 100);

                for (int i = firstRow; i <= lastRow; i++) {
                    Optional<? extends IArticle> opArticle = Optional.empty();
                    List<String> row = xl.getRow(i);
                    String stockCount = row.get(0);
                    String articleName = row.get(1);
                    String gtin = row.get(6);
                    String stockMin = null;
                    String stockMax = null;
                    if (row.size() > 8) {
                        stockMin = row.get(8);
                    }
                    if (row.size() > 9) {
                        stockMax = row.get(9);
                    }

                    // search for article
                    for (String storeId : storeIds) {
                        opArticle = ArticleServiceHolder.getService(storeId).get().findAnyByGTIN(gtin);
                    }

                    if (opArticle.isPresent()) {
                        // check if article is present in stock
                        IStockEntry stockEntry = CoreHub.getStockService().findStockEntryForArticleInStock(
                                stock, ((Artikel) opArticle.get()).storeToString());

                        String result = "MODIFY";
                        if (stockEntry == null) {
                            PersistentObject article = (PersistentObject) opArticle.get();
                            stockEntry = CoreHub.getStockService().storeArticleInStock(stock,
                                    article.storeToString());
                            result = "ADDITION";
                        }

                        if (stockEntry instanceof StockEntry) {
                            StockEntry poStockEntry = (StockEntry) stockEntry;
                            if (CoreHub.getLocalLockService().acquireLock(poStockEntry).isOk()) {
                                // do import
                                stockEntry.setCurrentStock(overrideStockEntries
                                        ? StringTool.parseSafeInt(stockCount)
                                        : (StringTool.parseSafeInt(stockCount) + stockEntry.getCurrentStock()));
                                if (stockMin != null) {
                                    stockEntry.setMinimumStock(StringTool.parseSafeInt(stockMin));
                                }
                                if (stockMax != null) {
                                    stockEntry.setMaximumStock(StringTool.parseSafeInt(stockMax));
                                }
                                importCount++;
                                addToReport("OK " + result + " '" + stock.getLabel() + "'", articleName, gtin);
                                CoreHub.getLocalLockService().releaseLock(poStockEntry);
                            } else {
                                addToReport("NO LOCK", articleName, gtin);
                                unexpectedErrors++;
                            }
                        } else {
                            addToReport("Not in Stock '" + stock.getLabel() + "'", articleName, gtin);
                            articleNotFoundInStock++;
                        }
                    } else {
                        articleNotFoundByGtin++;
                        addToReport("Not found by GTIN", articleName, gtin);
                    }

                    monitor.worked(1);
                    if (monitor.isCanceled()) {
                        buf.append("Der Import wurde durch den Benutzer abgebrochen.");
                        break;
                    }
                }

                buf.append(lastRow);
                buf.append(" Artikel gelesen.");
                buf.append("\n");
                buf.append("\n");
                buf.append(importCount);
                buf.append(" Artikel erfolgreich nach Lager '");
                buf.append(stock.getLabel());
                buf.append("' importiert.");
                buf.append("\n");
                if (articleNotFoundInStock > 0) {
                    buf.append("\n");
                    buf.append(articleNotFoundInStock);
                    buf.append(" Artikel nicht im Lager '");
                    buf.append(stock.getLabel());
                    buf.append("' vorhanden.");
                }

                if (articleNotFoundByGtin > 0) {
                    buf.append("\n");
                    buf.append(articleNotFoundByGtin);
                    buf.append(" Artikel nicht in der Datenbank gefunden.");
                }
                if (unexpectedErrors > 0) {
                    buf.append("\n");
                    buf.append(unexpectedErrors);
                    buf.append(" Artikel konnten nicht verarbeitet werden.");
                }
            }

        });
    } catch (InvocationTargetException | InterruptedException e) {
        LoggerFactory.getLogger(ImportArticleDialog.class).warn("Exception during article to lager import.", e);
    }
}

From source file:ch.elexis.core.ui.util.SqlWithUiRunner.java

License:Open Source License

public boolean runSql() {
    sql = new ArrayList<UpdateDbSql>();
    // create UpdateDbSql objects from input list
    for (String sqlString : sqlStrings) {
        sql.add(new UpdateDbSql(sqlString));
    }/* w  w  w .j  a v  a  2  s  .  co  m*/
    // run the update with progress in the UI Thread if a Display is available ...
    if (isDisplayAvailable()) {
        Display.getDefault().syncExec(new Runnable() {
            @Override
            public void run() {
                Shell parent = null;
                try {
                    parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                } catch (IllegalStateException e) {
                    // the workbench has not been created yet ... create a dummy Shell on the
                    // display
                    parent = new Shell(Display.getDefault());
                } catch (NullPointerException e) {
                    // the workbench has not been created yet ... create a dummy Shell on the
                    // display
                    parent = new Shell(Display.getDefault());
                }
                ProgressMonitorDialog dialog = new ProgressMonitorDialog(parent);
                try {
                    dialog.run(true, false, new IRunnableWithProgress() {
                        @Override
                        public void run(IProgressMonitor monitor) {
                            monitor.beginTask("Running DB Script", sql.size());
                            for (UpdateDbSql update : sql) {
                                monitor.subTask(update.getSql());
                                update.run();
                                // worked increates the monitor, the values is added to the
                                // existing ones
                                monitor.worked(1);
                            }
                            monitor.done();
                        }
                    });
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
    } else {
        // this code should only be reached during tests!
        for (UpdateDbSql update : sql) {
            update.run();
        }
    }
    // determine if all updates were successful
    for (UpdateDbSql update : sql) {
        if (update.getStatus() == SqlStatus.FAIL)
            return false;
    }
    return true;
}

From source file:ch.elexis.extdoc.dialogs.MoveIntoSubDirsDialog.java

License:Open Source License

public void run() {
    if (logger == null)
        logger = LoggerFactory.getLogger(this.getClass());
    logger.info("MoveIntoSubDirsDialog started"); //$NON-NLS-1$

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
    try {//  w  ww  .j  a v  a 2  s . co  m
        dialog.run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) {
                int nrTreated = 0;
                java.util.List<File> oldFiles = MatchPatientToPath.getAllOldConventionFiles();
                int nrFiles = oldFiles.size();
                String dialogTitle = String.format("Alle (%1d) Dateien in Unterverzeichnisse auslagern ...", //$NON-NLS-1$
                        nrFiles);
                logger.info(dialogTitle);
                if (oldFiles == null) {
                    SWTHelper.showInfo(dialogTitle, Messages.MoveIntoSubDirsDialog_no_old_Files_found);
                    return;
                }
                monitor.beginTask(dialogTitle, oldFiles.size());
                Iterator<File> iterator = oldFiles.iterator();
                while (iterator.hasNext()) {
                    if (monitor.isCanceled())
                        break;
                    File f = iterator.next();
                    logger.info("Moving " + f.getAbsolutePath()); //$NON-NLS-1$
                    MatchPatientToPath.MoveIntoSubDir(f.getAbsolutePath());
                    ++nrTreated;
                    if (nrTreated % 10 == 1) {
                        monitor.subTask(String.format(Messages.MoveIntoSubDirsDialog_sub_task, f.getName()));
                        monitor.worked(10);
                    }
                }
                monitor.done();
                logger.info("MoveIntoSubDirsDialog done"); //$NON-NLS-1$
                SWTHelper.showInfo(dialogTitle, Messages.MoveIntoSubDirsDialog_finished);
            }
        });
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        SWTHelper.showInfo("Fehler beim Auslagern!!",
                Messages.MoveIntoSubDirsDialog_finished + "\n" + e.getMessage());
        logger.info("Fehler beim Auslagern!!" + e.getLocalizedMessage()); //$NON-NLS-1$
    } catch (InterruptedException e) {
        e.printStackTrace();
        SWTHelper.showInfo("Fehler beim Auslagern!",
                Messages.MoveIntoSubDirsDialog_finished + "\n" + e.getMessage());
        logger.info("Fehler beim Auslagern!!" + e.getLocalizedMessage()); //$NON-NLS-1$
    }
    return;
}

From source file:ch.elexis.icpc.fire.handlers.ExportFireHandler.java

License:Open Source License

/**
 * the command has been executed, so extract extract the needed information from the application
 * context.//  ww w .  ja v  a2 s.c o  m
 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    String lastupdate = CoreHub.globalCfg.get(CFGPARAM, null);
    if (lastupdate == null) {
        lastupdate = "20090101";
    }
    Query<Konsultation> qbe = new Query<Konsultation>(Konsultation.class);
    TimeTool ttFrom = new TimeTool(lastupdate);
    ttFrom.addHours(Report.EXPORT_DELAY * -1);
    qbe.add(Konsultation.DATE, Query.GREATER, ttFrom.toString(TimeTool.DATE_COMPACT));
    TimeTool ttTo = new TimeTool();
    ttTo.addHours(Report.EXPORT_DELAY * -1);
    qbe.add(Konsultation.DATE, Query.LESS_OR_EQUAL, ttTo.toString(TimeTool.DATE_COMPACT));
    List<Konsultation> konsen = qbe.execute();
    if (konsen.size() > 0) {
        FileDialog fd = new FileDialog(Hub.getActiveShell(), SWT.SAVE);
        fd.setFileName("elexis-fire" + new TimeTool().toString(TimeTool.DATE_COMPACT) + ".xml");
        fd.setFilterExtensions(new String[] { "xml" });
        fd.setFilterNames(new String[] { "XML-Dateien" });
        String expath = fd.open();
        if (expath != null) {
            ProgressMonitorDialog progress = new ProgressMonitorDialog(HandlerUtil.getActiveShell(event));
            try {
                progress.run(true, true, new ReportExportRunnable(konsen, expath));
            } catch (InvocationTargetException | InterruptedException e) {
                logger.warn("Exception during FIRE export", e);
            }
        }
    }
    return null;
}

From source file:ch.elexis.TarmedRechnung.XMLExporter.java

License:Open Source License

/**
 * Output a Collection of bills. This essentially lets the user modify the output settings (if
 * any) and then calls doExport() fr each bill in rnn
 * /*  www  .  ja va 2 s.  c  o m*/
 * @param type
 *            desired mode (original, copy, storno)
 * @param rnn
 *            a Collection of Rechnung - Objects to output
 */
@Override
public Result<Rechnung> doOutput(final IRnOutputter.TYPE type, final Collection<Rechnung> rnn,
        Properties props) {
    Result<Rechnung> ret = new Result<Rechnung>();
    if (outputDir == null) {
        SWTHelper.SimpleDialog dlg = new SWTHelper.SimpleDialog(new SWTHelper.IControlProvider() {
            @Override
            public Control getControl(Composite parent) {
                return createSettingsControl(parent);
            }

            @Override
            public void beforeClosing() {
                // Nothing
            }
        });
        if (dlg.open() != Dialog.OK) {
            return ret;
        }
    }
    ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getDefault().getActiveShell());
    try {
        progress.run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(Messages.RechnungsDrucker_PrintingBills, rnn.size());
                for (Rechnung rn : rnn) {
                    if (doExport(rn, outputDir + File.separator + rn.getNr() + ".xml", type, //$NON-NLS-1$
                            false) == null) {
                        ret.add(Result.SEVERITY.ERROR, 1, Messages.XMLExporter_ErrorInBill + rn.getNr(), rn,
                                true);
                    }
                    monitor.worked(1);
                    if (monitor.isCanceled()) {
                        break;
                    }
                }
                monitor.done();
            }
        });

    } catch (InvocationTargetException | InterruptedException e) {
        LoggerFactory.getLogger(XMLExporter.class).error("Error outputting bills", e);
        MessageDialog.openError(Display.getDefault().getActiveShell(),
                Messages.RechnungsDrucker_MessageErrorWhilePrinting,
                Messages.RechnungsDrucker_MessageErrorWhilePrinting + "[" + e.getMessage() + "]");
    }
    return ret;
}

From source file:ch.hsr.ifs.cutelauncher.CuteLaunchShortcut.java

License:Open Source License

/**
 * Method searchAndLaunch.// w w w . ja v  a2  s  . c  om
 * @param objects
 * @param mode
 */
private void searchAndLaunch(final Object[] elements, String mode) {
    if (elements != null && elements.length > 0) {
        IBinary bin = null;
        if (elements.length == 1 && elements[0] instanceof IBinary) {
            bin = (IBinary) elements[0];
        } else {
            final List<IBinary> results = new ArrayList<IBinary>();
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
            IRunnableWithProgress runnable = new RunnableWithProgressToScanForExecutableImpl(elements, results);

            try {
                dialog.run(true, true, runnable);
            } catch (InterruptedException e) {
                return;
            } catch (InvocationTargetException e) {
                MessageDialog.openError(getShell(),
                        LaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                        e.getMessage());
                return;
            }

            int count = results.size();
            if (count == 0) {
                MessageDialog.openError(getShell(),
                        LaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                        LaunchMessages.getString("CApplicationLaunchShortcut.Launch_failed_no_binaries")); //$NON-NLS-1$
            } else if (count > 1) {
                bin = chooseBinary(results, mode);
            } else {
                bin = results.get(0);
            }
        }

        if (bin != null) {
            launch(bin, mode);
        }
    } else {
        MessageDialog.openError(getShell(),
                LaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                LaunchMessages.getString("CApplicationLaunchShortcut.Launch_failed_no_project_selected")); //$NON-NLS-1$
    }
}