예제 #1
0
  /**
   * Builds a wizard from the supplied list of paths.
   *
   * <p>The first path in the list is expected to be the main path.
   *
   * @param _paths The list of paths.
   * @param _consoleMode true if running in console mode, false otherwise.
   * @return The Wizard.
   */
  public static Wizard build(List _paths, boolean _consoleMode) {
    consoleMode = _consoleMode;

    if (_paths.size() == 0) {
      throw new BuildException("No paths defined.");
    }

    Path main = (Path) _paths.get(0);
    Map paths = new HashMap();
    for (int ii = 1; ii < _paths.size(); ii++) {
      Path path = (Path) _paths.get(ii);
      paths.put(path.getName(), path);
    }

    org.pietschy.wizard.models.Path mainPath = buildPath(main, paths);

    if (_consoleMode) {
      return new ConsoleWizard(new MultiPathModel(mainPath));
    }

    // GuiWizard is unable to register itself as a listener before the first
    // activeStep event is fired, so queue it up here and fire again after
    // GuiWizard is ready.
    MultiPathModel model = new MultiPathModel(mainPath);
    TempPropertyChangeListener listener = new TempPropertyChangeListener();
    model.addPropertyChangeListener(listener);
    GuiWizard wizard = new GuiWizard(model);
    wizard.setEventQueue(listener.getEvents());
    model.removePropertyChangeListener(listener);

    return wizard;
  }
예제 #2
0
  /**
   * Builds a wizard path from the supplied ant path.
   *
   * @param _path The ant path.
   * @param _paths A map of all other paths (except the main one).
   * @return The wizard path.
   */
  private static org.pietschy.wizard.models.Path buildPath(Path _path, Map _paths) {
    // add steps and branches.
    org.pietschy.wizard.models.Path path = null;
    for (int ii = _path.getSteps().size() - 1; ii >= 0; ii--) {
      Object next = _path.getSteps().get(ii);

      // steps
      if (next instanceof Step) {
        Step step = (Step) next;
        Log.debug("Adding step '" + step.getName() + "' to path '" + _path.getName() + "'");
        SimplePath simplePath =
            new SimplePath(
                step.getName(),
                (org.pietschy.wizard.WizardStep) getStep(step.getName(), step.getProperties()));
        if (path != null) {
          Log.debug(
              "Setting next path for '"
                  + getPathName(simplePath)
                  + "' to path '"
                  + getPathName(path)
                  + "'");
          simplePath.setNextPath(path);
        }
        path = simplePath;

        // branches
      } else {
        Branch branch = (Branch) next;
        if (!_paths.containsKey(branch.getPath())) {
          throw new BuildException(
              "No path '" + branch.getPath() + "' found for branch in '" + _path.getName() + "'");
        }

        Log.debug("Adding branch '" + branch.getPath() + "' to path '" + _path.getName() + "'");
        org.pietschy.wizard.models.Path branchPath =
            buildPath((Path) _paths.get(branch.getPath()), _paths);

        if (branchPath instanceof SimplePath) {
          Log.debug(
              "Setting next path for '"
                  + getPathName(branchPath)
                  + "' to path '"
                  + getPathName(path)
                  + "'");
          ((SimplePath) branchPath).setNextPath(path);
        }

        BranchingPath branchingPath = new BranchingPath(branch.getPath());
        branchingPath.addBranch(0, branchPath, new WizardCondition(branch));
        if (path != null) {
          Log.debug(
              "Adding static path for '"
                  + getPathName(branchingPath)
                  + "' containing path '"
                  + getPathName(path)
                  + "'");
          branchingPath.addBranch(path, new StaticCondition(true));
        }
        path = branchingPath;
      }
    }

    return path;
  }