Example usage for org.eclipse.jface.wizard IWizardContainer run

List of usage examples for org.eclipse.jface.wizard IWizardContainer run

Introduction

In this page you can find the example usage for org.eclipse.jface.wizard IWizardContainer run.

Prototype

public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
        throws InvocationTargetException, InterruptedException;

Source Link

Document

Runs the given IRunnableWithProgress in this context.

Usage

From source file:com.cloudbees.eclipse.ui.wizard.CBWizardSupport.java

License:Open Source License

public static JenkinsInstance[] getJenkinsInstances(final IWizardContainer container) throws Exception {
    JenkinsInstance[] result = null;/*  ww w .j a v a 2 s. com*/

    final List<JenkinsInstance> instances = new ArrayList<JenkinsInstance>();
    final Failure<CloudBeesException> failiure = new Failure<CloudBeesException>();

    IRunnableWithProgress operation = new IRunnableWithProgress() {

        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                monitor.beginTask("Fetching Jenkins instances", 0);
                CloudBeesUIPlugin plugin = CloudBeesUIPlugin.getDefault();

                monitor.subTask("loading local Jenkins instances...");
                List<JenkinsInstance> manualInstances = plugin.loadManualJenkinsInstances();

                monitor.subTask("loading DEV@cloud Jenkins instances...");
                List<JenkinsInstance> cloudInstances = plugin.loadDevAtCloudInstances(monitor);

                instances.addAll(manualInstances);
                instances.addAll(cloudInstances);
            } catch (CloudBeesException e) {
                failiure.cause = e;
            }
        }
    };

    try {
        container.run(true, false, operation);
        result = new JenkinsInstance[instances.size()];
        instances.toArray(result);
    } catch (Exception e) {
        if (failiure.cause != null) {
            throw failiure.cause;
        }
        throw e;
    }

    return result;
}

From source file:com.cloudbees.eclipse.ui.wizard.CBWizardSupport.java

License:Open Source License

public static List<JenkinsJobsResponse.Job> getJenkinsJobs(final IWizardContainer container,
        final JenkinsInstance instance) throws Exception {
    final CloudBeesUIPlugin plugin = CloudBeesUIPlugin.getDefault();
    final JenkinsService service = plugin.getJenkinsServiceForUrl(instance.url);
    final List<JenkinsJobsResponse.Job> jobsList = new ArrayList<JenkinsJobsResponse.Job>();
    final Failure<CloudBeesException> failiure = new Failure<CloudBeesException>();

    IRunnableWithProgress operation = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                String jobName = MessageFormat.format("Requesting {0} Jenkins jobs...", instance.username);
                monitor.beginTask(jobName, 0);

                monitor.subTask("Requesting Jenkins instance...");
                JenkinsInstanceResponse response = service.getInstance(monitor);

                monitor.subTask("Requesting Jenkins job list...");
                JenkinsJobsResponse jobs = service.getJobs(response.viewUrl, monitor);

                monitor.subTask("Processing jobs result");
                jobsList.addAll(Arrays.asList(jobs.jobs));

            } catch (CloudBeesException e) {
                failiure.cause = e;//from w  w  w.  j a  va  2s .co m
            } finally {
                monitor.done();
            }
        }
    };

    try {
        container.run(true, false, operation);
        return jobsList;
    } catch (Exception e) {
        if (failiure.cause != null) {
            throw failiure.cause;
        }
        throw e;
    }
}

From source file:com.cloudbees.eclipse.ui.wizard.CBWizardSupport.java

License:Open Source License

public static ForgeInstance[] getRepos(final IWizardContainer container, final ForgeInstance.TYPE type)
        throws Exception {
    final List<ForgeInstance> repos = new ArrayList<ForgeInstance>();
    final Failure<CloudBeesException> failiure = new Failure<CloudBeesException>();

    IRunnableWithProgress operation = new IRunnableWithProgress() {

        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                monitor.beginTask("Fetching forge repositories", 0);
                List<ForgeInstance> forgeRepos = CloudBeesUIPlugin.getDefault().getForgeRepos(monitor);
                if (type == null) {
                    repos.addAll(forgeRepos);
                } else {
                    for (ForgeInstance r : forgeRepos) {
                        if (r.type.equals(type)) {
                            repos.add(r);
                        }//from   ww w . j a  v a  2s.com
                    }
                }
            } catch (CloudBeesException e) {
                failiure.cause = e;
            }
        }
    };

    try {
        container.run(true, false, operation);
        return repos.toArray(new ForgeInstance[repos.size()]);
    } catch (Exception e) {
        if (failiure.cause != null) {
            throw failiure.cause;
        }
        throw e;
    }
}

From source file:com.cloudbees.eclipse.ui.wizard.CBWizardSupport.java

License:Open Source License

public static void makeJenkinsJob(final String configXML, final JenkinsService jenkinsService,
        final String jobName, final IWizardContainer container) throws Exception {

    final Failure<CloudBeesException> failiure = new Failure<CloudBeesException>();

    IRunnableWithProgress operation = new IRunnableWithProgress() {

        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                monitor.beginTask("Creating new Jenkins job...", 0);
                jenkinsService.createJenkinsJob(jobName, configXML, monitor);
            } catch (CloudBeesException e) {
                failiure.cause = e;//w  w  w  .j  a  v  a2s  . c o m
            }
        }

    };

    try {
        container.run(true, false, operation);
    } catch (Exception e) {
        if (failiure.cause != null) {
            throw failiure.cause;
        }
        throw e;
    }

}

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

License:Open Source License

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

    final AtomicReference<List<FogBugzFilter>> filtersRef = new AtomicReference<List<FogBugzFilter>>();

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

                    List<FogBugzFilter> filters = client.listFilters(monitor);

                    filtersRef.set(filters);

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

        wizard.run(true, true, runnable);

        filtersList.setInput(filtersRef.get());

        if (queryToEdit != null && filtersRef.get() != null) {
            IStructuredSelection sel = null;

            for (FogBugzFilter filter : filtersRef.get()) {
                if (filter.getFilterID().equals(queryToEdit.getFilterID())) {
                    sel = new StructuredSelection(filter);
                    break;
                }
            }

            if (sel != null) {
                filtersList.setSelection(sel, true);
            }
        }

    } catch (InvocationTargetException e) {
        FoglynUIPlugin.log("Cannot fetch list of filters from FogBugz", e.getCause());
        setErrorMessage("Cannot fetch list of filters from FogBugz");
    } catch (InterruptedException e) {
        FoglynUIPlugin.log("Cannot fetch list of filters from FogBugz", e);
        setErrorMessage("Cannot fetch list of filters from FogBugz");
    }
}

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

License:Open Source License

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

    final AtomicReference<List<FogBugzFilter>> filtersRef = new AtomicReference<List<FogBugzFilter>>();
    final AtomicReference<Collection<FogBugzProject>> projectsRef = new AtomicReference<Collection<FogBugzProject>>();
    final AtomicReference<Collection<FogBugzFixFor>> milestonesRef = new AtomicReference<Collection<FogBugzFixFor>>();
    final AtomicReference<FogBugzClient> fbclient = new AtomicReference<FogBugzClient>();

    try {/*from w w w.ja va  2  s  . com*/
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    monitor.beginTask("Fetching data from FogBugz server", IProgressMonitor.UNKNOWN);
                    FogBugzClient client = connector.getClientManager().getFogbugzClient(getTaskRepository(),
                            monitor);

                    filtersRef.set(client.listFilters(monitor));
                    projectsRef.set(client.getAllProjects());
                    milestonesRef.set(client.getAllFixFors());
                    fbclient.set(client);

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

        wizard.run(true, true, runnable);

        client = fbclient.get();
        filter.setInput(filtersRef.get());
        project.setInput(projectsRef.get());

        setupMilestones(fbclient.get(), milestonesRef.get());

        QueryType qt = null;
        if (query != null) {
            if (query instanceof FilterQuery && filtersRef.get() != null) {
                qt = QueryType.FILTER_CASES;

                FilterID fid = ((FilterQuery) query).getFilterID();
                for (FogBugzFilter f : filtersRef.get()) {
                    if (f.getFilterID().equals(fid)) {
                        filter.setSelection(new StructuredSelection(f), true);
                    }
                }
            }

            if (query instanceof AdvancedSearchQuery) {
                AdvancedSearchQuery asq = (AdvancedSearchQuery) query;

                if (asq.getProject() != null && projectsRef.get() != null) {
                    qt = QueryType.MY_PROJECT_CASES;

                    for (FogBugzProject p : projectsRef.get()) {
                        if (p.getID().equals(asq.getProject())) {
                            project.setSelection(new StructuredSelection(p), true);
                        }
                    }
                } else if (asq.getFixFor() != null && milestonesRef.get() != null) {
                    qt = QueryType.MY_MILESTONE_CASES;

                    for (FogBugzFixFor m : milestonesRef.get()) {
                        if (m.getID().equals(asq.getFixFor())) {
                            milestone.setSelection(new StructuredSelection(m), true);
                        }
                    }
                }
            }

            if (qt != null) {
                for (Button b : radioButtons) {
                    b.setSelection(qt.equals(b.getData(QUERY_TYPE_KEY)));
                }
            }

            updateViewers();

            queryName.setText(query.getQueryTitle());
        }
    } catch (InvocationTargetException e) {
        FoglynUIPlugin.log("Cannot fetch data from FogBugz", e.getCause());
        setErrorMessage("Cannot fetch data from FogBugz");
    } catch (InterruptedException e) {
        FoglynUIPlugin.log("Cannot fetch data from FogBugz", e);
        setErrorMessage("Cannot fetch data from FogBugz");
    }
}

From source file:com.mentor.nucleus.bp.core.ui.NewDomainWizard.java

License:Open Source License

public boolean performFinish() {
    myRunnable op = new myRunnable();
    m_useTemplate = m_creationPage.useTemplate();
    m_templateFile = m_creationPage.getTemplateLocationFieldValue();
    m_domainName = m_creationPage.getDomainNameFieldValue();
    m_parseOnImport = m_creationPage.parseOnImport();
    try {//from  ww  w .  ja  v  a 2  s  .  c om
        IWizardContainer container = getContainer();
        if (container != null) {
            container.run(false, false, op);
        } else {
            // For unit tests.
            op.run(new NullProgressMonitor());
        }
    } catch (InvocationTargetException e) {
        CorePlugin.logError("Internal error: " + e.getMessage(), e); //$NON-NLS-1$
        return false;
    } catch (InterruptedException e) {
        CorePlugin.logError("Internal error: " + e.getMessage(), e); //$NON-NLS-1$
        return false;
    }
    // Send an empty transaction to signal the work is done
    Transaction tr = null;
    try {
        tr = m_sys.getTransactionManager().startTransaction(m_sys.Get_name(), m_sys.getModelRoot(), false);

    } catch (TransactionException te) {
        CorePlugin.logError("Unable to create domain: Transaction already in progress.", te);
    } finally {
        if (tr != null) {
            m_sys.getTransactionManager().endTransaction(tr);
        }
    }
    // save page values
    m_creationPage.internalSaveWidgetValues();

    return op.result;
}

From source file:com.mentor.nucleus.bp.core.ui.NewSystemWizard.java

License:Open Source License

public boolean performFinish() {
    myRunnable op = new myRunnable();
    try {/*from w w w .  j  ava2 s  .  com*/
        IWizardContainer container = getContainer();
        if (container != null && !createdByUnitTest) {
            container.run(false, false, op);
        } else {
            //Unit test invoke it without setting container/progress monitor.
            return performCreateProject(new NullProgressMonitor());
        }

    } catch (InvocationTargetException e) {
        CorePlugin.logError("Internal error: " + e.getMessage(), e); //$NON-NLS-1$
        return false;
    } catch (InterruptedException e) {
        CorePlugin.logError("Internal error: " + e.getMessage(), e); //$NON-NLS-1$
        return false;
    }

    return op.result;
}

From source file:com.motorola.studio.android.model.ProjectCreationSupport.java

License:Apache License

/**
 * Run the operation in async thread.//from w  w  w . j av  a 2s .  c  om
 * @param op
 * @param container
 * 
 * @return true if no errors occur during the operation or false otherwise
 */
private static boolean runAsyncOperation(WorkspaceModifyOperation op, IWizardContainer container) {
    boolean created = false;

    try {
        container.run(true, true, op);
        created = true;
    } catch (InvocationTargetException ite) {
        Throwable t = ite.getTargetException();
        if (t instanceof CoreException) {
            CoreException core = (CoreException) t;
            if (core.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
                MessageDialog.openError(container.getShell(), AndroidNLS.UI_GenericErrorDialogTitle,
                        AndroidNLS.ERR_ProjectCreationSupport_CaseVariantExistsError);
            } else {
                ErrorDialog.openError(container.getShell(), AndroidNLS.UI_GenericErrorDialogTitle, null,
                        core.getStatus());
            }
        } else {
            MessageDialog.openError(container.getShell(), AndroidNLS.UI_GenericErrorDialogTitle,
                    t.getMessage());
        }
    } catch (InterruptedException e) {
        StudioLogger.error(ProjectCreationSupport.class, "Error creating project.", e); //$NON-NLS-1$
    }

    return created;
}

From source file:eu.geclipse.batch.ui.wizards.BatchServiceSelectionWizardPage.java

License:Open Source License

/**
 * @return TRUE if the Queue configuration has been committed to the selected batch services or
 * FALSE if not./*from w  w w .  ja  v  a 2 s . c  o m*/
 * 
 */
public boolean finish() {
    boolean result = true;

    if (isServiceSelectionValid()) {
        final Object[] checkedElements = this.treeViewer.getCheckedElements();
        final IWizardContainer container = getContainer();

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

                protected void testCanceled(final IProgressMonitor monitor) {
                    if (monitor.isCanceled()) {
                        throw new OperationCanceledException();
                    }
                }

                public void run(final IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    IBatchService batchWrapper = null;
                    BatchQueueDescription batchQueue = null;

                    SubMonitor betterMonitor = SubMonitor.convert(monitor, checkedElements.length);

                    for (Object element : checkedElements) {
                        testCanceled(betterMonitor);

                        if (element instanceof IBatchService) {
                            betterMonitor.setTaskName(String.format(
                                    Messages.getString("BatchServiceSelectionDialog.task.Service"), //$NON-NLS-1$ 
                                    ((IBatchService) element).getName()));

                            batchWrapper = (IBatchService) element;
                            testCanceled(betterMonitor);
                            for (IGridBatchQueueDescription queueDescription : BatchServiceSelectionWizardPage.this.queueDescList) {
                                batchQueue = (BatchQueueDescription) queueDescription;
                                //                try {
                                batchQueue.load(queueDescription.getResource().getFullPath().toString());
                                try {
                                    betterMonitor.setTaskName(String.format(
                                            Messages.getString(
                                                    "BatchServiceSelectionDialog.task.Configuration"), //$NON-NLS-1$ 
                                            queueDescription.getResource().getName()));
                                    batchWrapper.createQueue(batchQueue.getRoot());
                                    testCanceled(betterMonitor);
                                } catch (ProblemException e) {
                                    ProblemDialog.openProblem(getShell(),
                                            Messages.getString("AddQueueWizard.error_manipulate_title"), //$NON-NLS-1$
                                            Messages.getString("AddQueueWizard.error_manipulate_message"), //$NON-NLS-1$
                                            e);
                                }
                                //                } catch( ProblemException e ) {
                                //                  Activator.logException( e );
                                //                }
                            } // end for
                        } // end if ( element instanceof IBatchService )
                    }
                    betterMonitor.worked(1);
                }
            });
        } catch (InvocationTargetException itExc) {
            ProblemDialog.openProblem(getShell(),
                    Messages.getString("BatchServiceSelectionDialog.QueueConfigurationFailed"), //$NON-NLS-1$
                    Messages.getString("BatchServiceSelectionDialog.QueueConfigurationFailed"), //$NON-NLS-1$
                    itExc.getCause());
            result = false;
        } catch (InterruptedException intExc) {
            ProblemDialog.openProblem(getShell(),
                    Messages.getString("BatchServiceSelectionDialog.QueueConfigurationInterupted"), //$NON-NLS-1$
                    Messages.getString("BatchServiceSelectionDialog.QueueConfigurationInterupted"), //$NON-NLS-1$
                    intExc);
            result = false;
        }
    } // end if ( isServiceSelectionValid() )
    return result;
}