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.gigaspaces.azure.runnable.NewHostedServiceWithProgressWindow.java

License:Open Source License

@Override
public void run() {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    try {//from   w ww . j av  a2  s.  c  o  m
        dialog.run(true, true, this);
        dialog.close();
    } catch (InvocationTargetException e) {
        MessageUtil.displayErrorDialog(shell,
                com.gigaspaces.azure.wizards.Messages.createHostedServiceFailedMsg, e.getMessage());
        Activator.getDefault().log(Messages.error, e);
    } catch (InterruptedException e) {
        MessageDialog.openWarning(shell, Messages.interrupt, Messages.newServiceInterrupted);
        Activator.getDefault().log(Messages.error, e);
    }
}

From source file:com.gigaspaces.azure.runnable.NewStorageAccountWithProgressWindow.java

License:Open Source License

@Override
public void run() {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    try {//w  ww. ja va  2  s .  c  om
        dialog.run(true, true, this);
        dialog.close();
    } catch (InvocationTargetException e) {
        MessageUtil.displayErrorDialog(shell,
                com.gigaspaces.azure.wizards.Messages.createStorageAccountFailedTitle, e.getMessage());
        Activator.getDefault().log(Messages.error, e);
    } catch (InterruptedException e) {
        MessageDialog.openWarning(shell, Messages.interrupt, Messages.newStorageInterrupted);
        Activator.getDefault().log(Messages.error, e);
    }
}

From source file:com.google.cloud.tools.eclipse.appengine.login.ui.LoginServiceUi.java

License:Apache License

private String showProgressDialogAndWaitForCode(final String message, final LocalServerReceiver codeReceiver,
        final String redirectUrl) throws IOException {
    try {/*from ww  w  .j a va  2  s. c  o m*/
        final Semaphore wait = new Semaphore(0 /* initially zero permit */);

        final ProgressMonitorDialog dialog = new ProgressMonitorDialog(shellProvider.getShell()) {
            @Override
            protected void configureShell(Shell shell) {
                super.configureShell(shell);
                shell.setText(Messages.LOGIN_PROGRESS_DIALOG_TITLE);
            }

            @Override
            protected void cancelPressed() {
                wait.release(); // Allow termination of the attached task.
                stopCodeWaitingJob(redirectUrl);

                AnalyticsPingManager.getInstance().sendPing(AnalyticsEvents.LOGIN_CANCELED, null, null,
                        getParentShell());
            }
        };

        final String[] codeHolder = new String[1];
        final IOException[] exceptionHolder = new IOException[1];

        dialog.run(true /* fork */, true /* cancelable */, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                AnalyticsPingManager.getInstance().sendPing(AnalyticsEvents.LOGIN_START, null, null,
                        dialog.getShell());

                monitor.beginTask(message != null ? message : Messages.LOGIN_PROGRESS_DIALOG_MESSAGE,
                        IProgressMonitor.UNKNOWN);
                // Fork another sub-job to circumvent the limitation of LocalServerReceiver.
                // (See the comments of scheduleCodeWaitingJob().)
                scheduleCodeWaitingJob(new LocalServerReceiverWrapper(codeReceiver), wait, codeHolder,
                        exceptionHolder);
                wait.acquireUninterruptibly(); // Block until signaled.
            }
        });

        if (exceptionHolder[0] != null) {
            throw exceptionHolder[0];
        }
        return codeHolder[0];

    } catch (InvocationTargetException | InterruptedException ex) {
        // Never thrown from the attached task.
        return null;
    }
}

From source file:com.google.cloud.tools.eclipse.login.ui.LoginServiceUi.java

License:Apache License

private String showProgressDialogAndWaitForCode(final String message, final LocalServerReceiver codeReceiver,
        final String redirectUrl) throws IOException {
    try {//from   w w  w .  j  a  va  2s . c om
        final Semaphore wait = new Semaphore(0 /* initially zero permit */);

        final ProgressMonitorDialog dialog = new ProgressMonitorDialog(shellProvider.getShell()) {
            @Override
            protected void configureShell(Shell shell) {
                super.configureShell(shell);
                shell.setText(Messages.getString("LOGIN_PROGRESS_DIALOG_TITLE"));
            }

            @Override
            protected void cancelPressed() {
                wait.release(); // Allow termination of the attached task.
                stopCodeWaitingJob(redirectUrl);

                AnalyticsPingManager.getInstance().sendPing(AnalyticsEvents.LOGIN_CANCELED, null, null,
                        getParentShell());
            }
        };

        final String[] codeHolder = new String[1];
        final IOException[] exceptionHolder = new IOException[1];

        dialog.run(true /* fork */, true /* cancelable */, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                AnalyticsPingManager.getInstance().sendPing(AnalyticsEvents.LOGIN_START, null, null,
                        dialog.getShell());

                monitor.beginTask(
                        message != null ? message : Messages.getString("LOGIN_PROGRESS_DIALOG_MESSAGE"),
                        IProgressMonitor.UNKNOWN);
                // Fork another sub-job to circumvent the limitation of LocalServerReceiver.
                // (See the comments of scheduleCodeWaitingJob().)
                scheduleCodeWaitingJob(new LocalServerReceiverWrapper(codeReceiver), wait, codeHolder,
                        exceptionHolder);
                wait.acquireUninterruptibly(); // Block until signaled.
            }
        });

        if (exceptionHolder[0] != null) {
            throw exceptionHolder[0];
        }
        return codeHolder[0];

    } catch (InvocationTargetException | InterruptedException ex) {
        // Never thrown from the attached task.
        return null;
    }
}

From source file:com.google.gdt.eclipse.designer.actions.deploy.DeployModuleAction.java

License:Open Source License

@Override
protected void runWithSelectedModule() throws Exception {
    final DeployDialog deployDialog = new DeployDialog(DesignerPlugin.getShell(), Activator.getDefault(),
            m_selectedModule);//from  www. j ava2  s .  co m
    if (deployDialog.open() != Window.OK) {
        return;
    }
    //
    IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                monitor.beginTask("Deployment of module '" + m_selectedModule.getId() + "'", 1);
                // create script
                {
                    monitor.worked(1);
                    createBuildScript(deployDialog);
                }
                // execute script
                {
                    IProject project = m_selectedModule.getProject();
                    IFolder targetFolder = m_selectedModule.getModuleFolder();
                    File buildFile = targetFolder.getFile("build.xml").getLocation().toFile();
                    AntHelper antHelper = new AntHelper(buildFile, project.getLocation().toFile());
                    antHelper.execute(monitor);
                }
            } catch (Throwable e) {
                throw new InvocationTargetException(e);
            }
        }
    };
    ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(DesignerPlugin.getShell());
    progressMonitorDialog.run(true, false, runnableWithProgress);
}

From source file:com.hsveclipse.phototoolkit.application.handlers.SaveHandler.java

License:Open Source License

@Execute
public void execute(IEclipseContext context, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
        @Named(IServiceConstants.ACTIVE_PART) final MContribution contribution)
        throws InvocationTargetException, InterruptedException {

    final IEclipseContext pmContext = context.createChild();

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    dialog.open();/*from  w ww.  java2  s. co  m*/
    dialog.run(true, true, new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            pmContext.set(IProgressMonitor.class.getName(), monitor);
            if (contribution != null) {
                Object clientObject = contribution.getObject();
                ContextInjectionFactory.invoke(clientObject, Persist.class, //$NON-NLS-1$
                        pmContext, null);
            }
        }
    });

    pmContext.dispose();
}

From source file:com.htmlhifive.tools.jslint.dialog.CreateEngineDialog.java

License:Apache License

@Override
protected void okPressed() {
    ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(getShell());
    DownloadEngineSupport support = createEngineDownload((Boolean) wvJslint.getValue());
    try {//  www  . jav  a 2s  .  co m
        IFile file = ResourcesPlugin.getWorkspace().getRoot()
                .getFile(new Path(wvOutputDir.getValue() + "/" + support.getEngine().getFileName()));
        if (file.exists()) {
            MessageBox box = new MessageBox(getShell(), SWT.OK | SWT.CANCEL | SWT.ICON_QUESTION);
            box.setMessage(Messages.DM0004.getText());
            box.setText(Messages.DT0011.getText());
            if (box.open() == SWT.CANCEL) {
                return;
            }
        }
        DownloadRunnable progress = new DownloadRunnable(support);
        progressDialog.run(true, false, progress);
        EngineInfo info = progress.getResult();
        if (info == null) {
            ErrorDialog.openError(getShell(), Messages.DT0003.getText(), Messages.EM0015.getText(),
                    ValidationStatus.error(Messages.EM0015.getText()));
            return;
        }
        ConfirmLicenseDialog dialog = new ConfirmLicenseDialog(getShell(),
                StringUtils.trim(info.getLicenseStr()), Messages.DT0009.getText());

        if (dialog.open() == IDialogConstants.OK_ID) {
            if (file.exists()) {
                file.setContents(new ByteArrayInputStream(info.getMainSource().getBytes()), IResource.FORCE,
                        null);
            } else {
                file.create(new ByteArrayInputStream(info.getMainSource().getBytes()), true, null);
            }
            this.engineFilePath = file.getFullPath().toString();
        } else {
            return;
        }
    } catch (InvocationTargetException e) {
        ErrorDialog.openError(getShell(), Messages.DT0003.getText(), Messages.EM0015.getText(),
                new Status(IStatus.ERROR, JSLintPlugin.PLUGIN_ID, e.getMessage(), e));
        logger.put(Messages.EM0100, e);
    } catch (InterruptedException e) {
        // ????????.
        throw new AssertionError();
    } catch (CoreException e) {
        ErrorDialog.openError(getShell(), Messages.DT0003.getText(), Messages.EM0016.getText(), e.getStatus());
        logger.put(Messages.EM0100, e);
    }

    super.okPressed();
}

From source file:com.htmlhifive.tools.wizard.RemoteContentManager.java

License:Apache License

/**
 * .//from ww w  .j a v a  2s  .co m
 * 
 * @param refresh 
 * @param shell 
 * @return 
 */
public static LibraryList getLibraryList(boolean refresh) {

    if (!refresh && H5WizardPlugin.getInstance().getLibraryList() != null) {
        return H5WizardPlugin.getInstance().getLibraryList();
    }

    // ?????
    H5WizardPlugin.getInstance().setLibraryList(null);
    H5WizardPlugin.getInstance().getSelectedLibrarySet().clear();

    ResultStatus resultStatus = new ResultStatus();

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);

    // ?.
    for (String urlStr : new String[] { PluginConstant.URL_LIBRARY_LIST, PluginConstant.URL_LIBRARY_LIST_MIRROR,
            LOCAL_LIBRARIES_XML }) {
        if (StringUtils.isNotEmpty(urlStr)) {
            InputStream is = null;
            DownloadModule downloadModule = new DownloadModule();
            try {

                //               IConnectMethod method = ConnectMethodFactory.getMethod(urlStr, true);
                //               method.setConnectionTimeout(PluginConstant.URL_LIBRARY_LIST_CONNECTION_TIMEOUT);
                //               method.setProxy(downloadModule.getProxyService());
                //               is = method.getInputStream();
                //               if (is == null) {
                //                  resultStatus.log(Messages.SE0046, urlStr);
                //               } else {
                //                  LibraryFileParser parser = LibraryFileParserFactory.createParser(is);
                //                  LibraryList libraryList = parser.getLibraryList();
                //                  libraryList.setLastModified(method.getLastModified());
                //                  libraryList.setSource(urlStr);
                //                  H5WizardPlugin.getInstance().setLibraryList(libraryList); // ??????.
                //                  return libraryList;
                //               }
                //            } catch (ParseException e) {
                //               resultStatus.log(e, Messages.SE0046, urlStr);
                //            } catch (MalformedURLException e) {
                //               resultStatus.log(e, Messages.SE0046, urlStr);
                //            } catch (IOException e) {
                //               resultStatus.log(e, Messages.SE0046, urlStr);

                //???
                final IRunnableWithProgress runnable = getSiteDownLoad(resultStatus, urlStr, downloadModule);

                try {
                    dialog.run(true, false, runnable);
                    if (resultStatus.isSuccess()) {
                        return H5WizardPlugin.getInstance().getLibraryList();
                    }
                } catch (InvocationTargetException e) {
                    resultStatus.log(e, Messages.SE0046, urlStr);
                } catch (InterruptedException e) {
                    resultStatus.log(e, Messages.SE0046, urlStr);
                }
            } finally {
                downloadModule.close();
                IOUtils.closeQuietly(is);
            }
        }
    }

    //      // ??.
    //      InputStream is = null;
    //      try {
    //         URLConnection connection = RemoteContentManager.class.getResource(LOCAL_LIBRARIES_XML).openConnection();
    //         is = connection.getInputStream();
    //         if (is == null) {
    //            resultStatus.log(Messages.SE0046, LOCAL_LIBRARIES_XML);
    //         } else {
    //            LibraryFileParser parser = LibraryFileParserFactory.createParser(is);
    //            LibraryList libraryList = parser.getLibraryList();
    //            if (connection.getLastModified() > 0) {
    //               libraryList.setLastModified(new Date(connection.getLastModified()));
    //            }
    //            libraryList.setSource(null);
    //            H5WizardPlugin.getInstance().setLibraryList(libraryList); // ??????.
    //            return libraryList;
    //         }
    //      } catch (ParseException e) {
    //         resultStatus.log(e, Messages.SE0046, LOCAL_LIBRARIES_XML);
    //      } catch (IOException e) {
    //         resultStatus.log(e, Messages.SE0046, LOCAL_LIBRARIES_XML);
    //      } finally {
    //         IOUtils.closeQuietly(is);
    //      }

    if (!resultStatus.isSuccess()) {
        // ?.
        resultStatus.falureDialog(Messages.PI0139, Messages.PI0140);
    }

    return null;
}

From source file:com.htmlhifive.tools.wizard.ui.property.LibraryImportPropertyPage.java

License:Apache License

/**
 * Nature??./*from www  . j av  a2  s  .  com*/
 * 
 * @param project 
 * @param natureId NatureID
 * @return ??????.
 */
private boolean addNature(IProject project, String natureId) {
    // JSNature?.
    if (MessageDialog.openQuestion(getShell(), Messages.SE0119.format(), Messages.SE0120.format(getTitle()))) {
        // ?.
        final ResultStatus logger = new ResultStatus();

        try {
            // .

            final IRunnableWithProgress downloadRunnable = getAddNatureRunnnable(logger, project, natureId);

            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
            dialog.run(false, false, downloadRunnable);

            // ?????.
            return true;
        } catch (InvocationTargetException e) {
            final Throwable ex = e.getTargetException();

            H5LogUtils.putLog(ex, Messages.SE0025);

        } catch (InterruptedException e) {
            logger.setInterrupted(true);
            // We were cancelled...
            //removeProject(logger);

        } finally {
            //               // ?.
            //               logger.showDialog(Messages.PI0138);
            if (logger.isSuccess()) {
                return true;
            }

            // ??(??).
            container.refreshTreeLibrary(false, true);
            // SE0103=INFO,?????
            logger.log(Messages.SE0103);
        }

    }
    return false;
}

From source file:com.htmlhifive.tools.wizard.ui.property.LibraryImportPropertyPage.java

License:Apache License

/**
 * {@inheritDoc}/*from  w  w w. j  av a 2 s.c om*/
 * 
 * @see org.eclipse.jface.preference.PreferencePage#performOk()
 */
@Override
public boolean performOk() {

    logger.log(Messages.TR0021, getClass().getName(), "performOk");

    if (!getApplyButton().isEnabled()) { // ?.
        return true;
    }

    // ????????.
    boolean needConfirmDialog = false;
    for (LibraryNode libraryNode : H5WizardPlugin.getInstance().getSelectedLibrarySet()) {
        if (libraryNode.isNeedConfirmDialog()) {
            needConfirmDialog = true;
        }
    }

    // ?.
    if (needConfirmDialog) {
        WizardDialog confirmLicenseWizardDialog = new WizardDialog(getShell(), new ConfirmLicenseWizard());
        confirmLicenseWizardDialog.setPageSize(getShell().getSize()); // ????.
        int ret = confirmLicenseWizardDialog.open();
        if (ret == SWT.ERROR) {
            // .
            return false;
        }
    }

    // ?.
    final ResultStatus logger = new ResultStatus();

    try {
        // .
        final IRunnableWithProgress downloadRunnable = getDownloadRunnnable(logger);

        ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
        dialog.run(false, false, downloadRunnable);

    } catch (InvocationTargetException e) {
        final Throwable ex = e.getTargetException();

        H5LogUtils.putLog(ex, Messages.SE0025);

    } catch (InterruptedException e) {
        logger.setInterrupted(true);
        // We were cancelled...
        //removeProject(logger);

        return false;
    } finally {
        // ?.
        logger.showDialog(Messages.PI0138);

        // ??(??).
        container.refreshTreeLibrary(false, true);
        // SE0103=INFO,?????
        logger.log(Messages.SE0103);
    }

    return logger.isSuccess();
}