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:com.ebmwebsourcing.petals.components.drivers.ZipUrlInputDialog.java

License:Open Source License

@Override
protected void okPressed() {

    // Parse the jbi.xml of the URL
    ProgressMonitorDialog dlg = new ProgressMonitorDialog(getShell());
    dlg.setOpenOnRun(true);/*from   ww  w  .j a va2  s. c o m*/
    try {
        dlg.run(true, true, new IRunnableWithProgress() {

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

                // To report progression and support cancellation, the parsing is made in another thread
                final AtomicBoolean isParsed = new AtomicBoolean(false);
                Thread parsingThread = new Thread() {
                    @Override
                    public void run() {

                        try {
                            URI uri = UriAndUrlHelper.urlToUri(getValue());
                            ZipUrlInputDialog.this.slProperties = ArtifactArchiveUtils
                                    .getSharedLibraryVersion(uri);

                        } catch (InvalidJbiXmlException e) {
                            PetalsComponentsPlugin.log(e, IStatus.ERROR);

                        } finally {
                            isParsed.set(true);
                        }
                    }
                };

                try {
                    monitor.beginTask("", IProgressMonitor.UNKNOWN);
                    parsingThread.start();
                    while (!isParsed.get()) {
                        Thread.sleep(500);
                        monitor.worked(2);

                        // Cancelled operation? Let the thread finish its job...
                        if (monitor.isCanceled()) {
                            ZipUrlInputDialog.this.cancelled = true;
                            break;
                        }
                    }

                } finally {
                    monitor.done();
                }
            }
        });

    } catch (InvocationTargetException e) {
        PetalsComponentsPlugin.log(e, IStatus.ERROR);

    } catch (InterruptedException e) {
        // nothing
    }

    // Close the dialog
    super.okPressed();
}

From source file:com.ecfeed.serialization.export.TestCasesExporter.java

License:Open Source License

public void runExportWithProgress(MethodNode method, Collection<TestCaseNode> testCases,
        OutputStream outputStream, boolean fromGui) {

    ExportRunnable exportRunnable = new ExportRunnable(method, testCases, outputStream);
    try {//from w  w w.  ja  v  a 2s.c  om
        if (fromGui) {
            ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(
                    EclipseHelper.getActiveShell());

            progressMonitorDialog.run(true, true, exportRunnable);
        } else {
            exportRunnable.run(null);
        }
    } catch (InvocationTargetException e) {
        ExceptionHelper.reportRuntimeException(e.getMessage());
    } catch (InterruptedException e) {
    }
}

From source file:com.ecfeed.ui.dialogs.CoverageCalculator.java

License:Open Source License

public boolean calculateCoverage() {
    // CurrentlyChangedCases are null if deselection left no test cases selected, 
    // hence we can just clear tuple map and set results to 0
    if (fCurrentlyChangedCases == null) {
        for (Map<List<OrderedChoice>, Integer> tupleMap : fTuples) {
            tupleMap.clear();/*from ww  w  .jav a  2 s .c  o m*/
        }
        // set results to zero
        resetResults();
        fCurrentlyChangedCases = new ArrayList<>();
        return true;
    } else {
        ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(Display.getDefault().getActiveShell());
        try {
            CalculatorRunnable runnable = new CalculatorRunnable();
            progressDialog.open();
            progressDialog.run(true, true, runnable);
            if (runnable.isCanceled) {
                return false;
            } else {
                fCurrentlyChangedCases.clear();
                return true;
            }

        } catch (InvocationTargetException e) {
            MessageDialog.openError(Display.getDefault().getActiveShell(), "Exception",
                    "Invocation: " + e.getCause());
            return false;
        } catch (InterruptedException e) {
            MessageDialog.openError(Display.getDefault().getActiveShell(), "Exception",
                    "Interrupted: " + e.getMessage());
            e.printStackTrace();
            return false;
        }
    }

}

From source file:com.ecfeed.ui.modelif.StaticTestExecutionSupport.java

License:Open Source License

public void proceed() {
    PrintStream currentOut = System.out;
    ConsoleManager.displayConsole();/*  w  w  w  .  ja  v  a2  s . c  om*/
    ConsoleManager.redirectSystemOutputToStream(ConsoleManager.getOutputStream());

    try {
        fFailedTests.clear();
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
        dialog.open();
        dialog.run(true, true, new ExecuteRunnable());
    } catch (InvocationTargetException e) {
        MessageDialog.openError(Display.getCurrent().getActiveShell(),
                Messages.DIALOG_TEST_EXECUTION_PROBLEM_TITLE, e.getTargetException().getMessage());
    } catch (InterruptedException e) {
        MessageDialog.openError(Display.getCurrent().getActiveShell(),
                Messages.DIALOG_TEST_EXECUTION_PROBLEM_TITLE, e.getMessage());
    }
    if (fFailedTests.size() > 0) {
        String message = "Following tests were not successfull\n\n";
        for (TestCaseNode testCase : fFailedTests) {
            message += testCase.toString() + "\n";
        }
        MessageDialog.openError(Display.getCurrent().getActiveShell(),
                Messages.DIALOG_TEST_EXECUTION_REPORT_TITLE, message);
    }
    displayTestStatusDialog();

    System.setOut(currentOut);
}

From source file:com.exploitpack.scanner.ShowDialog.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(HandlerUtil.getActiveShell(event).getShell());
    try {//  www . ja v a2  s .  c  om
        dialog.run(true, true, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) {
                monitor.beginTask("Doing something timeconsuming here", 100);
                for (int i = 0; i < 10; i++) {
                    if (monitor.isCanceled())
                        return;
                    monitor.subTask("I'm doing something here " + i);
                    sleep(1000);
                    // 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();
    }

    return null;
}

From source file:com.feup.contribution.druid.data.DruidProject.java

License:Open Source License

public boolean detectInteractions() {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
    try {// ww  w. j  a v a 2 s. c o  m
        dialog.run(true, true, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                detectInteractionsBuild(monitor);
            }
        });
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        return false;
    }
    return true;
}

From source file:com.foglyn.ui.OpenAttachmentWithDefaultProgramHandler.java

License:Open Source License

private void openAttachments(final Shell shell, final ITaskAttachment attachment) {
    String extension = getAttachmentExtension(attachment);

    final Program program = Program.findProgram(extension);
    if (program == null) {
        MessageDialog.openError(shell, "Unable to find default program",
                "Cannot find default program associated with " + attachment.getFileName());
        return;//from w ww  .  j a  va 2  s . c  om
    }

    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            String filename = "unknown.bin";

            if (attachment.getFileName() != null) {
                filename = attachment.getFileName();
            }

            File file = null;
            try {
                file = File.createTempFile("attach-", "-" + filename);
            } catch (IOException e) {
                throw new InvocationTargetException(e);
            }
            file.deleteOnExit();

            monitor.beginTask("Downloading attachment " + filename, IProgressMonitor.UNKNOWN);

            try {
                AttachmentUtils.download(attachment, monitor, file);
            } catch (IOException e) {
                AttachmentUtils.delete(file);
                throw new InvocationTargetException(e);
            } catch (CoreException e) {
                AttachmentUtils.delete(file);
                throw new InvocationTargetException(e);
            }

            Program program = Program.findProgram(getAttachmentExtension(attachment));
            if (program == null) {
                throw new InvocationTargetException(
                        new CoreException(new Status(IStatus.ERROR, FoglynUIPlugin.PLUGIN_ID,
                                "Cannot find default program associated with " + attachment.getFileName())));
            }

            // everything is OK... invoke
            if (!program.execute(file.getAbsolutePath())) {
                throw new InvocationTargetException(new CoreException(new Status(IStatus.ERROR,
                        FoglynUIPlugin.PLUGIN_ID, "Unable to start " + program.getName())));
            }
        }
    };

    ProgressMonitorDialog dlg = new ProgressMonitorDialog(shell);
    try {
        dlg.run(true, true, runnable);
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();

        if (cause instanceof IOException) {
            MessageDialog.openError(shell, "Unable to open attachment in default program",
                    "Input/output problem occured: " + cause.getMessage());
        } else {
            MessageDialog.openError(shell, "Unable to open attachment in default program", cause.getMessage());
        }
    } catch (InterruptedException e) {
        //
    }
}

From source file:com.ge.research.sadl.ui.imports.OwlFileResourceImportPage1.java

License:Open Source License

/**
 * Update the tree to only select those elements that match the selected types
 *//*from   w w w  . j av  a2 s. c o  m*/
protected void setupSelectionsBasedOnSelectedTypes() {
    ProgressMonitorDialog dialog = new ProgressMonitorJobsDialog(getContainer().getShell());
    final Map selectionMap = new Hashtable();

    final IElementFilter filter = new IElementFilter() {

        public void filterElements(Collection files, IProgressMonitor monitor) throws InterruptedException {
            if (files == null) {
                throw new InterruptedException();
            }
            Iterator filesList = files.iterator();
            while (filesList.hasNext()) {
                if (monitor.isCanceled()) {
                    throw new InterruptedException();
                }
                checkFile(filesList.next());
            }
        }

        public void filterElements(Object[] files, IProgressMonitor monitor) throws InterruptedException {
            if (files == null) {
                throw new InterruptedException();
            }
            for (int i = 0; i < files.length; i++) {
                if (monitor.isCanceled()) {
                    throw new InterruptedException();
                }
                checkFile(files[i]);
            }
        }

        private void checkFile(Object fileElement) {
            MinimizedFileSystemElement file = (MinimizedFileSystemElement) fileElement;
            if (isExportableExtension(file.getFileNameExtension())) {
                List elements = new ArrayList();
                FileSystemElement parent = file.getParent();
                if (selectionMap.containsKey(parent)) {
                    elements = (List) selectionMap.get(parent);
                }
                elements.add(file);
                selectionMap.put(parent, elements);
            }
        }

    };

    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(final IProgressMonitor monitor) throws InterruptedException {
            monitor.beginTask(SADLImportMessages.ImportPage_filterSelections, IProgressMonitor.UNKNOWN);
            getSelectedResources(filter, monitor);
        }
    };

    try {
        dialog.run(true, true, runnable);
    } catch (InvocationTargetException exception) {
        //Couldn't start. Do nothing.
        return;
    } catch (InterruptedException exception) {
        //Got interrupted. Do nothing.
        return;
    }
    // make sure that all paint operations caused by closing the progress
    // dialog get flushed, otherwise extra pixels will remain on the screen until
    // updateSelections is completed
    getShell().update();
    // The updateSelections method accesses SWT widgets so cannot be executed
    // as part of the above progress dialog operation since the operation forks
    // a new process.
    if (selectionMap != null) {
        updateSelections(selectionMap);
    }
}

From source file:com.generalrobotix.ui.item.GrxProjectItem.java

License:Open Source License

public void restoreProject() {

    String mode = manager_.getCurrentModeName();
    System.out.println("Restore Project (Mode:" + mode + ")"); //$NON-NLS-1$ //$NON-NLS-2$

    IRunnableWithProgress runnableProgress = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InterruptedException {
            String mode = manager_.getCurrentModeName();
            monitor.beginTask("Restore Project (Mode:" + mode + ")", 10); //$NON-NLS-1$ //$NON-NLS-2$
            restoreProject_work(mode, monitor);
            monitor.done();//  www .  j av a 2 s  . c  o  m
        }
    };
    ProgressMonitorDialog progressMonitorDlg = new ProgressMonitorDialog(
            GrxUIPerspectiveFactory.getCurrentShell());
    try {
        progressMonitorDlg.run(false, false, runnableProgress);
        //????????E//
        Grx3DView view3d = (Grx3DView) manager_.getView(Grx3DView.class, true);
        if (view3d != null) {
            view3d.repaint();
        }
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:com.genuitec.eclipse.gerrit.tools.internal.changes.commands.FetchChangeCommand.java

License:Open Source License

@Override
protected Object internalExecute(ExecutionEvent event) throws Exception {
    Shell shell = HandlerUtil.getActiveShell(event);

    Repository repository = RepositoryUtils.getRepository(HandlerUtil.getCurrentSelection(event));
    if (repository == null) {
        return null;
    }/*from ww  w .j  av  a 2s. c o m*/

    //configure branch creation
    try {
        FetchChangeBranchDialog fetchChangeBranchDialog = new FetchChangeBranchDialog(shell, repository);
        if (fetchChangeBranchDialog.open() != IDialogConstants.OK_ID) {
            return null;
        }
        //perform branch operation
        try {
            ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(shell);
            final CreateChangeBranchOperation op = new CreateChangeBranchOperation(progressDialog.getShell(),
                    event, repository, fetchChangeBranchDialog.getSettings());
            progressDialog.run(true, true, op);
        } catch (InterruptedException e) {
            //ignore
        }
    } catch (NoClassDefFoundError err) {
        MessageLinkDialog.openWarning(shell, "Mylyn for Gerrit is not installed",
                "To be able to fetch a change from Gerrit, please install Mylyn Gerrit connector. Detailed instructions can be found <a>here</a>.",
                new MessageLinkDialog.IMessageLinkDialogListener() {
                    @Override
                    public void linkSelected(SelectionEvent e) {
                        try {
                            PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(
                                    "https://github.com/Genuitec/gerrit-tools/wiki/Fetch-from-Gerrit-setup"));
                        } catch (Exception ex) {
                            RepositoryUtils.handleException(ex);
                        }
                    }
                });
    }

    return null;
}