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

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

Introduction

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

Prototype

public ProgressMonitorDialog(Shell parent) 

Source Link

Document

Creates a progress monitor dialog under the given shell.

Usage

From source file:carisma.ocl.library.presentation.LibraryEditor.java

License:Open Source License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * <!-- begin-user-doc -->/*ww w . j a  v  a 2 s . co  m*/
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void doSave(IProgressMonitor progressMonitor) {
    // Save only resources that have actually changed.
    //
    final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
    saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);

    // Do the work within an operation because this is a long running activity that modifies the workbench.
    //
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
        // This is the method that gets invoked when the operation runs.
        //
        @Override
        public void execute(IProgressMonitor monitor) {
            // Save the resources to the file system.
            //
            boolean first = true;
            for (Resource resource : LibraryEditor.this.editingDomain.getResourceSet().getResources()) {
                if ((first || !resource.getContents().isEmpty() || isPersisted(resource))
                        && !LibraryEditor.this.editingDomain.isReadOnly(resource)) {
                    try {
                        long timeStamp = resource.getTimeStamp();
                        resource.save(saveOptions);
                        if (resource.getTimeStamp() != timeStamp) {
                            LibraryEditor.this.savedResources.add(resource);
                        }
                    } catch (Exception exception) {
                        LibraryEditor.this.resourceToDiagnosticMap.put(resource,
                                analyzeResourceProblems(resource, exception));
                    }
                    first = false;
                }
            }
        }
    };

    this.updateProblemIndication = false;
    try {
        // This runs the options, and shows progress.
        //
        new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);

        // Refresh the necessary state.
        //
        ((BasicCommandStack) this.editingDomain.getCommandStack()).saveIsDone();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        OclEditorPlugin.INSTANCE.log(exception);
    }
    this.updateProblemIndication = true;
    updateProblemIndication();
}

From source file:cc.warlock.rcp.stormfront.ui.views.StormFrontGameView.java

License:Open Source License

public void startedDownloadingServerSettings() {
    settingsProgressDialog = new ProgressMonitorDialog(getSite().getShell());
    settingsProgressDialog.setBlockOnOpen(false);
    settingsProgressDialog.open();/*from ww  w .j a v  a 2 s  . co  m*/

    IProgressMonitor monitor = settingsProgressDialog.getProgressMonitor();
    monitor.beginTask("Downloading server settings...", IProgressMonitor.UNKNOWN);
}

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

License:Open Source License

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

        @Override/*from   w  ww.  j  a  v a 2  s  .  com*/
        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.agenda.preferences.Tageseinteilung.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {
    Composite ret = new Composite(parent, SWT.NONE);
    ret.setLayout(new GridLayout());
    new Label(ret, SWT.None).setText(Messages.Tageseinteilung_enterPeriods);
    final Combo cbBereich = new Combo(ret, SWT.READ_ONLY | SWT.SINGLE);
    cbBereich.setItems(bereiche);/* ww  w .  j av a  2  s.  co  m*/

    Composite grid = new Composite(ret, SWT.BORDER);
    grid.setLayout(new GridLayout(7, true));
    grid.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    new Label(grid, SWT.CENTER).setText(Messages.Tageseinteilung_mo);
    new Label(grid, SWT.CENTER).setText(Messages.Tageseinteilung_tu);
    new Label(grid, SWT.CENTER).setText(Messages.Tageseinteilung_we);
    new Label(grid, SWT.CENTER).setText(Messages.Tageseinteilung_th);
    new Label(grid, SWT.NONE).setText(Messages.Tageseinteilung_fr);
    new Label(grid, SWT.NONE).setText(Messages.Tageseinteilung_sa);
    new Label(grid, SWT.NONE).setText(Messages.Tageseinteilung_so);
    tMo = new Text(grid, SWT.BORDER | SWT.MULTI);
    tMo.setEnabled(false);
    tMo.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    originalBackgroundColor = tMo.getBackground();
    tDi = new Text(grid, SWT.BORDER | SWT.MULTI);
    tDi.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    tDi.setEnabled(false);
    tMi = new Text(grid, SWT.BORDER | SWT.MULTI);
    tMi.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    tMi.setEnabled(false);
    tDo = new Text(grid, SWT.BORDER | SWT.MULTI);
    tDo.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    tDo.setEnabled(false);
    tFr = new Text(grid, SWT.BORDER | SWT.MULTI);
    tFr.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    tFr.setEnabled(false);
    tSa = new Text(grid, SWT.BORDER | SWT.MULTI);
    tSa.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    tSa.setEnabled(false);
    tSo = new Text(grid, SWT.BORDER | SWT.MULTI);
    tSo.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    tSo.setEnabled(false);
    cbBereich.select(actBereich);

    Composite editDayComposite = new Composite(grid, SWT.None);
    editDayComposite.setLayoutData(SWTHelper.getFillGridData(7, true, 1, false));
    editDayComposite.setLayout(new GridLayout(3, false));

    btnEditValuesFor = new Button(editDayComposite, SWT.NONE);
    btnEditValuesFor.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            StructuredSelection ss = (StructuredSelection) comboViewerDayEditSelector.getSelection();
            editSelection = (DAYS) ss.getFirstElement();
            if (editSelection == null)
                return;

            Text[] days = new Text[] { tMo, tDi, tMi, tDo, tFr, tSa, tSo };
            for (Text text : days) {
                text.setEnabled(false);
                text.setBackground(originalBackgroundColor);
            }

            switch (editSelection) {
            case MONDAY:
                editSelectionText = tMo;
                break;
            case TUESDAY:
                editSelectionText = tDi;
                break;
            case FRIDAY:
                editSelectionText = tFr;
                break;
            case SATURDAY:
                editSelectionText = tSa;
                break;
            case SUNDAY:
                editSelectionText = tSo;
                break;
            case THURSDAY:
                editSelectionText = tDo;
                break;
            case WEDNESDAY:
                editSelectionText = tMi;
                break;
            default:
                break;
            }
            editSelectionText.setEnabled(true);
            editSelectionText
                    .setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_YELLOW));
            btnApplyEdit.setEnabled(true);
            dateTimeStartingFrom.setEnabled(true);
            editSelectionText.setFocus();
        }
    });
    btnEditValuesFor.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    btnEditValuesFor.setText(Messages.Tageseinteilung_lblEditValuesFor_text);

    comboViewerDayEditSelector = new ComboViewer(editDayComposite, SWT.NONE);
    Combo comboDayEditSelector = comboViewerDayEditSelector.getCombo();
    comboDayEditSelector.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    compositeEditStarting = new Composite(editDayComposite, SWT.NONE);
    compositeEditStarting.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
    GridLayout gl_compositeEditStarting = new GridLayout(3, false);
    gl_compositeEditStarting.verticalSpacing = 0;
    gl_compositeEditStarting.marginHeight = 0;
    compositeEditStarting.setLayout(gl_compositeEditStarting);

    lblChangedValuesAre = new Label(compositeEditStarting, SWT.NONE);
    lblChangedValuesAre.setText(Messages.Tageseinteilung_lblChangedValuesAre_text);

    dateTimeStartingFrom = new DateTime(compositeEditStarting, SWT.BORDER);
    TimeTool tomorrow = new TimeTool();
    tomorrow.addDays(1);
    dateTimeStartingFrom.setDate(tomorrow.get(TimeTool.YEAR), tomorrow.get(TimeTool.MONTH),
            tomorrow.get(TimeTool.DAY_OF_MONTH));
    dateTimeStartingFrom.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            setErrorMessage(null);
            DateTime dt = (DateTime) e.getSource();
            int day = dateTimeStartingFrom.getDay(); // Calendar.DAY_OF_MONTH
            int month = dateTimeStartingFrom.getMonth(); // Calendar.MONTH
            int year = dateTimeStartingFrom.getYear(); // Calendar.YEAR
            String timeString = String.format("%02d", day) + "." + String.format("%02d", month + 1) + "."
                    + String.format("%04d", year);
            TimeTool tt = new TimeTool(timeString);
            if (tt.isBefore(new TimeTool())) {
                setErrorMessage(Messages.Tageseinteilung_no_past_Date);
                TimeTool tomorrow = new TimeTool();
                tomorrow.addDays(1);
                dateTimeStartingFrom.setDate(tomorrow.get(TimeTool.YEAR), tomorrow.get(TimeTool.MONTH),
                        tomorrow.get(TimeTool.DAY_OF_MONTH));
            }
        }
    });
    dateTimeStartingFrom.setEnabled(false);

    btnApplyEdit = new Button(compositeEditStarting, SWT.NONE);
    btnApplyEdit.setText(Messages.Tageseinteilung_btnNewButton_text);
    btnApplyEdit.setEnabled(false);
    btnApplyEdit.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // Apply the selected edits starting from the selected date
            int day = dateTimeStartingFrom.getDay(); // Calendar.DAY_OF_MONTH
            int month = dateTimeStartingFrom.getMonth(); // Calendar.MONTH
            int year = dateTimeStartingFrom.getYear(); // Calendar.YEAR
            String timeString = String.format("%02d", day) + "." + String.format("%02d", month + 1) + "."
                    + String.format("%04d", year);
            ProgressMonitorDialog pmd = new ProgressMonitorDialog(UiDesk.getTopShell());
            IRunnableWithProgress irp = new TermineLockedTimesUpdater(new TimeTool(timeString), editSelection,
                    editSelectionText.getText(), Termin.TerminBereiche[actBereich]);
            try {
                pmd.run(false, false, irp);
                editSelectionText.setBackground(originalBackgroundColor);
                editSelectionText.setEnabled(false);
            } catch (InvocationTargetException e1) {
                Status status = new Status(IStatus.WARNING, Activator.PLUGIN_ID, "Execution Error", e1);
                StatusManager.getManager().handle(status, StatusManager.SHOW);
            } catch (InterruptedException e1) {
                Status status = new Status(IStatus.WARNING, Activator.PLUGIN_ID, "Execution Error", e1);
                StatusManager.getManager().handle(status, StatusManager.SHOW);
            }

            dateTimeStartingFrom.setEnabled(false);
            btnApplyEdit.setEnabled(false);
        }
    });

    comboViewerDayEditSelector.setContentProvider(ArrayContentProvider.getInstance());
    comboViewerDayEditSelector.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            TimeTool.DAYS day = (TimeTool.DAYS) element;
            return day.fullName;
        }
    });
    TimeTool.DAYS[] days = TimeTool.DAYS.values();
    comboViewerDayEditSelector.setInput(days);
    comboViewerDayEditSelector.setSelection(new StructuredSelection(days[0]));

    compositeDayBorders = new Composite(ret, SWT.NONE);
    compositeDayBorders.setLayout(new GridLayout(2, false));

    Composite compositeStart = new Composite(compositeDayBorders, SWT.NONE);
    compositeStart.setLayout(new GridLayout(3, false));

    Label btnDayStartHourIsSet = new Label(compositeStart, SWT.CHECK);
    btnDayStartHourIsSet.setText(Messages.Tageseinteilung_btnCheckButton_text);

    sodt = new Text(compositeStart, SWT.BORDER);
    sodt.setTextLimit(4);

    Label lblHours = new Label(compositeStart, SWT.NONE);
    lblHours.setText(Messages.Tageseinteilung_lblHours_text);

    Composite compositeEnd = new Composite(compositeDayBorders, SWT.NONE);
    compositeEnd.setLayout(new GridLayout(3, false));

    Label btnEndStartHourIsSet = new Label(compositeEnd, SWT.CHECK);
    btnEndStartHourIsSet.setText(Messages.Tageseinteilung_btnCheckButton_text_1);

    eodt = new Text(compositeEnd, SWT.BORDER);
    eodt.setTextLimit(4);

    Label lblHours_1 = new Label(compositeEnd, SWT.NONE);
    lblHours_1.setText(Messages.Tageseinteilung_lblHours_1_text);

    reload();
    cbBereich.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            int idx = cbBereich.getSelectionIndex();
            if (idx != -1) {
                save();
                actBereich = idx;
                reload();
            }
        }

    });
    return ret;
}

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  a  va 2 s.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;
        }//w  w w  .  j  a v  a 2s .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 {//from  ww  w  .  ja  v  a 2 s.  c o m
        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 {//from w  w w  . jav a 2  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 ava2  s .com*/
        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 va2s .c o 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;
}