<commit_before>package org.springframework.binding.form.support;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Iterator;

import org.springframework.binding.value.ValueChangeDetector;
import org.springframework.binding.value.ValueModel;
import org.springframework.binding.value.support.AbstractValueModelWrapper;
import org.springframework.binding.value.support.DirtyTrackingValueModel;
import org.springframework.binding.value.support.ValueHolder;
import org.springframework.richclient.application.Application;
import org.springframework.richclient.util.EventListenerListHelper;

/**
 * A value model wrapper that mediates between the (wrapped) data value model and the 
 * derived view value model. Allows for disconnection/reconnection of view and data models.
 * 
 * @author <NAME>
 */
public class FormModelMediatingValueModel extends AbstractValueModelWrapper implements DirtyTrackingValueModel,
        PropertyChangeListener {

    private final EventListenerListHelper dirtyChangeListeners = new EventListenerListHelper(
            PropertyChangeListener.class);

    private boolean disconectViewFromData = false;

    private final ValueHolder mediatedValueHolder;

    private Object originalValue;

    private boolean oldDirty;

    private final boolean trackDirty;

    private ValueChangeDetector valueChangeDetector;

    public FormModelMediatingValueModel(ValueModel propertyValueModel) {
        this(propertyValueModel, true);
    }

    public FormModelMediatingValueModel(ValueModel propertyValueModel, boolean trackDirty) {
        super(propertyValueModel);
        super.addValueChangeListener(this);
        this.originalValue = propertyValueModel.getValue();
        this.mediatedValueHolder = new ValueHolder(originalValue);
        this.trackDirty = trackDirty;
    }

    public Object getValue() {
        return mediatedValueHolder.getValue();
    }

    public void setValueSilently(Object value, PropertyChangeListener listenerToSkip) {
        if (disconectViewFromData) {
            throw new IllegalStateException("View attempted to set value to data model when data model was disconnected");
        }
        getWrappedValueModel().setValueSilently(value, this);
        mediatedValueHolder.setValueSilently(value, listenerToSkip);
        updateDirtyState();
    }

    // called by the wrapped value model
    public void propertyChange(PropertyChangeEvent evt) {
        originalValue = getWrappedValueModel().getValue();<commit_msg>Disconnected value models should still be readable and writeable but should not deliver change events.<commit_after>package org.springframework.binding.form.support;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Iterator;

import org.springframework.binding.value.ValueChangeDetector;
import org.springframework.binding.value.ValueModel;
import org.springframework.binding.value.support.AbstractValueModelWrapper;
import org.springframework.binding.value.support.DirtyTrackingValueModel;
import org.springframework.binding.value.support.ValueHolder;
import org.springframework.richclient.application.Application;
import org.springframework.richclient.util.EventListenerListHelper;

/**
 * A value model wrapper that mediates between the (wrapped) data value model and the 
 * derived view value model. Allows for disconnection/reconnection of view and data models.
 * 
 * @author <NAME>
 */
public class FormModelMediatingValueModel extends AbstractValueModelWrapper implements DirtyTrackingValueModel,
        PropertyChangeListener {

    private final EventListenerListHelper dirtyChangeListeners = new EventListenerListHelper(
            PropertyChangeListener.class);

    private boolean disconectViewFromData = false;

    private final ValueHolder mediatedValueHolder;

    private Object originalValue;

    private boolean oldDirty;

    private final boolean trackDirty;

    private ValueChangeDetector valueChangeDetector;

    public FormModelMediatingValueModel(ValueModel propertyValueModel) {
        this(propertyValueModel, true);
    }

    public FormModelMediatingValueModel(ValueModel propertyValueModel, boolean trackDirty) {
        super(propertyValueModel);
        super.addValueChangeListener(this);
        this.originalValue = propertyValueModel.getValue();
        this.mediatedValueHolder = new ValueHolder(originalValue);
        this.trackDirty = trackDirty;
    }

    public Object getValue() {
        return getWrappedValueModel().getValue();
    }

    public void setValueSilently(Object value, PropertyChangeListener listenerToSkip) {
        getWrappedValueModel().setValueSilently(value, this);
        mediatedValueHolder.setValueSilently(value, listenerToSkip);
        updateDirtyState();
    }

    // called by the wrapped value model
    public void propertyChange(PropertyChangeEvent evt) {
        originalValue = getWrappedValueModel().getValue();
{'fraction_non_alphanumeric': 0.06658644203770557, 'fraction_numerical': 0.0, 'mean_word_length': 4.63502824858757, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6349082', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1171, 'n_words': 296}