package jetbrains.mps.vcs.plugin;
/*Generated by MPS */
import jetbrains.mps.workbench.action.BaseAction;
import javax.swing.Icon;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnActionEvent;
import java.util.Map;
import java.util.List;
import org.jetbrains.mps.openapi.model.SModel;
import jetbrains.mps.internal.collections.runtime.MapSequence;
import jetbrains.mps.extapi.model.TransientSModel;
import jetbrains.mps.util.NameUtil;
import org.jetbrains.annotations.NotNull;
import jetbrains.mps.ide.actions.MPSCommonDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import jetbrains.mps.ide.ui.tree.SortUtil;
import com.intellij.diff.contents.DiffContent;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import jetbrains.mps.internal.collections.runtime.ISelector;
import jetbrains.mps.vcs.platform.integration.ModelDiffContent;
import com.intellij.diff.requests.DiffRequest;
import com.intellij.diff.requests.SimpleDiffRequest;
import com.intellij.diff.DiffManager;
public class CompareTransientModels_Action extends BaseAction {
private static final Icon ICON = AllIcons.Actions.Diff;
public CompareTransientModels_Action() {
super("Compare Models", "", ICON);
this.setIsAlwaysVisible(false);
this.setExecuteOutsideCommand(true);
}
@Override
public boolean isDumbAware() {
return true;
}
@Override
public boolean isApplicable(AnActionEvent event, final Map<String, Object> _params) {
return ((List<SModel>) MapSequence.fromMap(_params).get("models")).size() == 2 && ((List<SModel>) MapSequence.fromMap(_params).get("models")).get(0) instanceof TransientSModel && ((List<SModel>) MapSequence.fromMap(_params).get("models")).get(1) instanceof TransientSModel && eq_5whyyr_a0a0a4(NameUtil.getModelLongName(((List<SModel>) MapSequence.fromMap(_params).get("models")).get(0)), NameUtil.getModelLongName(((List<SModel>) MapSequence.fromMap(_params).get("models")).get(1)));
}
@Override
public void doUpdate(@NotNull AnActionEvent event, final Map<String, Object> _params) {
this.setEnabledState(event.getPresentation(), this.isApplicable(event, _params));
}
@Override
protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) {
if (!(super.collectActionData(event, _params))) {
return false;
}
{
List<SModel> p = event.getData(MPSCommonDataKeys.MODELS);
MapSequence.fromMap(_params).put("models", p);
if (p == null) {
return false;
}
}
{
Project p = event.getData(CommonDataKeys.PROJECT);
MapSequence.fromMap(_params).put("project", p);
if (p == null) {
return false;
}
}
return true;
}
@Override
public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) {
List<SModel> sortedModels = SortUtil.sortModels(((List<SModel>) MapSequence.fromMap(_params).get("models")));
List<DiffContent> contents = ListSequence.fromList(sortedModels).select(new ISelector<SModel, DiffContent>() {
public DiffContent select(SModel model) {
return (DiffContent) new ModelDiffContent(model);
}
}).toListSequence();
List<String> titles = ListSequence.fromList(sortedModels).select(new ISelector<SModel, String>() {
public String select(SModel model) {
return model.getName() + "";
}
}).toListSequence();
DiffRequest request = new SimpleDiffRequest("", contents, titles);
DiffManager.getInstance().showDiff(((Project) MapSequence.fromMap(_params).get("project")), request);
}
private static boolean eq_5whyyr_a0a0a4(Object a, Object b) {
return (a != null ? a.equals(b) : a == b);
}
}