Search in sources :

Example 1 with NewProjectWizard

use of org.jboss.tools.openshift.internal.ui.wizard.project.NewProjectWizard in project jbosstools-openshift by jbosstools.

the class AbstractProjectPage method getLoadResourcesJobBuilder.

/**
 * Create and configure the list of jobs that need to be performed during
 * resource loading. The base behavior is to load the projects and force project
 * creation if no project exists.
 *
 * @param closeAfter
 *            return parameter if wizard needs to be closed (may be updated)
 * @param closeOnCancel
 *            true if the wizard need to be closed
 * @return the job builder
 */
protected JobChainBuilder getLoadResourcesJobBuilder(final boolean[] closeAfter, final boolean closeOnCancel) {
    JobChainBuilder builder = new JobChainBuilder(new AbstractDelegatingMonitorJob("Loading projects...") {

        @Override
        protected IStatus doRun(IProgressMonitor monitor) {
            try {
                model.loadResources();
            } catch (OpenShiftException e) {
                closeAfter[0] = closeOnCancel;
                String problem = e.getStatus() == null ? e.getMessage() : e.getStatus().getMessage();
                return OpenShiftUIActivator.statusFactory().errorStatus(problem, e);
            }
            return Status.OK_STATUS;
        }
    });
    builder.runWhenSuccessfullyDone(new UIJob("Verifying required project...") {

        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            if (!model.hasProjects()) {
                List<IProject> projects = new ObservableTreeItem2ModelConverter().convert(model.getProjectItems());
                Connection connection = model.getConnection();
                NewProjectWizard newProjectWizard = new NewProjectWizard(connection, projects);
                if (Dialog.CANCEL == WizardUtils.openWizardDialog(newProjectWizard, getShell())) {
                    closeAfter[0] = closeOnCancel;
                    return Status.CANCEL_STATUS;
                } else {
                    model.loadResources();
                    model.setProject(newProjectWizard.getProject());
                }
            }
            return Status.OK_STATUS;
        }
    });
    return builder;
}
Also used : AbstractDelegatingMonitorJob(org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) OpenShiftException(com.openshift.restclient.OpenShiftException) Connection(org.jboss.tools.openshift.core.connection.Connection) UIJob(org.eclipse.ui.progress.UIJob) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) List(java.util.List) NewProjectWizard(org.jboss.tools.openshift.internal.ui.wizard.project.NewProjectWizard) JobChainBuilder(org.jboss.tools.openshift.internal.common.core.job.JobChainBuilder)

Aggregations

OpenShiftException (com.openshift.restclient.OpenShiftException)1 List (java.util.List)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 UIJob (org.eclipse.ui.progress.UIJob)1 Connection (org.jboss.tools.openshift.core.connection.Connection)1 AbstractDelegatingMonitorJob (org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob)1 JobChainBuilder (org.jboss.tools.openshift.internal.common.core.job.JobChainBuilder)1 ObservableTreeItem2ModelConverter (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter)1 NewProjectWizard (org.jboss.tools.openshift.internal.ui.wizard.project.NewProjectWizard)1