<commit_before>package org.javarosa.formmanager.view.summary;

import org.javarosa.core.api.Constants;
import org.javarosa.core.model.FormDef;
import org.javarosa.core.model.FormIndex;
import org.javarosa.core.model.data.IAnswerData;
import org.javarosa.core.services.locale.Localization;
import org.javarosa.form.api.FormEntryController;
import org.javarosa.form.api.FormEntryModel;
import org.javarosa.form.api.FormEntryPrompt;
import org.javarosa.formmanager.utility.SortedIndexSet;
import org.javarosa.j2me.view.J2MEDisplay;

import de.enough.polish.ui.Command;
import de.enough.polish.ui.List;
import de.enough.polish.ui.Style;
import de.enough.polish.ui.StyleSheet;

public class FormSummaryView extends List {
	private FormEntryModel model;
	private SortedIndexSet indexSet;

	public final Command CMD_EXIT = new Command(Localization.get("menu.Exit"),
			Command.EXIT, 4);
	public final Command CMD_SAVE_EXIT = new Command(Localization
			.get("menu.SaveAndExit"), Command.SCREEN, 4);

	public FormSummaryView(FormEntryModel model) {
		// #style View_All_Form
		super("Form Overview", List.IMPLICIT);
		this.model = model;
		createView();

		addCommand(CMD_EXIT);
		
		// TODO: handle readonly
		if (true) {
			addCommand(CMD_SAVE_EXIT);
		}
	}

	protected void createView() {
		indexSet = new SortedIndexSet();

		FormIndex index = FormIndex.createBeginningOfFormIndex();
		FormDef form = model.getForm();
		while (!index.isEndOfFormIndex()) {
			if (index.isInForm() && model.isRelevant(index)) {
				if (model.getEvent(index) == FormEntryController.EVENT_QUESTION) {
					FormEntryPrompt prompt = model.getQuestionPrompt(index);
					String styleName = getStyleName(prompt);
					String line = prompt.getLongText() + " => ";

					IAnswerData answerValue = prompt.getAnswerValue();
					if (answerValue != null) {
						line += answerValue.getDisplayText();
					}
					Style style = styleName == null ? null : StyleSheet
							.getStyle(styleName);
					append(line, null, style);
					indexSet.add(index);
				}
			}
			index = form.incrementIndex(index);
		}
	}

	private String getStyleName(FormEntryPrompt prompt) {
		if (prompt.isRequired() && prompt.getAnswerValue() == null) {
			return Constants.STYLE_COMPULSORY;
		}
		return null;
	}

	public FormIndex getFormIndex() {
		int selectedIndex = getSelectedIndex();
		if (selectedIndex < 0) {
			return null;
		}
		FormIndex formIndex = (FormIndex) indexSet.get(selectedIndex);
		return formIndex;
	}

	public void show() {
		J2MEDisplay.setView(this);
	}
}<commit_msg>list with styles for groups<commit_after>package org.javarosa.formmanager.view.summary;

import org.javarosa.core.model.FormDef;
import org.javarosa.core.model.FormIndex;
import org.javarosa.core.model.GroupDef;
import org.javarosa.core.model.data.IAnswerData;
import org.javarosa.core.services.locale.Localization;
import org.javarosa.form.api.FormEntryCaption;
import org.javarosa.form.api.FormEntryController;
import org.javarosa.form.api.FormEntryModel;
import org.javarosa.form.api.FormEntryPrompt;
import org.javarosa.j2me.view.J2MEDisplay;

import de.enough.polish.ui.Command;
import de.enough.polish.ui.List;
import de.enough.polish.ui.Style;
import de.enough.polish.ui.StyleSheet;
import de.enough.polish.util.HashMap;

public class FormSummaryView extends List {
	private FormEntryModel model;
	private HashMap indexHash;

	private static String STYLE_NOGROUP = "SingleQuestionScreen_No_Group";
	private static String STYLE_GROUP = "SingleQuestionScreen_Group";
	private static String STYLE_GROUP_ALT = "SingleQuestionScreen_Group_Alt";

	public final Command CMD_EXIT = new Command(Localization.get("menu.Exit"),
			Command.EXIT, 4);
	public final Command CMD_SAVE_EXIT = new Command(Localization
			.get("menu.SaveAndExit"), Command.SCREEN, 4);

	public FormSummaryView(FormEntryModel model) {
		// #style SingleQuestionScreen_Form
		super("Form Overview", List.IMPLICIT);
		this.model = model;
		createView();

		addCommand(CMD_EXIT);

		// TODO: handle readonly
		if (true) {
			addCommand(CMD_SAVE_EXIT);
		}
	}

	protected void createView() {
		int level = 0;
		int captioncount = - 1;

		indexHash = new HashMap();

		FormIndex index = FormIndex.createBeginningOfFormIndex();
		FormDef form = model.getForm();
		while (!index.isEndOfFormIndex()) {
			if (index.isInForm() && model.isRelevant(index)) {
				if (model.getEvent(index) == FormEntryController.EVENT_QUESTION) {
					FormEntryCaption[] hierachy = model
							.getCaptionHierarchy(index);
					for (FormEntryCaption caption : hierachy) {
						captioncount++;
						if (caption.getFormElement() instanceof GroupDef) {
							if (!caption.getFormElement().getChildren()
									.isEmpty()) { // start of group
								System.out
										.print("start of group. level changed from "
												+ level + " to ");
								level++;
								System.out.println(level);
							} else { // end of group
								System.out
										.print("end of group. level changed from "
												+ level + " to ");
								level--;
								System.out.println(level);
							}
						}
						String text = getText(caption);
						append(text, null, getStyleForLevel(level));
						indexHash.put(new Integer(captioncount), index);
					}
				}
			}
			index = form.incrementIndex(index);
		}
	}

	private String getText(FormEntryCaption caption) {
		String line = "";
		if (caption instanceof FormEntryPrompt) {
			FormEntryPrompt prompt = (FormEntryPrompt) caption;
			line += prompt.getLongText() + " => ";
			if (prompt.isRequired() && prompt.getAnswerValue() == null) {
				line = "*" + line;
			}
			IAnswerData answerValue = prompt.getAnswerValue();
			if (answerValue != null) {
				line += answerValue.getDisplayText();
			}
		} else if (!caption.getFormElement().getChildren().isEmpty()) {
			line += caption.getLongText();
		}

		return line;
	}

	private Style getStyleForLevel(int level) {
		Style style = null;
		if (level == 0) {
			style = StyleSheet.getStyle(STYLE_NOGROUP);
		} else if ((level % 2) == 0) {
			style = StyleSheet.getStyle(STYLE_GROUP);
		} else {
			style = StyleSheet.getStyle(STYLE_GROUP_ALT);
		}
		return style;
	}

	public FormIndex getFormIndex() {
		int selectedIndex = getSelectedIndex();
		if (selectedIndex < 0) {
			return null;
		}
		FormIndex formIndex = (FormIndex) indexHash.get(new Integer(
				selectedIndex));
		return formIndex;
	}

	public void show() {
		J2MEDisplay.setView(this);
	}
}
{'fraction_non_alphanumeric': 0.1203603043950924, 'fraction_numerical': 0.0026401615157633173, 'mean_word_length': 3.9010654490106544, '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': '1893684', 'n_tokens_mistral': 2461, 'n_tokens_neox': 2069, 'n_words': 422}