package org.gwtbootstrap3.client.ui;

/*
 * #%L
 * GwtBootstrap3
 * %%
 * Copyright (C) 2013 GwtBootstrap3
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.InputElement;
import com.google.gwt.event.dom.client.*;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.uibinder.client.UiConstructor;
import com.google.gwt.user.client.ui.HasName;
import org.gwtbootstrap3.client.ui.base.ComplexWidget;
import org.gwtbootstrap3.client.ui.constants.ElementTags;
import org.gwtbootstrap3.client.ui.constants.InputType;
import org.gwtbootstrap3.client.ui.constants.Styles;

/**
 * @author Joshua Godi
 * @see org.gwtbootstrap3.client.ui.HasEnabled
 */
public class Input extends ComplexWidget implements HasEnabled, HasInputType, HasPlaceholder, HasFormValue, HasName,
        HasAllKeyHandlers {

    private static final String MIN = "min";
    private static final String MAX = "max";

    public Input() {
        setElement(Document.get().createElement(ElementTags.INPUT));
        addStyleName(Styles.FORM_CONTROL);
    }

    @UiConstructor
    public Input(final InputType type) {
        this();
        setType(type);
    }

    public void setMin(final String min) {
        getElement().setAttribute(MIN, min);
    }

    public void setMax(final String max) {
        getElement().setAttribute(MAX, max);
    }

    @Override
    public void setEnabled(final boolean enabled) {
        getElement().setPropertyBoolean(DISABLED_PROPERTY, !enabled);
    }

    @Override
    public boolean isEnabled() {
        return !getElement().getPropertyBoolean(DISABLED_PROPERTY);
    }

    @Override
    public void setType(final InputType inputType) {
        getElement().setAttribute(TYPE, inputType.getType());
    }

    @Override
    public InputType getType() {
        if (getElement().getAttribute(TYPE) == null || getElement().getAttribute(TYPE).isEmpty()) {
            return null;
        }
        return InputType.valueOf(getElement().getAttribute(TYPE));
    }

    @Override
    public void setPlaceholder(final String placeHolder) {
        getElement().setAttribute(PLACEHOLDER, placeHolder != null ? placeHolder : "");
    }

    @Override
    public String getPlaceholder() {
        return getElement().getAttribute(PLACEHOLDER);
    }

    @Override
    public String getFormValue() {
        return InputElement.as(getElement()).getValue();
    }

    @Override
    public void setFormValue(final String value) {
        InputElement.as(getElement()).setValue(value);
    }

    @Override
    public String getName() {
        return InputElement.as(getElement()).getName();
    }

    @Override
    public void setName(final String name) {
        InputElement.as(getElement()).setName(name);
    }

    @Override
    public HandlerRegistration addKeyDownHandler(KeyDownHandler handler) {
        return addDomHandler(handler, KeyDownEvent.getType());
    }

    @Override
    public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) {
        return addDomHandler(handler, KeyPressEvent.getType());
    }

    @Override
    public HandlerRegistration addKeyUpHandler(KeyUpHandler handler) {
        return addDomHandler(handler, KeyUpEvent.getType());
    }
}

@@ -745,73 +745,45 @@
 gwt.
-dom.client.InputElement;%0Aimport com.google.gwt.event.dom.client.*
+text.shared.testing.PassthroughParser
 ;%0Aim
@@ -806,12 +806,11 @@
 gwt.
-even
+tex
 t.sh
@@ -814,35 +814,43 @@
 .shared.
-HandlerRegistration
+testing.PassthroughRenderer
 ;%0Aimport
@@ -900,54 +900,8 @@
 or;%0A
-import com.google.gwt.user.client.ui.HasName;%0A
 impo
@@ -936,29 +936,28 @@
 ui.base.
-ComplexWidget
+ValueBoxBase
 ;%0Aimport
@@ -1227,123 +1227,52 @@
 nds 
-ComplexWidget implements HasEnabled, HasInputType, HasPlaceholder, HasFormValue, HasName,%0A        HasAllKeyHandlers
+ValueBoxBase%3CString%3E implements HasInputType
  %7B%0A%0A
@@ -1392,25 +1392,20 @@
        s
-etElement
+uper
 (Documen
@@ -1444,16 +1444,94 @@
 s.INPUT)
+, PassthroughRenderer.instance(),%0A                PassthroughParser.instance()
 );%0A     
@@ -1875,287 +1875,8 @@
  %7D%0A%0A
-    @Override%0A    public void setEnabled(final boolean enabled) %7B%0A        getElement().setPropertyBoolean(DISABLED_PROPERTY, !enabled);%0A    %7D%0A%0A    @Override%0A    public boolean isEnabled() %7B%0A        return !getElement().getPropertyBoolean(DISABLED_PROPERTY);%0A    %7D%0A%0A    @Override%0A
     
@@ -2534,945 +2534,6 @@
  %7D%0A%0A
-    @Override%0A    public String getFormValue() %7B%0A        return InputElement.as(getElement()).getValue();%0A    %7D%0A%0A    @Override%0A    public void setFormValue(final String value) %7B%0A        InputElement.as(getElement()).setValue(value);%0A    %7D%0A%0A    @Override%0A    public String getName() %7B%0A        return InputElement.as(getElement()).getName();%0A    %7D%0A%0A    @Override%0A    public void setName(final String name) %7B%0A        InputElement.as(getElement()).setName(name);%0A    %7D%0A%0A    @Override%0A    public HandlerRegistration addKeyDownHandler(KeyDownHandler handler) %7B%0A        return addDomHandler(handler, KeyDownEvent.getType());%0A    %7D%0A%0A    @Override%0A    public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) %7B%0A        return addDomHandler(handler, KeyPressEvent.getType());%0A    %7D%0A%0A    @Override%0A    public HandlerRegistration addKeyUpHandler(KeyUpHandler handler) %7B%0A        return addDomHandler(handler, KeyUpEvent.getType());%0A    %7D%0A
 %7D%0A

Make Input extend ValueBoxBase and remove redundant code