<commit_before>package eu.ydp.empiria.player.client.module.draggap.presenter;

import java.util.List;

import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;

import eu.ydp.empiria.player.client.controller.variables.processor.AnswerEvaluationSupplier;
import eu.ydp.empiria.player.client.gin.scopes.module.ModuleScoped;
import eu.ydp.empiria.player.client.gin.scopes.page.PageScoped;
import eu.ydp.empiria.player.client.module.IModule;
import eu.ydp.empiria.player.client.module.MarkAnswersMode;
import eu.ydp.empiria.player.client.module.MarkAnswersType;
import eu.ydp.empiria.player.client.module.ModuleSocket;
import eu.ydp.empiria.player.client.module.ShowAnswersType;
import eu.ydp.empiria.player.client.module.dragdrop.SourcelistManager;
import eu.ydp.empiria.player.client.module.draggap.DragGapModuleModel;
import eu.ydp.empiria.player.client.module.draggap.structure.DragGapBean;
import eu.ydp.empiria.player.client.module.draggap.view.DragGapDropHandler;
import eu.ydp.empiria.player.client.module.draggap.view.DragGapView;
import eu.ydp.empiria.player.client.module.gap.DropZoneGuardian;
import eu.ydp.empiria.player.client.module.selection.model.UserAnswerType;
import eu.ydp.empiria.player.client.resources.StyleNameConstants;
import eu.ydp.empiria.player.client.util.dom.drag.DragDropHelper;
import eu.ydp.empiria.player.client.util.dom.drag.DroppableObject;

public class DragGapPresenterImpl implements DragGapPresenter {

	@Inject
	@ModuleScoped
	private DragGapModuleModel model;

	@Inject
	private DragGapView view;

	@Inject
	private SourcelistManager sourcelistManager;

	@Inject
	@PageScoped
	private AnswerEvaluationSupplier answerEvaluationSupplier;

	private DragGapBean bean;
	private ModuleSocket socket;

	private StyleNameConstants styleNames;
	
	private final DroppableObject<TextBox> droppable;
	private DropZoneGuardian dropZoneGuardian;

	@Inject
	public DragGapPresenterImpl(@Assisted("imodule") IModule parentModule, DragDropHelper dragDropHelper, StyleNameConstants styleNameConstants) {
		droppable = dragDropHelper.enableDropForWidget(new TextBox(), parentModule);
		styleNames = styleNameConstants;
		
		dropZoneGuardian = new DropZoneGuardian(droppable, view.asWidget(), styleNames);
	}
	
	@Override
	public void bindView() {
		view.updateStyle(UserAnswerType.DEFAULT);
	}

	@Override
	public void reset() {
		view.removeContent();
		model.reset();
		view.updateStyle(UserAnswerType.DEFAULT);
	}

	@Deprecated
	@Override
	public void setModel(DragGapModuleModel model) {
	}

	@Override
	public void setModuleSocket(ModuleSocket socket) {
		this.socket = socket;
	}

	@Override
	public void setBean(DragGapBean bean) {
		this.bean = bean;
	}

	@Override
	public void setLocked(boolean locked) {
		view.lock(locked);
	}

	@Override
	public void markAnswers(MarkAnswersType type, MarkAnswersMode mode) {
		List<Boolean> evaluatedAnswers = answerEvaluationSupplier
				.evaluateAnswer(model.getResponse());

		if (evaluatedAnswers.size() < 1){
			view.updateStyle(UserAnswerType.NONE);
		}else{
			Boolean isAnswerCorrect = evaluatedAnswers.get(0);
			
			if (mode == MarkAnswersMode.MARK) {<commit_msg>prezenter implementation for DragGap bug - refactor YPUB-5451<commit_after>package eu.ydp.empiria.player.client.module.draggap.presenter;

import java.util.List;

import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;

import eu.ydp.empiria.player.client.controller.variables.processor.AnswerEvaluationSupplier;
import eu.ydp.empiria.player.client.gin.scopes.module.ModuleScoped;
import eu.ydp.empiria.player.client.gin.scopes.page.PageScoped;
import eu.ydp.empiria.player.client.module.IModule;
import eu.ydp.empiria.player.client.module.MarkAnswersMode;
import eu.ydp.empiria.player.client.module.MarkAnswersType;
import eu.ydp.empiria.player.client.module.ModuleSocket;
import eu.ydp.empiria.player.client.module.ShowAnswersType;
import eu.ydp.empiria.player.client.module.dragdrop.SourcelistManager;
import eu.ydp.empiria.player.client.module.draggap.DragGapModuleModel;
import eu.ydp.empiria.player.client.module.draggap.structure.DragGapBean;
import eu.ydp.empiria.player.client.module.draggap.view.DragGapDropHandler;
import eu.ydp.empiria.player.client.module.draggap.view.DragGapView;
import eu.ydp.empiria.player.client.module.gap.DropZoneGuardian;
import eu.ydp.empiria.player.client.module.selection.model.UserAnswerType;
import eu.ydp.empiria.player.client.resources.StyleNameConstants;
import eu.ydp.empiria.player.client.util.dom.drag.DragDropHelper;
import eu.ydp.empiria.player.client.util.dom.drag.DroppableObject;

public class DragGapPresenterImpl implements DragGapPresenter {

	@Inject
	@ModuleScoped
	private DragGapModuleModel model;

	@Inject
	private DragGapView view;

	@Inject
	private SourcelistManager sourcelistManager;

	@Inject
	@PageScoped
	private AnswerEvaluationSupplier answerEvaluationSupplier;

	private DragGapBean bean;
	private ModuleSocket socket;

	private StyleNameConstants styleNames;
	
	private final DroppableObject<TextBox> droppable;
	private DropZoneGuardian dropZoneGuardian;

	@Inject
	public DragGapPresenterImpl(@Assisted("imodule") IModule parentModule, DragDropHelper dragDropHelper, StyleNameConstants styleNameConstants) {
		droppable = dragDropHelper.enableDropForWidget(new TextBox(), parentModule);
		styleNames = styleNameConstants;
		
		dropZoneGuardian = new DropZoneGuardian(droppable, view.asWidget(), styleNames);
	}
	
	@Override
	public void bindView() {
		view.updateStyle(UserAnswerType.DEFAULT);
	}

	@Override
	public void reset() {
		view.removeContent();
		model.reset();
		view.updateStyle(UserAnswerType.DEFAULT);
	}

	@Deprecated
	@Override
	public void setModel(DragGapModuleModel model) {
	}

	@Override
	public void setModuleSocket(ModuleSocket socket) {
		this.socket = socket;
	}

	@Override
	public void setBean(DragGapBean bean) {
		this.bean = bean;
	}

	@Override
	public void setLocked(boolean locked) {
		view.lock(locked);
	}

	@Override
	public void markAnswers(MarkAnswersType type, MarkAnswersMode mode) {
		List<Boolean> evaluatedAnswers = answerEvaluationSupplier
				.evaluateAnswer(model.getResponse());

		if (evaluatedAnswers.isEmpty()){
			view.updateStyle(UserAnswerType.NONE);
		}else{
			Boolean isAnswerCorrect = evaluatedAnswers.get(0);
			
			if (mode == MarkAnswersMode.MARK) {
{'fraction_non_alphanumeric': 0.10132561328660673, 'fraction_numerical': 0.001066585403016913, 'mean_word_length': 5.866108786610878, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, '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': '1120069', 'n_tokens_mistral': 2288, 'n_tokens_neox': 2177, 'n_words': 339}