package eu.ydp.empiria.player.client.module.colorfill.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

import eu.ydp.empiria.player.client.module.model.color.ColorModel;
import eu.ydp.empiria.player.client.resources.StyleNameConstants;
import eu.ydp.gwtutil.client.ui.InputToButtonReplacer;

public class PaletteButtonImpl extends Composite implements PaletteButton {

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

	@UiTemplate("PaletteButton.ui.xml")
	interface PaletteButtonUiBinder extends UiBinder<Widget, PaletteButtonImpl> {}
	
	@UiField
	FlowPanel container;

	@UiField
	PushButton button;
	
	@UiField
	FlowPanel description;
	
	private StyleNameConstants styleNameConstants;
	
	@Inject
	public PaletteButtonImpl(StyleNameConstants styleNameConstants, InputToButtonReplacer inputReplacer) {
		initWidget(uiBinder.createAndBindUi(this));
		this.styleNameConstants = styleNameConstants;
		inputReplacer.changeInputTypeChildToButton(button);
	}

	@Override
	public void setColor(ColorModel color) {
		container.addStyleDependentName(color.toStringRgba());
	}

	@Override
	public void select() {
		container.addStyleName(styleNameConstants.QP_COLORFILL_PALETTE_BUTTON_CONTAINER_SELECTED());
	}

	@Override
	public void deselect() {
		container.removeStyleName(styleNameConstants.QP_COLORFILL_PALETTE_BUTTON_CONTAINER_SELECTED());
	}

	@Override
	public void setDescription(String description) {
		this.description.getElement().setInnerHTML(description);
	}
}

@@ -646,32 +646,32 @@
 ui.Input
-ToButtonReplacer
+InsideButtonHack
 ;%0D%0A%0D%0Apub
@@ -959,12 +959,14 @@
 l%3E %7B
+%0D%0A%09
 %7D%0D%0A
-%09
 %0D%0A%09@
@@ -1031,19 +1031,18 @@
 utton;%0D%0A
-%09
 %0D%0A
+
 %09@UiFiel
@@ -1069,19 +1069,18 @@
 ption;%0D%0A
-%09
 %0D%0A
+
 %09private
@@ -1124,11 +1124,10 @@
 s;%0D%0A
-%09
 %0D%0A
+
 %09@In
@@ -1206,38 +1206,46 @@
 nput
-ToButtonReplacer inputReplacer
+InsideButtonHack inputInsideButtonHack
 ) %7B%0D
@@ -1352,45 +1352,44 @@
 nput
-Replacer.changeInputTypeChildToButton
+InsideButtonHack.activateIfNeededFor
 (but

refactor and add condition to hack YPUB-5928