package com.vaadin.polymer;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.user.client.ui.HTMLPanel;

public class PolymerWidget extends HTMLPanel {

    public PolymerWidget(String tag, String src, String html) {
        super(tag, html);
        Polymer.ensureCustomElement(getElement(), tag, src);
    }

    public PolymerWidget(String tag, SafeHtml safeHtml) {
        super(tag, safeHtml.asString());
    }

    public void setHorizontal(boolean horizontal) {
        setBooleanAttribute("horizontal", horizontal);
    }
    public void setHorizontal(String horizontal) {
        setBooleanAttribute("horizontal", true);
    }

    public void setLayout(boolean layout) {
        setBooleanAttribute("layout", layout);
    }
    public void setLayout(String layout) {
        setBooleanAttribute("layout", true);
    }

    public void setCenter(boolean center) {
        setBooleanAttribute("center", center);
    }
    public void setCenter(String center) {
        setBooleanAttribute("center", true);
    }

    public void setFlex(boolean flex) {
        setBooleanAttribute("flex", flex);
    }
    public void setFlex(String flex) {
        setBooleanAttribute("flex", true);
    }

    public void setSelfEnd(boolean selfEnd) {
        setBooleanAttribute("self-end", selfEnd);
    }
    public void setSelfEnd(String selfEnd) {
        setBooleanAttribute("self-end", true);
    }


    public void setDisabled(boolean disabled) {
        setBooleanAttribute("disabled", disabled);
    }
    public void setDisabled(String disabled) {
        setBooleanAttribute("disabled", true);
    }


    public void setAriaLabel(String ariaLabel) {
        getElement().setAttribute("ariaLabel", ariaLabel);
    }


    public void setCenterCenter(String centerCenter) {
        getElement().setAttribute("center-center", centerCenter);
    }


    public void setBooleanAttribute(String name, boolean value) {
        if (value) {
            getElement().setAttribute(name, "");
        } else {
            getElement().removeAttribute(name);
        }
    }

    // TODO: Remove this hack for paper-radio-button
    public void setName(String value) {
        getElement().setAttribute("name", value);
    }

    // TODO: Remove this hack for paper-tabs
    public void setLink(String link) {
        getElement().setAttribute("link", link);
    }

    public void setToggle(String toggle) {
        getElement().setAttribute("toggle", toggle);
    }
    public void setNoink(String noink) {
        getElement().setAttribute("noink", noink);
    }
    public void setDismissive(String dismissive) {
        getElement().setAttribute("dismissive", dismissive);
    }
    public void setAffirmative(String affirmative) {
        getElement().setAttribute("affirmative", affirmative);
    }
    public void setAutofocus(String autofocus) {
        getElement().setAttribute("autofocus", autofocus);
    }
    public void setTabindex(int index) {
        getElement().setAttribute("tabindex", "" + index);
    }

    // TODO: Remove this hacks for paper-menu-button
    public void setLabel(String label) {
        getElement().setAttribute("label", label);
    }

    public HandlerRegistration addClickHandler(ClickHandler handler) {
        return addDomHandler(handler, ClickEvent.getType());
    }
}

@@ -614,962 +614,90 @@
  set
-Horizontal(boolean horizontal) %7B%0A        setBooleanAttribute(%22horizontal%22, horizontal);%0A    %7D%0A    public void setHorizontal(String horizontal) %7B%0A        setBooleanAttribute(%22horizontal%22, true);%0A    %7D%0A%0A    public void setLayout(boolean layout) %7B%0A        setBooleanAttribute(%22layout%22, layout);%0A    %7D%0A    public void setLayout(String layout) %7B%0A        setBooleanAttribute(%22layout%22, true);%0A    %7D%0A%0A    public void setCenter(boolean center) %7B%0A        setBooleanAttribute(%22center%22, center);%0A    %7D%0A    public void setCenter(String center) %7B%0A        setBooleanAttribute(%22center%22, true);%0A    %7D%0A%0A    public void setFlex(boolean flex) %7B%0A        setBooleanAttribute(%22flex%22, flex);%0A    %7D%0A    public void setFlex(String flex) %7B%0A        setBooleanAttribute(%22flex%22, true);%0A    %7D%0A%0A    public void setSelfEnd(boolean selfEnd) %7B%0A        setBooleanAttribute(%22self-end%22, selfEnd);%0A    %7D%0A    public void setSelfEnd(String selfEnd) %7B%0A        setBooleanAttribute(%22self-end%22, true
+Disabled(boolean disabled) %7B%0A        this.setBooleanAttribute(%22disabled%22, disabled
 );%0A 
@@ -706,114 +706,8 @@
  %7D%0A%0A
-%0A
-    public void setDisabled(boolean disabled) %7B%0A        setBooleanAttribute(%22disabled%22, disabled);%0A    %7D%0A
     
@@ -757,16 +757,21 @@
         
+this.
 setBoole
@@ -798,257 +798,33 @@
 d%22, 
-true);%0A    %7D%0A%0A%0A    public void setAriaLabel(String ariaLabel) %7B%0A        getElement().setAttribute(%22ariaLabel%22, ariaLabel);%0A    %7D%0A%0A%0A    public void setCenterCenter(String centerCenter) %7B%0A        getElement().setAttribute(%22center-center%22, centerCenter
+Boolean.valueOf(disabled)
 );%0A 
@@ -829,17 +829,16 @@
 %0A    %7D%0A%0A
-%0A
     publ
@@ -905,17 +905,16 @@
       if
- 
 (value) 
@@ -919,32 +919,37 @@
 ) %7B%0A            
+this.
 getElement().set
@@ -990,32 +990,37 @@
 e %7B%0A            
+this.
 getElement().rem
@@ -1045,24 +1045,25 @@
 ;%0A        %7D%0A
+%0A
     %7D%0A%0A    /

Remove unnecessary methods (legacy of 0.5 version) and fix the setDisabled(String) method