<commit_before>package ch.openech.client.e11;

import java.util.List;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import ch.openech.dm.code.EchCodes;
import ch.openech.dm.person.MaritalStatus;
import ch.openech.mj.autofill.DemoEnabled;
import ch.openech.mj.edit.fields.AbstractEditField;
import ch.openech.mj.edit.fields.CodeEditField;
import ch.openech.mj.edit.fields.DateField;
import ch.openech.mj.edit.fields.FormField;
import ch.openech.mj.edit.fields.TextFormField;
import ch.openech.mj.edit.validation.Indicator;
import ch.openech.mj.edit.validation.Validatable;
import ch.openech.mj.edit.validation.ValidationMessage;
import ch.openech.mj.toolkit.ClientToolkit;
import ch.openech.mj.toolkit.HorizontalLayout;
import ch.openech.mj.toolkit.IComponent;


public class MaritalStatusField extends AbstractEditField<MaritalStatus> implements Validatable, DemoEnabled {
	private final boolean editable;
	private final FormField<String> code;
	private final DateField date;
	private final HorizontalLayout horizontalLayout;
	private DateEnablerChangeListener dateEnablerChangeListener;
	private MaritalStatus maritalStatus;
	
	public MaritalStatusField(Object key, boolean editable) {
		super(key);
		
		this.editable = editable;
		code = editable ? new CodeEditField(key, EchCodes.maritalStatus) : new TextFormField(key, EchCodes.maritalStatus);
		date = new DateField(DateField.NOT_REQUIRED, editable);
		horizontalLayout = ClientToolkit.getToolkit().createHorizontalLayout(code, date);
		
		dateEnablerChangeListener = new DateEnablerChangeListener();
		// dateEnablerChangeListener.stateChanged(null);
		
		if (editable) {
			((CodeEditField) code).setChangeListener(dateEnablerChangeListener);
		}
		date.setChangeListener(listener());
	}

	@Override
	protected IComponent getComponent0() {
		return horizontalLayout;
	}

	// 

	@Override
	public MaritalStatus getObject() {
		if (editable) {
			// Der Cast auf CodeEditField geht schief, falls kein editable, darum das if hier
			maritalStatus.maritalStatus = ((CodeEditField) code).getObject();
			maritalStatus.dateOfMaritalStatus = date.getObject();
		}
		return maritalStatus;
	}

	@Override
	public void setObject(MaritalStatus maritalStatus) {
		this.maritalStatus = maritalStatus;
		code.setObject(maritalStatus.maritalStatus);
		date.setObject(maritalStatus.dateOfMaritalStatus);
	}
	
	private void enableDate() {
		date.setEnabled(editable && !getObject().isLedig());
	}
	
	private class DateEnablerChangeListener implements ChangeListener {
		@Override
		public void stateChanged(ChangeEvent changeEvent) {
			enableDate();
			listener().stateChanged(changeEvent);
		}
	}

	@Override
	public void validate(List<ValidationMessage> resultList) {
		if (!getObject().isLedig()) {
			date.validate(resultList);
		}
	}

	@Override
	public void fillWithDemoData() {
		int code = (int)(1 + 7 * Math.random());
		this.code.setObject("" + code);
		if (!getObject().isLedig()) {
			date.fillWithDemoData();
		}
	}

	@Override
	protected Indicator[] getIndicatingComponents() {
		return new Indicator[]{date};
	}

}
<commit_msg>Editierbarkeit bei nur Anzeige abgeschaltet<commit_after>package ch.openech.client.e11;

import java.util.List;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import ch.openech.dm.code.EchCodes;
import ch.openech.dm.person.MaritalStatus;
import ch.openech.mj.autofill.DemoEnabled;
import ch.openech.mj.edit.fields.AbstractEditField;
import ch.openech.mj.edit.fields.CodeEditField;
import ch.openech.mj.edit.fields.DateField;
import ch.openech.mj.edit.fields.FormField;
import ch.openech.mj.edit.fields.TextFormField;
import ch.openech.mj.edit.validation.Indicator;
import ch.openech.mj.edit.validation.Validatable;
import ch.openech.mj.edit.validation.ValidationMessage;
import ch.openech.mj.toolkit.ClientToolkit;
import ch.openech.mj.toolkit.HorizontalLayout;
import ch.openech.mj.toolkit.IComponent;

// TODO Das MaritalStatus-Field sollte in zwei Felder mit DependingOn aufgeteilt werden.
// das createHorizontalLayout(code, date) mit Namenlosen Feldern ist ein Murks
public class MaritalStatusField extends AbstractEditField<MaritalStatus> implements Validatable, DemoEnabled {
	private final boolean editable;
	private final FormField<String> code;
	private final DateField date;
	private final HorizontalLayout horizontalLayout;
	private DateEnablerChangeListener dateEnablerChangeListener;
	private MaritalStatus maritalStatus;
	
	public MaritalStatusField(Object key, boolean editable) {
		super(key);
		
		this.editable = editable;
		code = editable ? new CodeEditField(key, EchCodes.maritalStatus) : new TextFormField(key, EchCodes.maritalStatus);
		date = new DateField(null, DateField.NOT_REQUIRED, editable);
		
		horizontalLayout = ClientToolkit.getToolkit().createHorizontalLayout(code, date);
		
		dateEnablerChangeListener = new DateEnablerChangeListener();
		// dateEnablerChangeListener.stateChanged(null);
		
		if (editable) {
			((CodeEditField) code).setChangeListener(dateEnablerChangeListener);
		}
		date.setChangeListener(listener());
	}

	@Override
	protected IComponent getComponent0() {
		return horizontalLayout;
	}

	// 

	@Override
	public MaritalStatus getObject() {
		if (editable) {
			// Der Cast auf CodeEditField geht schief, falls kein editable, darum das if hier
			maritalStatus.maritalStatus = ((CodeEditField) code).getObject();
			maritalStatus.dateOfMaritalStatus = date.getObject();
		}
		return maritalStatus;
	}

	@Override
	public void setObject(MaritalStatus maritalStatus) {
		this.maritalStatus = maritalStatus;
		code.setObject(maritalStatus.maritalStatus);
		date.setObject(maritalStatus.dateOfMaritalStatus);
	}
	
	private void enableDate() {
		date.setEnabled(editable && !getObject().isLedig());
	}
	
	private class DateEnablerChangeListener implements ChangeListener {
		@Override
		public void stateChanged(ChangeEvent changeEvent) {
			enableDate();
			listener().stateChanged(changeEvent);
		}
	}

	@Override
	public void validate(List<ValidationMessage> resultList) {
		if (!getObject().isLedig()) {
			date.validate(resultList);
		}
	}

	@Override
	public void fillWithDemoData() {
		int code = (int)(1 + 7 * Math.random());
		this.code.setObject("" + code);
		if (!getObject().isLedig()) {
			date.fillWithDemoData();
		}
	}

	@Override
	protected Indicator[] getIndicatingComponents() {
		return new Indicator[]{date};
	}

}

{'fraction_non_alphanumeric': 0.10521415270018622, 'fraction_numerical': 0.0015518311607697084, 'mean_word_length': 5.445, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6816532', 'n_tokens_mistral': 2201, 'n_tokens_neox': 2032, 'n_words': 395}