private static void buildFlexiblePath(
      final TreatmentCategorizationWizardPresentation pm,
      final JDialog dialog,
      final BranchingPath flexiblePath,
      final SpecifyDoseTypeWizardStep type,
      final SimplePath lastPath,
      final ValueModel condition) {
    final DoseRangeWizardStep lowerFirst = createFlexibleLowerDose(dialog, pm);
    final DoseRangeWizardStep upperFirst = createFlexibleUpperDose(dialog, pm);
    final BranchingPath lowerFirstPath = new BranchingPath(lowerFirst);
    final BranchingPath upperFirstPath = new BranchingPath(upperFirst);

    addBranch(
        flexiblePath,
        lowerFirstPath,
        new BooleanAndModel(condition, pm.getConsiderFlexibleLowerFirst()));
    addBranch(
        flexiblePath,
        upperFirstPath,
        new BooleanAndModel(condition, pm.getConsiderFlexibleUpperFirst()));

    addBranch(
        lowerFirstPath,
        createSimplePath(lastPath, createFlexibleUpperRanges(dialog, pm)),
        lowerFirst.getConsiderNextProperty());
    addBranch(
        upperFirstPath,
        createSimplePath(lastPath, createFlexibleLowerRanges(dialog, pm)),
        upperFirst.getConsiderNextProperty());
    addBranch(lowerFirstPath, lastPath, new BooleanNotModel(lowerFirst.getConsiderNextProperty()));
    addBranch(upperFirstPath, lastPath, new BooleanNotModel(upperFirst.getConsiderNextProperty()));
  }
 private static WizardStep createFlexibleLowerRanges(
     final JDialog dialog, final TreatmentCategorizationWizardPresentation pm) {
   return DoseRangeWizardStep.createOnMultipleParentRanges(
       dialog,
       pm,
       pm.getFlexibleUpperRanges(),
       "Specify the ranges for lower bound of flexible doses",
       "For each of the categories, define a range in which the lower bound of the administered dose must lie.");
 }
 private static DoseRangeWizardStep createFlexibleUpperDose(
     final JDialog dialog, final TreatmentCategorizationWizardPresentation pm) {
   return DoseRangeWizardStep.createOnBeanProperty(
       dialog,
       pm,
       pm.getFlexibleUpperRangeNode(),
       FlexibleDose.PROPERTY_MIN_DOSE,
       "Specify the ranges for upper bound of flexible doses",
       "For each of the categories, define a range in which the upper bound of the administered dose must lie.");
 }
 private static AbstractTreatmentCategorizationWizardStep createFixedDose(
     final JDialog dialog, final TreatmentCategorizationWizardPresentation pm) {
   return DoseRangeWizardStep.createOnBeanProperty(
       dialog,
       pm,
       pm.getFixedRangeNode(),
       null,
       "Specify ranges for fixed doses",
       "For each of the categories, define a range in which the administered dose must lie.");
 }
  private static WizardModel buildModel(
      final TreatmentCategorizationWizardPresentation pm, final JDialog dialog) {
    final AddTreatmentCategorizationWizardStep generalInfo =
        new AddTreatmentCategorizationWizardStep(pm, dialog);
    final SpecifyDoseTypeWizardStep type = new SpecifyDoseTypeWizardStep(pm, dialog);
    final TreatmentCategorizationOverviewWizardStep overview =
        new TreatmentCategorizationOverviewWizardStep(pm);

    final SimplePath lastPath = new SimplePath(overview);
    final BranchingPath typePath = new BranchingPath(type);
    final BranchingPath firstStep = new BranchingPath(generalInfo);
    final BranchingPath fixedAndFlexiblePath = new BranchingPath(createFixedDose(dialog, pm));

    final ValueModel considerFixed = pm.getConsiderFixed();
    buildFlexiblePath(
        pm, dialog, fixedAndFlexiblePath, type, lastPath, new UnmodifiableHolder<Boolean>(true));
    buildFlexiblePath(pm, dialog, typePath, type, lastPath, new BooleanNotModel(considerFixed));

    final ValueModel anyFlexibleDose =
        new BooleanOrModel(
            Arrays.<ValueModel>asList(
                pm.getConsiderFlexibleLowerFirst(), pm.getConsiderFlexibleUpperFirst()));

    addBranch(
        typePath,
        createSimplePath(lastPath, createFixedDose(dialog, pm)),
        new BooleanAndModel(new BooleanNotModel(anyFlexibleDose), considerFixed));

    addBranch(
        typePath,
        lastPath,
        new BooleanAndModel(
            new BooleanNotModel(anyFlexibleDose), new BooleanNotModel(considerFixed)));

    addBranch(typePath, fixedAndFlexiblePath, new BooleanAndModel(considerFixed, anyFlexibleDose));

    addBranch(
        firstStep,
        lastPath,
        new BooleanNotModel(new BooleanOrModel(pm.getConsiderDoseType(), pm.getIgnoreDoseType())));

    addBranch(firstStep, typePath, pm.getConsiderDoseType());

    addBranch(
        firstStep, createSimplePath(lastPath, createKnownDose(dialog, pm)), pm.getIgnoreDoseType());

    return new DynamicMultiPathModel(firstStep);
  }