Search in sources :

Example 1 with AbstractDelegatingMonitorJob

use of org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob in project jbosstools-openshift by jbosstools.

the class RefreshResourceHandler method createRefreshJob.

private Job createRefreshJob(IOpenshiftUIElement<?, ?> element) {
    return new AbstractDelegatingMonitorJob(LOADING_OPEN_SHIFT_INFORMATIONS) {

        @Override
        protected IStatus doRun(IProgressMonitor monitor) {
            try {
                monitor.beginTask(LOADING_OPEN_SHIFT_INFORMATIONS, IProgressMonitor.UNKNOWN);
                element.refresh();
            } catch (OpenShiftException e) {
                OpenShiftCommonUIActivator.getDefault().getLogger().logError(FAILED_TO_REFRESH_ELEMENT, e);
                return new Status(Status.ERROR, OpenShiftCommonUIActivator.PLUGIN_ID, FAILED_TO_REFRESH_ELEMENT, e);
            } finally {
                monitor.done();
            }
            return Status.OK_STATUS;
        }
    };
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) AbstractDelegatingMonitorJob(org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) OpenShiftException(com.openshift.restclient.OpenShiftException)

Example 2 with AbstractDelegatingMonitorJob

use of org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob in project jbosstools-openshift by jbosstools.

the class BuildConfigWizardPage method loadBuildConfigs.

private void loadBuildConfigs(final IBuildConfigPageModel model) {
    try {
        AbstractDelegatingMonitorJob job = new AbstractDelegatingMonitorJob("Loading build configs...") {

            @Override
            protected IStatus doRun(IProgressMonitor monitor) {
                model.loadBuildConfigs();
                return Status.OK_STATUS;
            }
        };
        WizardUtils.runInWizard(job, job.getDelegatingProgressMonitor(), getContainer());
    } catch (InvocationTargetException | InterruptedException e) {
    // intentionnally swallowed
    }
}
Also used : AbstractDelegatingMonitorJob(org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with AbstractDelegatingMonitorJob

use of org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob in project jbosstools-openshift by jbosstools.

the class DeployImageHandler method runWizard.

public void runWizard(final Shell shell, final IDockerConnection dockerConnection, final IDockerImage image, final IProject project, final Connection connection) {
    if (connection != null) {
        final boolean[] authorized = new boolean[1];
        Job job = new AbstractDelegatingMonitorJob("Checking connection...") {

            @Override
            protected IStatus doRun(IProgressMonitor monitor) {
                try {
                    authorized[0] = connection.isAuthorized(new NullProgressMonitor());
                    return Status.OK_STATUS;
                } catch (Exception e) {
                    return new Status(Status.ERROR, OpenShiftUIActivator.PLUGIN_ID, "Unable to load the OpenShift projects for the selected connection.", e);
                }
            }
        };
        job.addJobChangeListener(new JobChangeAdapter() {

            @Override
            public void done(IJobChangeEvent event) {
                shell.getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        DeployImageWizard wizard = new DeployImageWizard(dockerConnection, image, connection, project, authorized[0]);
                        WizardUtils.openWizardDialog(500, 500, wizard, shell);
                    }
                });
            }
        });
        job.schedule();
    } else {
        DeployImageWizard wizard = new DeployImageWizard(dockerConnection, image, connection, project, false);
        WizardUtils.openWizardDialog(600, 1500, wizard, shell);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) AbstractDelegatingMonitorJob(org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) AbstractDelegatingMonitorJob(org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob) Job(org.eclipse.core.runtime.jobs.Job) ExecutionException(org.eclipse.core.commands.ExecutionException) DeployImageWizard(org.jboss.tools.openshift.internal.ui.wizard.deployimage.DeployImageWizard)

Example 4 with AbstractDelegatingMonitorJob

use of org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob 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

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 AbstractDelegatingMonitorJob (org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob)4 IStatus (org.eclipse.core.runtime.IStatus)3 OpenShiftException (com.openshift.restclient.OpenShiftException)2 Status (org.eclipse.core.runtime.Status)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 Job (org.eclipse.core.runtime.jobs.Job)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1 UIJob (org.eclipse.ui.progress.UIJob)1 Connection (org.jboss.tools.openshift.core.connection.Connection)1 JobChainBuilder (org.jboss.tools.openshift.internal.common.core.job.JobChainBuilder)1 ObservableTreeItem2ModelConverter (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter)1 DeployImageWizard (org.jboss.tools.openshift.internal.ui.wizard.deployimage.DeployImageWizard)1 NewProjectWizard (org.jboss.tools.openshift.internal.ui.wizard.project.NewProjectWizard)1