Example usage for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress

List of usage examples for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress

Introduction

In this page you can find the example usage for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress.

Prototype

IRunnableWithProgress

Source Link

Usage

From source file:com.ebmwebsourcing.petals.services.su.wizards.pages.JbiProvidePage.java

License:Open Source License

/**
 * Runs the WSDL parsing and updates the WSDL text decoration.
 * @param wsdlUrl the URL of the WSDL to parse
 *///www.java  2 s .  co m
private void runWsdlParsing() {

    // The runnable
    IRunnableWithProgress wsdlParsingOperation = new IRunnableWithProgress() {
        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException {

            monitor.beginTask(Messages.ProvideJbiPage_24, 2);
            monitor.worked(1);
            JbiProvidePage.this.wsdlParsingError = null;
            JbiProvidePage.this.jbiBasicBeans.clear();
            try {
                if (!StringUtils.isEmpty(JbiProvidePage.this.wsdlUrl)) {
                    JbiProvidePage.this.jbiBasicBeans
                            .addAll(WsdlUtils.INSTANCE.parse(JbiProvidePage.this.wsdlUrl));
                    if (JbiProvidePage.this.jbiBasicBeans.isEmpty())
                        JbiProvidePage.this.wsdlParsingError = "The WSDL does not contain any service desription.";
                }

            } catch (IllegalArgumentException e1) {
                JbiProvidePage.this.wsdlParsingError = "The WSDL URI is invalid.";

            } catch (InvocationTargetException e1) {
                JbiProvidePage.this.wsdlParsingError = Messages.ProvideJbiPage_25;

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

    // Run it
    try {
        getContainer().run(true, false, wsdlParsingOperation);

    } catch (Exception e) {
        PetalsServicesPlugin.log(e, IStatus.ERROR);
    }

    // Update the UI
    JbiProvidePage.this.wsdlTextDecoration.setDescriptionText(this.wsdlParsingError);
    if (this.wsdlParsingError == null)
        JbiProvidePage.this.wsdlTextDecoration.hide();
    else
        JbiProvidePage.this.wsdlTextDecoration.show();

    int size = this.jbiBasicBeans.size();
    if (size > 1)
        this.wsdlHelper.getLink()
                .setText("<A>Select another service</A> in the WSDL" + " (" + size + " available)");
    else if (size == 1)
        this.wsdlHelper.getLink()
                .setText("<A>Restore from the WSDL values</A>" + " (" + size + " service available)");

    this.wsdlHelper.setVisible(size > 0);
    this.wsdlHelper.layout();

    if (this.jbiBasicBeans.size() > 0)
        selectJbiBasicBean(this.jbiBasicBeans.get(0));
}

From source file:com.eco.bio7.scenebuilder.wizard.JavaFXWizard.java

License:Open Source License

public boolean performFinish() {
    final String containerName = page.getContainerName();
    final String fileName = page.getFileName();
    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                doFinish(containerName, fileName, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();// w w  w . j  a  v a2 s .c o m
            }
        }
    };
    try {
        getContainer().run(true, false, op);
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        Throwable realException = e.getTargetException();
        MessageDialog.openError(getShell(), "Error", realException.getMessage());
        return false;
    }
    return true;
}

From source file:com.elphel.vdt.core.launching.LaunchCore.java

License:Open Source License

/**
 * Launches the given run configuration in the foreground with a progress 
 * dialog. Reports any exceptions that occur in an error dialog.
 *//*from  www.j av  a 2 s .com*/
// Never used - where it was supposed to be called from? //
public static void launchInForeground(final VDTRunnerConfiguration configuration) {
    if (!saveAllEditors(true)) {
        return;
    }
    System.out.println("launchInForeground, JOB_NAME=" + JOB_NAME);

    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                launch(configuration, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            }
        }
    };

    try {
        PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable);
    } catch (InvocationTargetException e) {
        handleInvocationTargetException(e);
    } catch (InterruptedException e) {
    }

}

From source file:com.embedthis.ejs.ide.wizards.EJScriptNewBCWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    final String containerName = page.getContainerName();
    final String fileName = page.getFileName();
    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                doFinish(containerName, fileName, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();/*from w  w  w .j av a  2  s . co m*/
            }
        }
    };
    try {
        getContainer().run(true, false, op);
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        Throwable realException = e.getTargetException();
        MessageDialog.openError(getShell(), "Error", realException.getMessage());
        return false;
    }
    return true;
}

From source file:com.essiembre.eclipse.rbe.ui.wizards.ResourceBundleWizard.java

License:Apache License

/**
 * This method is called when 'Finish' button is pressed in
 * the wizard. We will create an operation and run it
 * using wizard as execution context.//from ww w  .  j  av a 2 s  . c  o  m
 */
public boolean performFinish() {
    final String containerName = page.getContainerName();
    final String baseName = page.getFileName();
    final String[] locales = page.getLocaleStrings();
    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                monitor.worked(1);
                monitor.setTaskName(RBEPlugin.getString("editor.wiz.creating"));
                IFile file = null;
                for (int i = 0; i < locales.length; i++) {
                    String fileName = baseName;
                    if (locales[i].equals(ResourceBundleNewWizardPage.DEFAULT_LOCALE)) {
                        fileName += ".properties";
                    } else {
                        fileName += "_" + locales[i] + ".properties";
                    }
                    file = createFile(containerName, fileName, monitor);
                }
                final IFile lastFile = file;
                getShell().getDisplay().asyncExec(new Runnable() {
                    public void run() {
                        IWorkbenchPage wbPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
                                .getActivePage();
                        try {
                            IDE.openEditor(wbPage, lastFile, true);
                        } catch (PartInitException e) {
                        }
                    }
                });
                monitor.worked(1);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
            }
        }
    };
    try {
        getContainer().run(true, false, op);
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        Throwable realException = e.getTargetException();
        MessageDialog.openError(getShell(), "Error", realException.getMessage());
        return false;
    }
    return true;
}

From source file:com.example.app.bootstrapper.Application.java

License:Open Source License

private boolean installNewFeature() throws ProvisionException {

    /*//  ww  w .ja  v a 2 s  .c o m
     * Check to make sure that we are not restarting after an update. If we
     * are, then there is no need to check for updates again.
     */
    final IPreferenceStore prefStore = Activator.getDefault().getPreferenceStore();
    if (prefStore.getBoolean(JUSTUPDATED)) {
        prefStore.setValue(JUSTUPDATED, false);
        return false;
    }

    final IProvisioningAgent agent = this.getProvisioningAgent();

    /*
     * Create a runnable to execute the update. We'll show a dialog during
     * the process and then return when the runnable is complete.
     */
    final boolean[] restartRequired = new boolean[] { false };
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            IStatus installStatus = doInstallOperation(agent, monitor);
            if (installStatus.getSeverity() != IStatus.ERROR) {
                prefStore.setValue(JUSTUPDATED, true);
                restartRequired[0] = true;
            } else {
                log(installStatus);
            }
        }
    };

    /*
     * Execute the runnable and wait for it to complete.
     */
    try {
        new ProgressMonitorDialog(null).run(true, true, runnable);
        return restartRequired[0];
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
    }
    return false;
}

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 {//from w ww . j ava  2s  . 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 {/*from   w  ww  .java 2  s  . c  om*/
        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.FoglynAdvancedSearchPage.java

License:Open Source License

private void initializePage(IRunnableContext runnableContext) {
    final FoglynRepositoryConnector connector = (FoglynRepositoryConnector) TasksUi.getRepositoryManager()
            .getRepositoryConnector(FoglynCorePlugin.CONNECTOR_KIND);

    final AtomicReference<FogBugzClient> clientRef = new AtomicReference<FogBugzClient>(null);

    try {//from   ww w . java2 s  .  co m
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    monitor.beginTask("Fetching repository details", IProgressMonitor.UNKNOWN);
                    FogBugzClient client = connector.getClientManager().getFogbugzClient(getTaskRepository(),
                            monitor);

                    clientRef.set(client);

                    monitor.done();
                } catch (CoreException e) {
                    throw new InvocationTargetException(e, e.getMessage());
                }
            }
        };

        runnableContext.run(true, true, runnable);
    } catch (InvocationTargetException e) {
        FoglynUIPlugin.log("Cannot fetch repository data from FogBugz", e);
        setErrorMessage("Cannot fetch repository data from FogBugz");
    } catch (InterruptedException e) {
        FoglynUIPlugin.log("Cannot fetch repository data from FogBugz", e);
        setErrorMessage("Cannot fetch repository data from FogBugz");
    }

    FogBugzClient client = clientRef.get();
    if (client != null) {
        setupComponentsFromClient(client);
    }

    if (inSearchContainer()) {
        restoreState();
    } else if (initialQuery != null) {
        setupComponentsFromInitialQuery();
    }
}

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

License:Open Source License

private void updateRepositoryValues(IRunnableContext runnableContext) {
    final FoglynRepositoryConnector connector = (FoglynRepositoryConnector) TasksUi.getRepositoryManager()
            .getRepositoryConnector(FoglynCorePlugin.CONNECTOR_KIND);

    final AtomicReference<FogBugzClient> clientRef = new AtomicReference<FogBugzClient>(null);

    try {//from  www.  j av a 2s  .  com
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    monitor.beginTask("Updating repository configuration", IProgressMonitor.UNKNOWN);
                    connector.updateRepositoryConfiguration(getTaskRepository(), monitor);

                    FogBugzClient client = connector.getClientManager().getFogbugzClient(getTaskRepository(),
                            monitor);

                    clientRef.set(client);

                    monitor.done();
                } catch (CoreException e) {
                    throw new InvocationTargetException(e, e.getMessage());
                }
            }
        };

        runnableContext.run(true, true, runnable);
    } catch (InvocationTargetException e) {
        FoglynUIPlugin.log("Cannot fetch repository data from FogBugz", e);
        setErrorMessage("Cannot fetch repository data from FogBugz");
    } catch (InterruptedException e) {
        FoglynUIPlugin.log("Cannot fetch repository data from FogBugz", e);
        setErrorMessage("Cannot fetch repository data from FogBugz");
    }

    FogBugzClient client = clientRef.get();
    if (client != null) {
        setupComponentsFromClient(client);
    }
}