package org.ovirt.engine.ui.common.widget.editor.generic;

import com.google.gwt.text.shared.Parser;
import com.google.gwt.text.shared.Renderer;
import org.ovirt.engine.ui.common.widget.editor.AbstractValueBoxWithLabelEditor;
import org.ovirt.engine.ui.common.widget.editor.EnterIgnoringFocusHandler;

public class EntityModelTextAreaEditor<T> extends AbstractValueBoxWithLabelEditor<T, EntityModelTextArea<T>> {

    public EntityModelTextAreaEditor(Renderer<T> renderer, Parser<T> parser) {
        this(new EntityModelTextArea<T>(renderer, parser));

        registerEnterIgnoringHandlers();
    }

    public EntityModelTextAreaEditor(EntityModelTextArea<T> widget) {
        super(widget);

        registerEnterIgnoringHandlers();
    }

    private void registerEnterIgnoringHandlers() {
        EnterIgnoringFocusHandler enterIgnoringFocusHandler = new EnterIgnoringFocusHandler() {
            @Override
            protected void enterPressed() {
                super.enterPressed();
                getContentWidget().setText(getContentWidget().getText() + '\n'); //$NON-NLS-1$
            }
        };

        getContentWidget().addFocusHandler(enterIgnoringFocusHandler);
        getContentWidget().addBlurHandler(enterIgnoringFocusHandler);
    }
}

@@ -56,94 +56,8 @@
 c;%0A%0A
-import com.google.gwt.text.shared.Parser;%0Aimport com.google.gwt.text.shared.Renderer;%0A
 impo
@@ -209,16 +209,103 @@
 ndler;%0A%0A
+import com.google.gwt.text.shared.Parser;%0Aimport com.google.gwt.text.shared.Renderer;%0A%0A
 public c
@@ -1009,86 +1009,293 @@
     
-getContentWidget().setText(getContentWidget().getText() + '%5Cn'); //$NON-NLS-1$
+int pos = getContentWidget().getCursorPos();%0A                getContentWidget().setText(getContentWidget().getText().substring(0, pos) + '%5Cn'%0A                        + getContentWidget().getText().substring(pos)); //$NON-NLS-1$%0A                getContentWidget().setCursorPos(pos + 1);
 %0A   

EntityModelTextAreaEditor add new line only at the end of the text