Example #1
0
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.jface.wizard.IWizard#addPages()
   */
  public void addPages() {
    if (addingPages) return;

    try {
      addingPages = true;
      pages = new ArrayList<IWizardPage>();
      Iterator<WizardFragment> iterator = getAllWizardFragments().iterator();
      while (iterator.hasNext()) {
        WizardFragment fragment = (WizardFragment) iterator.next();
        FragmentedWizardPage page = getFragmentData(fragment);
        if (fragment.hasComposite()) {
          if (page != null) {
            addPage(page);
          } else {
            page = new FragmentedWizardPage(fragment);
            fragmentData.put(fragment, page);
            addPage(page);
          }
        }
      }
    } catch (Exception e) {
      PHPUiPlugin.log(
          new Status(
              IStatus.ERROR,
              PHPUiPlugin.ID,
              0,
              "Error adding fragments to wizard",
              e)); //$NON-NLS-1$
    } finally {
      addingPages = false;
    }
  }
Example #2
0
 protected boolean executeTask(WizardFragment fragment, byte type, IProgressMonitor monitor)
     throws CoreException {
   if (fragment == null) {
     return true;
   }
   if (type == FINISH) {
     return fragment.performFinish(monitor);
   } else if (type == CANCEL) {
     fragment.performCancel(monitor);
   }
   return true;
 }
Example #3
0
  private List<WizardFragment> getAllWizardFragments() {
    List<WizardFragment> list = new ArrayList<WizardFragment>();
    list.add(rootFragment);
    addSubWizardFragments(rootFragment, list);

    Iterator<WizardFragment> iterator = list.iterator();
    while (iterator.hasNext()) {
      WizardFragment fragment = (WizardFragment) iterator.next();
      if (!wizardModel.equals(fragment.getWizardModel())) {
        fragment.setWizardModel(wizardModel);
      }
    }
    return list;
  }
Example #4
0
 private void addSubWizardFragments(WizardFragment fragment, List<WizardFragment> list) {
   Iterator<?> iterator = fragment.getChildFragments().iterator();
   while (iterator.hasNext()) {
     WizardFragment child = (WizardFragment) iterator.next();
     list.add(child);
     addSubWizardFragments(child, list);
   }
 }
Example #5
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 #6
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;
  }