<commit_before>package eu.ydp.empiria.player.client.module.sourcelist.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.DragEndEvent;
import com.google.gwt.event.dom.client.DragEndHandler;
import com.google.gwt.event.dom.client.DragStartEvent;
import com.google.gwt.event.dom.client.DragStartHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.web.bindery.event.shared.HandlerRegistration;

import eu.ydp.empiria.player.client.module.IModule;
import eu.ydp.empiria.player.client.resources.StyleNameConstants;
import eu.ydp.empiria.player.client.util.dom.drag.DragDataObject;
import eu.ydp.empiria.player.client.util.dom.drag.DragDropHelper;
import eu.ydp.empiria.player.client.util.dom.drag.DraggableObject;

public class SourceListViewItem extends Composite {

	private static SourceListViewItemUiBinder uiBinder = GWT.create(SourceListViewItemUiBinder.class);

	interface SourceListViewItemUiBinder extends UiBinder<Widget, SourceListViewItem> {
	}

	@UiField
	protected FlowPanel item;

	DragDropHelper dragDropHelper;

	private final DragDataObject dragDataObject;

	private SourceListViewImpl sourceListView;
	DraggableObject<FlowPanel> draggable;

	FlowPanel container;
	private final IModule parentModule;

	private final StyleNameConstants styleNames;

	protected HandlerRegistration addTouchHandler;
	protected boolean dragRelease = false;

	@Inject
	public SourceListViewItem(@Assisted DragDataObject dragDataObject, @Assisted IModule parentModule, StyleNameConstants styleNames,
			DragDropHelper dragDropHelper) {
		this.dragDropHelper = dragDropHelper;
		this.dragDataObject = dragDataObject;
		this.parentModule = parentModule;
		this.styleNames = styleNames;
	}

	public void createAndBindUi() {
		initWidget(uiBinder.createAndBindUi(this));
		Label label = new Label(dragDataObject.getValue());
		container = new FlowPanel();
		container.addStyleName(styleNames.QP_DRAG_ITEM());
		container.add(label);
		draggable = dragDropHelper.enableDragForWidget(container, parentModule);
		item.add(draggable.getDraggableWidget());
		draggable.addDragStartHandler(new DragStartHandler() {
			@Override
			public void onDragStart(DragStartEvent event) {
				dragRelease = false;
				getElement().addClassName(styleNames.QP_DRAGGED_DRAG());
				event.getDataTransfer().setDragImage(getElement(), 0, 0);
				event.setData("json", dragDataObject.toJSON());
				sourceListView.onItemDragStarted(dragDataObject, event, SourceListViewItem.this);

			}
		});
		draggable.addDragEndHandler(new DragEndHandler() {
			@Override
			public void onDragEnd(DragEndEvent event) {
				getElement().removeClassName(styleNames.QP_DRAGGED_DRAG());
				sourceListView.onMaybeDragCanceled();
			}
		});
	}

	public void setSourceListView(SourceListViewImpl sourceListView) {
		this.sourceListView = sourceListView;
	}

	public void setDisableDrag(boolean disableDrag) {
		draggable.setDisableDrag(disableDrag);
	}

	public void show() {
		container.setVisible(true);
	}

	public void hide() {
		container.setVisible(false);
	}
}<commit_msg>Small code refactoring - extracted methods for adding handlers - sorted methods (public above private) - changed modifiers from protected to private issue YPUB-5229<commit_after>package eu.ydp.empiria.player.client.module.sourcelist.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.DragEndEvent;
import com.google.gwt.event.dom.client.DragEndHandler;
import com.google.gwt.event.dom.client.DragStartEvent;
import com.google.gwt.event.dom.client.DragStartHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
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.module.IModule;
import eu.ydp.empiria.player.client.resources.StyleNameConstants;
import eu.ydp.empiria.player.client.util.dom.drag.DragDataObject;
import eu.ydp.empiria.player.client.util.dom.drag.DragDropHelper;
import eu.ydp.empiria.player.client.util.dom.drag.DraggableObject;

public class SourceListViewItem extends Composite {

	private static SourceListViewItemUiBinder uiBinder = GWT.create(SourceListViewItemUiBinder.class);

	interface SourceListViewItemUiBinder extends UiBinder<Widget, SourceListViewItem> {
	}

	@UiField
	protected FlowPanel item;

	private final DragDataObject dragDataObject;
	private final IModule parentModule;
	private final StyleNameConstants styleNames;

	private DragDropHelper dragDropHelper;
	private SourceListViewImpl sourceListView;
	private DraggableObject<FlowPanel> draggable;
	private FlowPanel container;

	@Inject
	public SourceListViewItem(@Assisted DragDataObject dragDataObject, @Assisted IModule parentModule, StyleNameConstants styleNames,
			DragDropHelper dragDropHelper) {
		this.dragDropHelper = dragDropHelper;
		this.dragDataObject = dragDataObject;
		this.parentModule = parentModule;
		this.styleNames = styleNames;
	}
	
	public void setSourceListView(SourceListViewImpl sourceListView) {
		this.sourceListView = sourceListView;
	}
	
	public void setDisableDrag(boolean disableDrag) {
		draggable.setDisableDrag(disableDrag);
	}
	
	public void show() {
		container.setVisible(true);
	}
	
	public void hide() {
		container.setVisible(false);
	}

	public void createAndBindUi() {
		initWidget(uiBinder.createAndBindUi(this));
		Label label = new Label(dragDataObject.getValue());
		container = new FlowPanel();
		container.addStyleName(styleNames.QP_DRAG_ITEM());
		container.add(label);
		draggable = dragDropHelper.enableDragForWidget(container, parentModule);
		item.add(draggable.getDraggableWidget());
		addDragHandlers();
	}

	private void addDragHandlers() {
		addDragStartHandler();
		addDragEndHandler();
	}
	
	private void addDragStartHandler() {
		draggable.addDragStartHandler(new DragStartHandler() {
			@Override
			public void onDragStart(DragStartEvent event) {
				getElement().addClassName(styleNames.QP_DRAGGED_DRAG());
				event.getDataTransfer().setDragImage(getElement(), 0, 0);
				event.setData("json", dragDataObject.toJSON());
				sourceListView.onItemDragStarted(dragDataObject, event, SourceListViewItem.this);
			}
		});
	}

	private void addDragEndHandler() {
		draggable.addDragEndHandler(new DragEndHandler() {
			@Override
			public void onDragEnd(DragEndEvent event) {
				getElement().removeClassName(styleNames.QP_DRAGGED_DRAG());
				sourceListView.onMaybeDragCanceled();
			}
		});
	}
}
{'fraction_non_alphanumeric': 0.10098839707778255, 'fraction_numerical': 0.0011459676264145538, 'mean_word_length': 5.892398815399803, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5834807', 'n_tokens_mistral': 2345, 'n_tokens_neox': 2163, 'n_words': 364}