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:org.eclipse.linuxtools.changelog.core.actions.PrepareCommitAction.java

License:Open Source License

protected void doRun() {

    IRunnableWithProgress code = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            //   monitor.beginTask("Loading Clipboard", 1000);
            loadClipboard(monitor);//from w  w  w  .j  a v a  2s  .c o  m
            //monitor.done();
        }
    };

    ProgressMonitorDialog pd = new ProgressMonitorDialog(getWorkbench().getActiveWorkbenchWindow().getShell());

    try {
        pd.run(false /* fork */, false /* cancelable */, code);
    } catch (InvocationTargetException e) {
        ChangelogPlugin.getDefault().getLog()
                .log(new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
        return;
    } catch (InterruptedException e) {
        ChangelogPlugin.getDefault().getLog()
                .log(new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
        return;
    }

    //   loadClipboard();

}

From source file:org.eclipse.linuxtools.internal.changelog.core.actions.PrepareChangeLogAction.java

License:Open Source License

/**
 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
 *//*from w  w w .ja  va  2  s . c  o m*/
protected void doRun() {
    IRunnableWithProgress code = monitor -> {
        monitor.beginTask(Messages.getString("ChangeLog.PrepareChangeLog"), 1000); // $NON-NLS-1$
        prepareChangeLog(monitor);
        monitor.done();
    };

    ProgressMonitorDialog pd = new ProgressMonitorDialog(
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());

    try {
        pd.run(false /* fork */, false /* cancelable */, code);
    } catch (InvocationTargetException e) {
        ChangelogPlugin.getDefault().getLog()
                .log(new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
        return;
    } catch (InterruptedException e) {
        ChangelogPlugin.getDefault().getLog()
                .log(new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
    }
}

From source file:org.eclipse.linuxtools.internal.changelog.core.actions.PrepareCommitHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) {

    IRunnableWithProgress code = monitor -> loadClipboard(monitor);

    ProgressMonitorDialog pd = new ProgressMonitorDialog(
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());

    try {//  www .  j  av  a2 s  . c o  m
        pd.run(false /* fork */, false /* cancelable */, code);
    } catch (InvocationTargetException e) {
        ChangelogPlugin.getDefault().getLog()
                .log(new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
    } catch (InterruptedException e) {
        ChangelogPlugin.getDefault().getLog()
                .log(new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
    }

    return null;
}

From source file:org.eclipse.linuxtools.internal.docker.ui.launch.RunImageMainTab.java

License:Open Source License

private void findImageInfo(final IDockerImage selectedImage) {
    try {//from   w  ww  . jav  a2 s. c o m
        final FindImageInfoRunnable findImageInfoRunnable = new FindImageInfoRunnable(selectedImage);
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(this.getShell());
        dialog.run(true, true, findImageInfoRunnable);
        final IDockerImageInfo selectedImageInfo = findImageInfoRunnable.getResult();
        final Set<String> exposedPortInfos = selectedImageInfo.config().exposedPorts();
        final List<ExposedPortModel> availablePorts = new ArrayList<>();
        if (exposedPortInfos != null) {
            for (String exposedPortInfo : exposedPortInfos) {
                final String privatePort = exposedPortInfo.substring(0, exposedPortInfo.indexOf('/'));
                final String type = exposedPortInfo.substring(exposedPortInfo.indexOf('/')); // $NON-NLS-1$
                final ExposedPortModel exposedPort = new ExposedPortModel(privatePort, type, "", privatePort);
                availablePorts.add(exposedPort); // $NON-NLS-1$
            }
        }
        model.setExposedPorts(availablePorts);
        model.setEntrypoint(selectedImageInfo.config().entrypoint());
        model.setCommand(selectedImageInfo.config().cmd());

    } catch (InvocationTargetException | InterruptedException e) {
        Activator.log(e);
    }
}

From source file:org.eclipse.linuxtools.internal.oprofile.launch.launching.OprofileManualLaunchConfigurationDelegate.java

License:Open Source License

@Override
protected void postExec(LaunchOptions options, OprofileDaemonEvent[] daemonEvents, Process process) {
    final LaunchOptions fOptions = options;
    final OprofileDaemonEvent[] fDaemonEvents = daemonEvents;
    Display.getDefault().syncExec(() -> {
        //TODO: have a initialization dialog to do reset and setupDaemon?
        // using a progress dialog, can't abort the launch if there's an exception..
        try {/*  w  w w . j  a  va2  s  .c  om*/
            if (!oprofileStatus()) {
                return;
            }
            oprofileReset();
            oprofileSetupDaemon(fOptions.getOprofileDaemonOptions(), fDaemonEvents);
        } catch (OpcontrolException oe) {
            OprofileCorePlugin.showErrorDialog("opcontrolProvider", oe); //$NON-NLS-1$
            return; // dont open the dialog
        }

        //manual oprofile control dialog
        final OprofiledControlDialog dlg = new OprofiledControlDialog();

        // This was earlier in an if (!fLaunch.isTerminated()) {} block. From a
        // usability perspective I think it's better to show the oprofile control
        // dialog regardless, since it might not show up at all if the launch
        // has already be terminated. Anyhow, I think it's better this way.
        // --Severin, 2011-02-11
        dlg.setBlockOnOpen(false);
        dlg.open();

        //progress dialog for ensuring the daemon is shut down
        IRunnableWithProgress refreshRunner = monitor -> {
            monitor.beginTask(OprofileLaunchMessages.getString("oprofiledcontroldialog.post.stopdaemon"), 1); //$NON-NLS-1$
            try {
                oprofileShutdown();
            } catch (OpcontrolException e) {
            }
            monitor.worked(1);
            monitor.done();
        };
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
        try {
            dialog.run(true, false, refreshRunner);
        } catch (InvocationTargetException e1) {
            e1.printStackTrace();
        } catch (InterruptedException e2) {
            // cannot be thrown when cancelable is false
        }
    });
}

From source file:org.eclipse.linuxtools.internal.oprofile.ui.view.OprofileView.java

License:Open Source License

/**
 * Extremely convoluted way of getting the running and parsing to happen in
 *   a separate thread, with a progress monitor. In most cases and on fast
 *   machines this will probably only be a blip.
 *///from ww w .  jav  a  2 s  .  c o m
public void refreshView() {
    try {
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                .showView(OprofileUiPlugin.ID_OPROFILE_VIEW);
    } catch (PartInitException e) {
        e.printStackTrace();
    }

    IRunnableWithProgress refreshRunner = monitor -> {
        monitor.beginTask(OprofileUiMessages.getString("view.dialog.parsing.text"), 2); //$NON-NLS-1$

        OpModelRoot dataModelRoot = OpModelRoot.getDefault();
        dataModelRoot.refreshModel();
        monitor.worked(1);

        final UiModelRoot UiRoot = UiModelRoot.getDefault();
        UiRoot.refreshModel();

        Display.getDefault().asyncExec(
                () -> OprofileUiPlugin.getDefault().getOprofileView().getTreeViewer().setInput(UiRoot));
        monitor.worked(1);
        monitor.done();
    };

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
    try {
        dialog.run(true, false, refreshRunner);
    } catch (InvocationTargetException | InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:org.eclipse.linuxtools.oprofile.ui.view.OprofileView.java

License:Open Source License

/**
 * Extremely convoluted way of getting the running and parsing to happen in 
 *   a separate thread, with a progress monitor. In most cases and on fast 
 *   machines this will probably only be a blip.
 *//*from w  ww . java 2 s .c  o  m*/
public void refreshView() {
    try {
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                .showView(OprofileUiPlugin.ID_OPROFILE_VIEW);
    } catch (PartInitException e) {
        e.printStackTrace();
    }

    IRunnableWithProgress refreshRunner = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitor.beginTask(OprofileUiMessages.getString("view.dialog.parsing.text"), 2); //$NON-NLS-1$

            OpModelRoot dataModelRoot = OpModelRoot.getDefault();
            dataModelRoot.refreshModel();
            //            System.out.println(dataModelRoot);   //debugging
            monitor.worked(1);

            final UiModelRoot UiRoot = UiModelRoot.getDefault();
            UiRoot.refreshModel();

            Display.getDefault().asyncExec(new Runnable() {
                public void run() {
                    OprofileUiPlugin.getDefault().getOprofileView().getTreeViewer().setInput(UiRoot);
                }
            });
            monitor.worked(1);

            monitor.done();
        }
    };

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
    try {
        dialog.run(true, false, refreshRunner);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:org.eclipse.linuxtools.profiling.launch.ProfileLaunchShortcut.java

License:Open Source License

/**
 * Method searchAndLaunch./*  w  w w . j  av a  2s  .  c  o  m*/
 * @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(getActiveWorkbenchShell());
            IRunnableWithProgress runnable = new IRunnableWithProgress() {
                public void run(IProgressMonitor pm) throws InterruptedException {
                    int nElements = elements.length;
                    pm.beginTask(Messages.getString("ProfileLaunchShortcut.Looking_for_executables"), //$NON-NLS-1$
                            nElements);
                    try {
                        IProgressMonitor sub = new SubProgressMonitor(pm, 1);
                        for (int i = 0; i < nElements; i++) {
                            if (elements[i] instanceof IAdaptable) {
                                IResource r = (IResource) ((IAdaptable) elements[i])
                                        .getAdapter(IResource.class);
                                if (r != null) {
                                    ICProject cproject = CoreModel.getDefault().create(r.getProject());
                                    if (cproject != null) {
                                        try {
                                            IBinary[] bins = cproject.getBinaryContainer().getBinaries();

                                            for (int j = 0; j < bins.length; j++) {
                                                if (bins[j].isExecutable()) {
                                                    results.add(bins[j]);
                                                }
                                            }
                                        } catch (CModelException e) {
                                        }
                                    }
                                }
                            }
                            if (pm.isCanceled()) {
                                throw new InterruptedException();
                            }
                            sub.done();
                        }
                    } finally {
                        pm.done();
                    }
                }
            };
            try {
                dialog.run(true, true, runnable);
            } catch (InterruptedException e) {
                return;
            } catch (InvocationTargetException e) {
                handleFail(e.getMessage());
                return;
            }
            int count = results.size();
            if (count == 0) {
                handleFail(Messages.getString("ProfileLaunchShortcut.Binary_not_found")); //$NON-NLS-1$
            } else if (count > 1) {
                bin = chooseBinary(results, mode);
            } else {
                bin = (IBinary) results.get(0);
            }
        }
        if (bin != null) {
            launch(bin, mode);
        }
    } else {
        handleFail(Messages.getString("ProfileLaunchShortcut.no_project_selected")); //$NON-NLS-1$
    }
}

From source file:org.eclipse.ltk.internal.ui.refactoring.ChangeExceptionHandler.java

License:Open Source License

private void performUndo(final Change undo) {
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
        public void run(IProgressMonitor monitor) throws CoreException {
            monitor.beginTask("", 11); //$NON-NLS-1$
            try {
                undo.initializeValidationData(
                        new NotCancelableProgressMonitor(new SubProgressMonitor(monitor, 1)));
                if (undo.isValid(new SubProgressMonitor(monitor, 1)).hasFatalError()) {
                    monitor.done();/*www.j  a  va  2 s.  c om*/
                    return;
                }
                undo.perform(new SubProgressMonitor(monitor, 9));
            } finally {
                undo.dispose();
            }
        }
    };
    WorkbenchRunnableAdapter adapter = new WorkbenchRunnableAdapter(runnable,
            ResourcesPlugin.getWorkspace().getRoot());
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(fParent);
    try {
        dialog.run(false, false, adapter);
    } catch (InvocationTargetException e) {
        ExceptionHandler.handle(e, fParent, RefactoringUIMessages.ChangeExceptionHandler_rollback_title,
                RefactoringUIMessages.ChangeExceptionHandler_rollback_message + fName);
    } catch (InterruptedException e) {
        // can't happen
    }
}

From source file:org.eclipse.mdht.uml.cda.ui.handlers.AnalyzeCDAHandler.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {

    try {//from   w  w w. ja  va  2 s  .c o  m

        ProgressMonitorDialog pd = new ProgressMonitorDialog(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());

        ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
        if (selection instanceof IStructuredSelection) {

            // ProgressMonitorPart monitor = new ProgressMonitorPart(
            // PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), new FillLayout(), true);

            /*
             * IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
             * ed = window.getActivePage().getActiveEditor();
             * shell = window.getShell();
             */

            final CDAAnalaysisInput cdaAnalaysisInput = new CDAAnalaysisInput();
            final IStructuredSelection iss = (IStructuredSelection) selection;

            try {
                pd.run(true, true, new IRunnableWithProgress() {

                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {

                        try {
                            Iterator<Object> iter = iss.iterator();
                            while (iter.hasNext() && !monitor.isCanceled()) {

                                Object o = iter.next();
                                if (o instanceof IFolder) {
                                    IFolder folder = (IFolder) o;

                                    monitor.beginTask("Analyze CDA Documents", folder.members().length);

                                    codeMetricsFile = folder.getFile("codemetrics.cfg");

                                    for (IResource resource : folder.members()) {

                                        if (monitor.isCanceled()) {
                                            monitor.done();
                                            break;
                                        }
                                        if (resource instanceof IFile) {
                                            IFile file = (IFile) resource;
                                            if ("XML".equalsIgnoreCase(file.getFileExtension())) {

                                                monitor.worked(1);
                                                monitor.subTask("Processing " + file.getName());
                                                cdaAnalaysisInput.getMetrics().add(analyzePluginMode(file));
                                                //
                                                // IWorkbench wb = PlatformUI.getWorkbench();
                                                // IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
                                                // IWorkbenchPage page = win.getActivePage();
                                                //
                                                // IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().findEditor(
                                                // "org.eclipse.mdht.uml.cda.ui.editors.CDAAnalyzer");
                                                //
                                                // page.openEditor(new FileEditorInput(file), desc.getId());

                                            }

                                        }

                                    }

                                }
                            }
                        } catch (PartInitException e) {

                        } catch (CoreException e) {

                        }
                    }
                });
            } catch (InvocationTargetException e) {

            } catch (InterruptedException e) {

            }

            IWorkbench wb = PlatformUI.getWorkbench();
            IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
            IWorkbenchPage page = win.getActivePage();

            IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry()
                    .findEditor("org.eclipse.mdht.uml.cda.ui.editors.CDAAnalyzer2");

            page.openEditor(cdaAnalaysisInput, desc.getId());
            //

        }

    } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // if (selection instanceof IStructuredSelection) {
    // result = getSelectedElement((IStructuredSelection) selection, selectionType);
    // }

    return null;
}