Java Code Examples for org.eclipse.jface.dialogs.ProgressMonitorDialog#run()

The following examples show how to use org.eclipse.jface.dialogs.ProgressMonitorDialog#run() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: MergeProcessor   File: MergeTask.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Executes the merge in a separate minimal working copy.
 * 
 * @throws InterruptedException
 * @throws InvocationTargetException
 * @throws SvnClientException
 */
private void mergeInMinimalWorkingCopy() throws InvocationTargetException, InterruptedException {
	LogUtil.entering();
	final ProgressMonitorDialog pmd = new ProgressMonitorDialog(shellProvider.getShell());
	Dashboard.setShellProgressMonitorDialog(pmd);
	pmd.run(true, true, monitor -> {
		try {
			boolean cancelled = MergeProcessorUtil.merge(pmd, monitor, configuration, mergeUnit);
			if (cancelled) {
				mergeUnit.setStatus(MergeUnitStatus.CANCELLED);
				MergeProcessorUtil.canceled(mergeUnit);
			} else {
				mergeUnit.setStatus(MergeUnitStatus.DONE);
			}
		} catch (Throwable e) {
			pmd.getShell().getDisplay().syncExec(() -> {
				MultiStatus status = createMultiStatus(e);
				ErrorDialog.openError(pmd.getShell(), "Error dusrching merge process",
						"An Exception occured during the merge process. The merge didn't run successfully.",
						status);
			});
		}

	});
	LogUtil.exiting();
}
 
Example 2
Source Project: n4js   File: EclipseUtils.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Same as {@link #runInModalDialog(OperationCanceledManager, IRunnableWithProgress)}, but allows reacting to
 * exceptions.
 *
 * @param throwableHandler
 *            will be invoked on the runnable's thread in case the runnable throws an exception other than a
 *            {@link OperationCanceledManager#isOperationCanceledException(Throwable) cancellation exception}. May
 *            be <code>null</code> if no handling of exceptions is required.
 */
public static void runInModalDialog(OperationCanceledManager ocm, IRunnableWithProgress runnable,
		Consumer<Throwable> throwableHandler) {
	try {
		final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
		final ProgressMonitorDialog dlg = new ProgressMonitorDialog(shell);
		dlg.run(true, true, monitor -> {
			try {
				runnable.run(monitor);
			} catch (Throwable th) {
				// translate cancellation exceptions from Eclipse/Xtext to SWT/JFace world
				if (ocm.isOperationCanceledException(th)) {
					throw new InterruptedException();
				}
				if (throwableHandler != null) {
					throwableHandler.accept(th);
				}
				throw th;
			}
		});
	} catch (InvocationTargetException | InterruptedException e) {
		// ignore
	}
}
 
Example 3
/**
 * Test code below
 */
public static void main(String[] arg) {
    Shell shl = new Shell();
    ProgressMonitorDialog dlg = new AsynchronousProgressMonitorDialog(shl);

    long l = System.currentTimeMillis();
    try {
        dlg.run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Testing", 100000);
                for (long i = 0; i < 100000 && !monitor.isCanceled(); i++) {
                    //monitor.worked(1);
                    monitor.setTaskName("Task " + i);
                }
            }
        });
    } catch (Exception e) {
        Log.log(e);
    }
    System.out.println("Took " + ((System.currentTimeMillis() - l)));
}
 
Example 4
@Override
protected void okPressed(){
	ProgressMonitorDialog progress = new ProgressMonitorDialog(getShell());
	QueryProposalRunnable runnable = new QueryProposalRunnable();
	try {
		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 Ausführen des Rechnungs-Vorschlags.");
		return;
	}
	
	super.okPressed();
}
 
Example 5
Source Project: olca-app   File: ValidationView.java    License: Mozilla Public License 2.0 6 votes vote down vote up
public static void validate(Collection<INavigationElement<?>> selection) {
	IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	try {
		ValidationView instance = (ValidationView) page.showView("views.problems");
		List<ModelStatus> result = new ArrayList<>();
		ProgressMonitorDialog dialog = new ProgressMonitorDialog(UI.shell());
		dialog.run(true, true, (monitor) -> {
			monitor.beginTask(M.Initializing, IProgressMonitor.UNKNOWN);
			Set<CategorizedDescriptor> descriptors = Navigator.collectDescriptors(selection);
			DatabaseValidation validation = DatabaseValidation.with(monitor);
			result.addAll(validation.evaluate(descriptors));
		});
		StatusList[] model = createModel(result);
		instance.viewer.setInput(model);
		if (model.length == 0)
			MsgBox.info(M.DatabaseValidationCompleteNoErrorsWereFound);
	} catch (Exception e) {
		log.error("Error validating database", e);
	}
}
 
Example 6
Source Project: olca-app   File: CheckoutAction.java    License: Mozilla Public License 2.0 6 votes vote down vote up
private void doCheckout(Commit commit) throws Exception {
	ProgressMonitorDialog dialog = new ProgressMonitorDialog(UI.shell());
	dialog.run(true, false, new IRunnableWithProgress() {

		@Override
		public void run(IProgressMonitor m) throws InvocationTargetException, InterruptedException {
			try {
				FetchNotifierMonitor monitor = new FetchNotifierMonitor(m, M.CheckingOutCommit);
				RepositoryClient client = Database.getRepositoryClient();
				client.checkout(commit.id, monitor);
			} catch (WebRequestException e) {
				throw new InvocationTargetException(e, e.getMessage());
			}
		}
	});
}
 
Example 7
Source Project: n4js   File: ProjectCompareTree.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new default comparison of all API / implementation projects in the default workspace (i.e. the one
 * accessed via {@link IN4JSCore}) and shows this comparison in the widget.
 */
public void setComparison() {
	final ProgressMonitorDialog dlg = new ProgressMonitorDialog(getTree().getShell());
	try {
		dlg.run(false, false, new IRunnableWithProgress() {
			@Override
			public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
				setComparison(monitor);
			}
		});
	} catch (InvocationTargetException | InterruptedException e) {
		// ignore
	}
}
 
Example 8
Source Project: ermasterr   File: AbstractExportDialog.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void perfomeOK() throws Exception {
    try {
        final ProgressMonitorDialog monitor = new ProgressMonitorDialog(getShell());

        final ExportWithProgressManager manager = getExportWithProgressManager(settings.getExportSetting());

        manager.init(diagram, getBaseDir());

        final ExportManagerRunner runner = new ExportManagerRunner(manager);

        monitor.run(true, true, runner);

        if (runner.getException() != null) {
            throw runner.getException();
        }

        if (openAfterSavedButton != null && openAfterSavedButton.getSelection()) {
            final File openAfterSaved = openAfterSaved();

            final URI uri = openAfterSaved.toURI();

            final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

            if (openWithExternalEditor()) {
                IDE.openEditor(page, uri, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID, true);

            } else {
                final IFileStore fileStore = EFS.getStore(uri);
                IDE.openEditorOnFileStore(page, fileStore);
            }
        }

        // there is a case in another project
        diagram.getEditor().refreshProject();

    } catch (final InterruptedException e) {
        throw new InputException();
    }
}
 
Example 9
static void build() {

		final ProgressMonitorDialog dialog = new ProgressMonitorDialog(WorkbenchHelper.getShell());
		dialog.setBlockOnOpen(false);
		dialog.setCancelable(false);
		dialog.setOpenOnRun(true);
		try {
			dialog.run(true, false, monitor -> doBuild(monitor));
		} catch (InvocationTargetException | InterruptedException e1) {
			e1.printStackTrace();
		}
	}
 
Example 10
public void setInterpreterInfosWithProgressDialog(IInterpreterManager interpreterManager,
        final IInterpreterInfo[] interpreterInfos, Shell shell) {
    //this is the default interpreter
    ProgressMonitorDialog monitorDialog = new AsynchronousProgressMonitorDialog(shell);
    monitorDialog.setBlockOnOpen(false);

    try {
        IRunnableWithProgress operation = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Restoring PYTHONPATH", IProgressMonitor.UNKNOWN);
                try {
                    Set<String> interpreterNamesToRestore = new HashSet<>(); // i.e.: don't restore the PYTHONPATH (only order was changed).
                    interpreterManager.setInfos(interpreterInfos, interpreterNamesToRestore, monitor);
                } finally {
                    monitor.done();
                }
            }
        };

        monitorDialog.run(true, true, operation);

    } catch (Exception e) {
        Log.log(e);
    }
}
 
Example 11
public void restoreInterpreterInfos(boolean editorChanged,
        Shell shell, IInterpreterManager iInterpreterManager) {
    final Set<String> interpreterNamesToRestore = this.getInterpreterExeOrJarToRestoreAndClear();
    final IInterpreterInfo[] exesList = this.getExesList();

    if (!editorChanged && interpreterNamesToRestore.size() == 0) {
        IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        SelectionDialog listDialog = AbstractInterpreterPreferencesPage.createChooseIntepreterInfoDialog(
                workbenchWindow, exesList,
                "Select interpreters to be restored", true);

        int open = listDialog.open();
        if (open != ListDialog.OK) {
            return;
        }
        Object[] result = listDialog.getResult();
        if (result == null || result.length == 0) {
            return;

        }
        for (Object o : result) {
            interpreterNamesToRestore.add(((IInterpreterInfo) o).getExecutableOrJar());
        }

    }

    //this is the default interpreter
    ProgressMonitorDialog monitorDialog = new AsynchronousProgressMonitorDialog(shell);
    monitorDialog.setBlockOnOpen(false);

    try {
        IRunnableWithProgress operation = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Restoring PYTHONPATH", IProgressMonitor.UNKNOWN);
                try {
                    pushExpectedSetInfos();
                    //clear all but the ones that appear
                    iInterpreterManager.setInfos(exesList, interpreterNamesToRestore, monitor);
                } finally {
                    popExpectedSetInfos();
                    monitor.done();
                }
            }
        };

        monitorDialog.run(true, true, operation);

    } catch (Exception e) {
        Log.log(e);
    }
}
 
Example 12
private void createBill(List<Konsultation> toBill){
	ProgressMonitorDialog dialog =
		new ProgressMonitorDialog(Display.getDefault().getActiveShell());
	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(Display.getDefault().getActiveShell(),
							"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(Display.getDefault().getActiveShell(), "Fehler",
			"Fehler beim Ausführen der Rechnungserstelltung. Details siehe Log.");
		LoggerFactory.getLogger(BillingProposalViewCreateBillsHandler.class)
			.error("Error creating bills", e);
	}
}