package org.gwtbootstrap3.client.ui.base;

/*
 * #%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.Element;
import com.google.gwt.dom.client.Style;
import com.google.gwt.user.client.ui.HasHTML;
import com.google.gwt.user.client.ui.Widget;
import org.gwtbootstrap3.client.ui.base.helper.StyleHelper;
import org.gwtbootstrap3.client.ui.base.mixin.IdMixin;
import org.gwtbootstrap3.client.ui.constants.DeviceSize;
import org.gwtbootstrap3.client.ui.constants.HasId;
import org.gwtbootstrap3.client.ui.constants.HasInlineStyle;
import org.gwtbootstrap3.client.ui.constants.HasResponsiveness;

/**
 * Base class for {@link Widget} that just contains text.
 *
 * @author Sven Jacobs
 * @author Joshua Godi
 */
public abstract class AbstractTextWidget extends Widget implements HasId, HasHTML, HasResponsiveness, HasInlineStyle {

    private final IdMixin<AbstractTextWidget> idMixin = new IdMixin<AbstractTextWidget>(this);

    protected AbstractTextWidget(final Element element) {
        setElement(element);
    }

    @Override
    public String getId() {
        return idMixin.getId();
    }

    @Override
    public void setId(final String id) {
        idMixin.setId(id);
    }

    @Override
    public String getText() {
        return getElement().getInnerText();
    }

    @Override
    public void setText(final String text) {
        // Set innerHTML instead to allow for spacing and HTML code!
        getElement().setInnerHTML(text);
    }

    @Override
    public String getHTML() {
        return getElement().getInnerHTML();
    }

    @Override
    public void setHTML(final String html) {
        getElement().setInnerHTML(html);
    }

    @Override
    public void setVisibleOn(final DeviceSize deviceSize) {
        StyleHelper.setVisibleOn(this, deviceSize);
    }

    @Override
    public void setHiddenOn(final DeviceSize deviceSize) {
        StyleHelper.setHiddenOn(this, deviceSize);
    }

    @Override
    public void setMarginTop(final double margin) {
        getElement().getStyle().setMarginTop(margin, Style.Unit.PX);
    }

    @Override
    public void setMarginLeft(final double margin) {
        getElement().getStyle().setMarginLeft(margin, Style.Unit.PX);
    }

    @Override
    public void setMarginRight(final double margin) {
        getElement().getStyle().setMarginRight(margin, Style.Unit.PX);
    }

    @Override
    public void setMarginBottom(final double margin) {
        getElement().getStyle().setMarginBottom(margin, Style.Unit.PX);
    }

    @Override
    public void setPaddingTop(final double padding) {
        getElement().getStyle().setPaddingTop(padding, Style.Unit.PX);
    }

    @Override
    public void setPaddingLeft(final double padding) {
        getElement().getStyle().setPaddingLeft(padding, Style.Unit.PX);
    }

    @Override
    public void setPaddingRight(final double padding) {
        getElement().getStyle().setPaddingRight(padding, Style.Unit.PX);
    }

    @Override
    public void setPaddingBottom(final double padding) {
        getElement().getStyle().setPaddingBottom(padding, Style.Unit.PX);
    }

}

@@ -759,24 +759,186 @@
 ient.Style;%0A
+import com.google.gwt.editor.client.IsEditor;%0Aimport com.google.gwt.editor.client.LeafValueEditor;%0Aimport com.google.gwt.editor.ui.client.adapters.HasTextEditor;%0A
 import com.g
@@ -1597,16 +1597,59 @@
 ineStyle
+,%0A        IsEditor%3CLeafValueEditor%3CString%3E%3E
  %7B%0A%0A    
@@ -1738,16 +1738,60 @@
 %3E(this);
+%0A    private LeafValueEditor%3CString%3E editor;
 %0A%0A    pr
@@ -3961,10 +3961,187 @@
 %0A    %7D%0A%0A
+    @Override%0A    public LeafValueEditor%3CString%3E asEditor() %7B%0A        if (editor == null) %7B%0A            editor = HasTextEditor.of(this);%0A        %7D%0A        return editor;%0A    %7D%0A%0A
 %7D%0A

Fix #149: AbstractTextWidget implements IsEditor<LeafValueEditor<String>>