Search in sources :

Example 1 with WorkspaceRunnableAdapter

use of org.eclipse.wst.server.ui.internal.wizard.page.WorkspaceRunnableAdapter in project webtools.servertools by eclipse.

the class TaskWizard method performFinish.

public boolean performFinish() {
    if (currentFragment != null)
        currentFragment.exit();
    final WizardFragment cFragment = currentFragment;
    final List list = getAllWizardFragments();
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            // enter & exit the remaining pages
            int index = list.indexOf(cFragment);
            while (index > 0 && index < list.size() - 1) {
                final WizardFragment fragment = (WizardFragment) list.get(++index);
                try {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            fragment.enter();
                            fragment.exit();
                        }
                    });
                } catch (Exception e) {
                    if (Trace.WARNING) {
                        Trace.trace(Trace.STRING_WARNING, "Could not enter/exit page", e);
                    }
                }
            }
            if (useJob()) {
                class FinishWizardJob extends Job {

                    public FinishWizardJob() {
                        super(getJobTitle());
                    }

                    public boolean belongsTo(Object family) {
                        return "org.eclipse.wst.server.ui.family".equals(family);
                    }

                    public IStatus run(IProgressMonitor monitor2) {
                        try {
                            Iterator iterator = list.iterator();
                            while (iterator.hasNext()) executeTask((WizardFragment) iterator.next(), FINISH, monitor2);
                        } catch (CoreException ce) {
                            if (Trace.SEVERE) {
                                Trace.trace(Trace.STRING_SEVERE, "Error finishing wizard job", ce);
                            }
                            return new Status(IStatus.ERROR, ServerUIPlugin.PLUGIN_ID, 0, ce.getLocalizedMessage(), null);
                        }
                        return Status.OK_STATUS;
                    }
                }
                FinishWizardJob job = new FinishWizardJob();
                job.setUser(true);
                job.schedule();
            } else {
                Iterator iterator = list.iterator();
                while (iterator.hasNext()) executeTask((WizardFragment) iterator.next(), FINISH, monitor);
            }
        }
    };
    Throwable t = null;
    try {
        if (getContainer() != null)
            getContainer().run(true, true, new WorkspaceRunnableAdapter(runnable));
        else
            runnable.run(new NullProgressMonitor());
        return true;
    } catch (InvocationTargetException te) {
        if (Trace.SEVERE) {
            Trace.trace(Trace.STRING_SEVERE, "Error finishing task wizard", te);
        }
        t = te.getCause();
    } catch (InterruptedException interruptedEx) {
        if (Trace.INFO) {
            Trace.trace(Trace.STRING_INFO, "The task wizard was cancelled.", interruptedEx);
        }
        // return false since the request was canceled
        return false;
    } catch (Exception e) {
        if (Trace.SEVERE) {
            Trace.trace(Trace.STRING_SEVERE, "Error finishing task wizard 2", e);
        }
        t = e;
    }
    if (Trace.WARNING) {
        Trace.trace(Trace.STRING_WARNING, "Error completing wizard", t);
    }
    if (t instanceof CoreException) {
        EclipseUtil.openError(t.getLocalizedMessage(), ((CoreException) t).getStatus());
    } else if (t instanceof NullPointerException)
        EclipseUtil.openError("NullPointerException");
    else
        EclipseUtil.openError(t.getLocalizedMessage());
    return false;
}
Also used : DownloadableAdapterLicenseWizardFragment(org.eclipse.wst.server.ui.internal.wizard.fragment.DownloadableAdapterLicenseWizardFragment) WizardFragment(org.eclipse.wst.server.ui.wizard.WizardFragment) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) WorkspaceRunnableAdapter(org.eclipse.wst.server.ui.internal.wizard.page.WorkspaceRunnableAdapter) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 Job (org.eclipse.core.runtime.jobs.Job)1 DownloadableAdapterLicenseWizardFragment (org.eclipse.wst.server.ui.internal.wizard.fragment.DownloadableAdapterLicenseWizardFragment)1 WorkspaceRunnableAdapter (org.eclipse.wst.server.ui.internal.wizard.page.WorkspaceRunnableAdapter)1 WizardFragment (org.eclipse.wst.server.ui.wizard.WizardFragment)1