Example #1
0
  protected void switchWizardFragment(WizardFragment newFragment) {
    List<WizardFragment> list = getAllWizardFragments();
    int oldIndex = list.indexOf(currentFragment);
    int newIndex = list.indexOf(newFragment);
    if (oldIndex == newIndex) return;

    if (currentFragment != null) currentFragment.exit();

    if (oldIndex < newIndex) oldIndex++;
    else oldIndex--;

    while (oldIndex != newIndex) {
      WizardFragment fragment = (WizardFragment) list.get(oldIndex);
      fragment.enter();
      fragment.exit();
      if (oldIndex < newIndex) oldIndex++;
      else oldIndex--;
    }

    currentFragment = newFragment;
    currentFragment.enter();
  }
Example #2
0
  public boolean performFinish() {
    if (currentFragment != null) currentFragment.exit();

    final WizardFragment cFragment = currentFragment;

    status = Status.OK_STATUS;

    final List<WizardFragment> list = getAllWizardFragments();
    IRunnableWithProgress runnable =
        new IRunnableWithProgress() {
          public void run(IProgressMonitor monitor) {
            // 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() {
                            FragmentedWizardPage page = getFragmentData(fragment);
                            if (page.getControl() == null && pageContainerHook != null) {
                              page.createControl(pageContainerHook);
                            }
                            fragment.enter();
                            fragment.exit();
                          }
                        });
              } catch (Exception e) {
                PHPUiPlugin.log(
                    new Status(
                        IStatus.ERROR,
                        PHPUiPlugin.ID,
                        0,
                        "Could not enter/exit page",
                        e)); //$NON-NLS-1$
              }
            }

            if (useJob()) {
              class FinishWizardJob extends Job {
                public FinishWizardJob() {
                  super(getJobTitle());
                }

                public boolean belongsTo(Object family) {
                  return "org.eclipse.wst.server.ui.family".equals(family); // $NON-NLS-1$
                }

                public IStatus run(IProgressMonitor monitor2) {
                  try {
                    Iterator<WizardFragment> iterator = list.iterator();
                    while (iterator.hasNext()) executeTask(iterator.next(), FINISH, monitor2);
                  } catch (CoreException ce) {
                    Status status =
                        new Status(
                            IStatus.ERROR, PHPUiPlugin.ID, 0, ce.getLocalizedMessage(), null);
                    PHPUiPlugin.log(status);
                    return status;
                  }
                  return Status.OK_STATUS;
                }
              }

              FinishWizardJob job = new FinishWizardJob();
              job.setUser(true);
              job.schedule();
            } else {
              Iterator<WizardFragment> iterator = list.iterator();
              while (iterator.hasNext())
                try {
                  WizardFragment fragment = (WizardFragment) iterator.next();
                  if (!executeTask(fragment, FINISH, monitor)) {
                    status =
                        new Status(
                            IStatus.ERROR,
                            PHPUiPlugin.ID,
                            "Error during wizard page execution."); //$NON-NLS-1$
                  }
                } catch (CoreException e) {
                  PHPUiPlugin.log(e);
                }
            }
          }
        };

    Throwable t = null;
    try {
      if (getContainer() != null) getContainer().run(true, true, runnable);
      else runnable.run(new NullProgressMonitor());
      if (status.getSeverity() != IStatus.OK) {
        return false;
      }
      return true;
    } catch (InvocationTargetException te) {
      PHPUiPlugin.log(
          new Status(
              IStatus.ERROR, PHPUiPlugin.ID, 0, "Error finishing task wizard", te)); // $NON-NLS-1$
      t = te.getCause();
    } catch (Exception e) {
      PHPUiPlugin.log(
          new Status(
              IStatus.ERROR, PHPUiPlugin.ID, 0, "Error finishing task wizard 2", e)); // $NON-NLS-1$
      t = e;
    }
    if (t instanceof CoreException) {
      openError(t.getLocalizedMessage(), ((CoreException) t).getStatus());
    } else if (t instanceof NullPointerException) openError(PHPUIMessages.FragmentedWizard_7);
    else openError(t.getLocalizedMessage());

    return false;
  }