package jetbrains.mps.vcs.diff.ui.common;

/*Generated by MPS */

import jetbrains.mps.annotations.GeneratedClass;
import jetbrains.mps.vcs.diff.ChangeSet;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;
import jetbrains.mps.openapi.editor.update.UpdaterListener;
import jetbrains.mps.openapi.editor.update.UpdaterListenerAdapter;
import jetbrains.mps.openapi.editor.EditorComponent;
import java.util.List;
import jetbrains.mps.vcs.diff.changes.ModelChange;

@GeneratedClass(node = "r:07568eb8-30c0-4bb3-9dcb-50ee4b8de59a(jetbrains.mps.vcs.diff.ui.common)/6402272430682108518", model = "r:07568eb8-30c0-4bb3-9dcb-50ee4b8de59a(jetbrains.mps.vcs.diff.ui.common)")
public class DiffChangeGroupLayout extends ChangeGroupLayout {
  private DiffEditor myLeftEditor;
  private DiffEditor myRightEditor;
  private ChangeSet myChangeSet;
  private SplitterRepainter mySplitterRepainter;


  public DiffChangeGroupLayout(@Nullable ChangeEditorMessage.ConflictChecker conflictChecker, @NotNull ChangeSet changeSet, @NotNull DiffEditor leftEditor, @NotNull DiffEditor rightEditor, SplitterRepainter splitterRepainter, boolean inspector) {
    super(conflictChecker, inspector, false);
    myLeftEditor = leftEditor;
    myRightEditor = rightEditor;
    myChangeSet = changeSet;
    mySplitterRepainter = splitterRepainter;
    if (inspector) {
      UpdaterListener updaterListener = new UpdaterListenerAdapter() {
        @Override
        public void editorUpdated(EditorComponent editorComponent) {
          invalidate();
        }
      };
      myLeftEditor.getInspector().getUpdater().addListener(updaterListener);
      myRightEditor.getInspector().getUpdater().addListener(updaterListener);
    }
  }

  @NotNull
  @Override
  public jetbrains.mps.nodeEditor.EditorComponent getLeftComponent() {
    return myLeftEditor.getEditorComponent(myInspector);
  }
  @NotNull
  @Override
  public jetbrains.mps.nodeEditor.EditorComponent getRightComponent() {
    return myRightEditor.getEditorComponent(myInspector);
  }
  @Override
  protected List<ChangeEditorMessage> getLeftMessages(ModelChange change) {
    return myLeftEditor.getMessagesForChange(change);
  }
  @Override
  protected List<ChangeEditorMessage> getRightMessages(ModelChange change) {
    return myRightEditor.getMessagesForChange(change);
  }
  @Nullable
  @Override
  protected ChangeSet getChangeSet() {
    return myChangeSet;
  }
  public void setChangeSet(ChangeSet changeSet) {
    myChangeSet = changeSet;
  }

  public void repaintSplitter() {
    if (mySplitterRepainter != null) {
      mySplitterRepainter.repaintSplitter();
    }
  }

  public interface SplitterRepainter {
    void repaintSplitter();
  }

  public DiffEditor getDiffEditor(boolean left) {
    return (left ? myLeftEditor : myRightEditor);
  }
}
