package jetbrains.mps.migration.component.plugin;
/*Generated by MPS */
import jetbrains.mps.workbench.action.BaseAction;
import javax.swing.Icon;
import jetbrains.mps.migration.global.ProjectMigration;
import org.jetbrains.annotations.NotNull;
import com.intellij.openapi.actionSystem.AnActionEvent;
import java.util.Map;
import jetbrains.mps.project.MPSProject;
import jetbrains.mps.ide.actions.MPSCommonDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.util.WaitForProgressToShow;
public class RunProjectMigration_Action extends BaseAction {
private static final Icon ICON = null;
private ProjectMigration script;
public RunProjectMigration_Action(ProjectMigration script_par) {
super("Run", "", ICON);
this.script = script_par;
this.setIsAlwaysVisible(false);
this.setExecuteOutsideCommand(true);
}
@Override
public boolean isDumbAware() {
return false;
}
@Override
public void doUpdate(@NotNull AnActionEvent event, final Map<String, Object> _params) {
event.getPresentation().setText(RunProjectMigration_Action.this.script.getDescription());
}
@Override
protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) {
if (!(super.collectActionData(event, _params))) {
return false;
}
{
MPSProject p = event.getData(MPSCommonDataKeys.MPS_PROJECT);
if (p == null) {
return false;
}
}
{
Project p = event.getData(CommonDataKeys.PROJECT);
if (p == null) {
return false;
}
}
return true;
}
@Override
public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) {
ProgressManager.getInstance().run(new Task.Modal(event.getData(CommonDataKeys.PROJECT), "Run Migration", true) {
public void run(@NotNull ProgressIndicator progressIndicator) {
progressIndicator.setText(RunProjectMigration_Action.this.script.getDescription());
progressIndicator.setIndeterminate(true);
WaitForProgressToShow.runOrInvokeAndWaitAboveProgress(new Runnable() {
public void run() {
event.getData(MPSCommonDataKeys.MPS_PROJECT).getRepository().getModelAccess().executeCommand(new Runnable() {
public void run() {
RunProjectMigration_Action.this.script.execute(event.getData(MPSCommonDataKeys.MPS_PROJECT));
}
});
}
});
}
});
}
@NotNull
public String getActionId() {
StringBuilder res = new StringBuilder();
res.append(super.getActionId());
res.append("#");
res.append(script_State((ProjectMigration) this.script));
res.append("!");
return res.toString();
}
public static String script_State(ProjectMigration object) {
return object.getClass().getName();
}
}