package com.byteowls.vaadin.medium.editor;

import com.vaadin.ui.Component;
import com.vaadin.ui.CustomField;

public class MediumEditorField extends CustomField<String> {

  private static final long serialVersionUID = -741003307371028467L;
  
  private MediumEditor editor;
  private boolean valueReceived = false; 
  
  @SuppressWarnings("serial")
  public MediumEditorField(String caption) {
    setCaption(caption);
    
    addValueChangeListener(new ValueChangeListener() {
      @Override
      public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
        if (!valueReceived) {
          getEditor().setContent(getValue());
        } else {
          valueReceived = false;
        }
      }
    });
  }
  
  public MediumEditor getEditor() {
    if (editor == null) {
      editor = new MediumEditor();
      editor.addValueChangeListener(new MediumEditor.ValueChangeListener() {
        @Override
        public void valueChange(String value) {
          valueReceived = true;
          setValue(value);
        }
      });
    }
    return editor;
  }

  @Override
  protected Component initContent() {
    addStyleName("v-textarea");
    return getEditor();
  }

  @Override
  public Class<? extends String> getType() {
    return String.class;
  }

}

@@ -37,16 +37,49 @@
 ditor;%0A%0A
+import com.vaadin.data.Property;%0A
 import c
@@ -308,80 +308,8 @@
 ;%0A  
-private boolean valueReceived = false; %0A  %0A  @SuppressWarnings(%22serial%22)
 %0A  p
@@ -381,167 +381,123 @@
 ;%0A  
+%7D%0A
   %0A  
-  addValueChangeListener(new ValueChangeListener() %7B%0A      @Override%0A      public void valueChange(com.vaadin.data.Property.ValueChangeEvent event
+@Override%0A  @SuppressWarnings(%22rawtypes%22)%0A  public void setPropertyDataSource(Property newDataSource
 ) %7B%0A    
     
@@ -496,162 +496,96 @@
     
- 
-   if (!valueReceived) %7B%0A          getEditor().setContent(getValue());%0A        %7D else %7B%0A          valueReceived = false;%0A        %7D%0A      %7D%0A    %7D);%0A  %7D%0A  
+super.setPropertyDataSource(newDataSource);%0A    getEditor().setContent(getValue());%0A  %7D%0A
 %0A  p
@@ -825,40 +825,8 @@
 ) %7B%0A
-          valueReceived = true;%0A
     

set editor content on FieldGroup.bind #2