Beispiel #1
0
  /**
   * Creates a new checkpoint for {@link AbstractModel#revert()} to revert to, if called, and clears
   * the dirty state (including that of added inner {@link AbstractModel}-s).
   */
  public void checkpoint() {
    provider.checkpoint();

    for (AbstractModel<?> model : models) {
      model.checkpoint();
    }
  }
Beispiel #2
0
  /**
   * Make this {@link AbstractModel}'s dirty value depend on the inner {@link AbstractModel}-s, if
   * there are any.
   */
  private void updateDirtyDelegate() {
    List<ValueModel<Boolean>> values = new ArrayList<ValueModel<Boolean>>();
    values.add(provider.dirty());

    for (AbstractModel<?> model : models) {
      values.add(model.dirty());
    }

    dirty.setDelegate(new ReducingCondition(new OrFunction(), values));
  }
Beispiel #3
0
  /**
   * Reverts this {@link AbstractModel} to the value it was originally provided with (via {@link
   * AbstractModel#setValue(Object)}) or the value when {@link AbstractModel#checkpoint()} was last
   * called.
   */
  public void revert() {
    provider.revert();

    // revert inner models before checkpoint()-ing, otherwise the inner
    // models will revert to the checkpoint we just made (and not their
    // "original" value, which would have been overwritten by the
    // checkpoint).
    for (AbstractModel<?> model : models) {
      model.revert();
    }

    checkpoint();
  }
Beispiel #4
0
  /**
   * Binds a field to a model. The {@link FieldModel} <em>must</em> belong to this {@link
   * FormModel}.
   *
   * <p>Adds a {@link AbstractModel} to this {@link AbstractModel}, so that the former is reverted,
   * checkpoint-ed, validated, bound, unbound, dirty-checked, etc. whenever this {@link
   * AbstractModel} is.
   *
   * @param field bound to the model.
   * @param model bound to the field.
   * @param binder used to bind the model and field.
   */
  public <E> void bind(FieldModel<E> field, AbstractModel<E> model) {
    if (!field.getFormModel().equals(this)) {
      throw new IllegalArgumentException("field is not from this model");
    }

    models.add(model);
    binder.bind(field).to(model.getMutableValueModel());

    validationTree.add(model.validationTree);
  }
Beispiel #5
0
 private void unbindModels() {
   for (AbstractModel<?> model : models) {
     model.unbind();
   }
 }