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

/*Generated by MPS */

import jetbrains.mps.annotations.GeneratedClass;
import jetbrains.mps.workbench.action.BaseAction;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.actionSystem.AnActionEvent;
import java.util.Map;
import jetbrains.mps.internal.collections.runtime.Sequence;
import jetbrains.mps.vcs.diff.changes.ModelChange;

@GeneratedClass(node = "r:351fe3d9-2ce5-4ea0-8afc-9b076259a949(jetbrains.mps.vcs.diff.ui.merge)/708166622413808756", model = "r:351fe3d9-2ce5-4ea0-8afc-9b076259a949(jetbrains.mps.vcs.diff.ui.merge)")
public class ApplyNonConflictsForRoot extends BaseAction implements DumbAware {
  private MergeRootsPane myPane;
  public ApplyNonConflictsForRoot(MergeRootsPane pane) {
    super("Apply Non-Conflicting Changes", null, MergeModelsPanel.APPLY_NON_CONFLICTS);
    myPane = pane;
    setDisableOnNoProject(false);
  }

  @Override
  protected void doExecute(AnActionEvent event, Map<String, Object> map) {
    myPane.getMergeSession().applyChanges(getChanges());
    myPane.rehighlight();
  }
  @Override
  protected void doUpdate(AnActionEvent event, Map<String, Object> map) {
    event.getPresentation().setEnabled(Sequence.fromIterable(getChanges()).isNotEmpty());
  }
  private Iterable<ModelChange> getChanges() {
    return myPane.getMergeSession().getApplicableChangesForRoot(myPane.getRootId());
  }
}
