package jetbrains.mps.ide.migration.wizard;

/*Generated by MPS */

import jetbrains.mps.annotations.GeneratedClass;
import com.intellij.ide.wizard.AbstractWizardEx;
import com.intellij.openapi.project.Project;
import java.util.List;
import jetbrains.mps.migration.global.ProjectMigration;
import jetbrains.mps.internal.collections.runtime.Sequence;
import jetbrains.mps.migration.global.ProjectMigrationWithOptions;
import jetbrains.mps.baseLanguage.closures.runtime._FunctionTypes;
import java.util.Collection;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import java.util.ArrayList;
import javax.swing.JButton;

@GeneratedClass(node = "a5b1c28d-abeb-49a6-a58c-559039616d64/r:49062720-8530-4489-916a-fdd3a02a7b82(jetbrains.mps.migration.component/jetbrains.mps.ide.migration.wizard)/6781485246382122883", model = "a5b1c28d-abeb-49a6-a58c-559039616d64/r:49062720-8530-4489-916a-fdd3a02a7b82(jetbrains.mps.migration.component/jetbrains.mps.ide.migration.wizard)")
public class MigrationWizard extends AbstractWizardEx {
  public MigrationWizard(Project project, MigrationSession session) {
    super("Migration Assistant Wizard", project, createSteps(session));
    setSize(700, 400);
  }

  private static List<BaseStep> createSteps(final MigrationSession session) {
    Iterable<ProjectMigration> projectMig = session.getProjectMigrations();
    Sequence.fromIterable(projectMig).ofType(ProjectMigrationWithOptions.class).translate(new _FunctionTypes._return_P1_E0<Collection<ProjectMigrationWithOptions.Option>, ProjectMigrationWithOptions>() {
      public Collection<ProjectMigrationWithOptions.Option> invoke(ProjectMigrationWithOptions it) {
        return it.getOptions();
      }
    }).visitAll(new _FunctionTypes._void_P1_E0<ProjectMigrationWithOptions.Option>() {
      public void invoke(ProjectMigrationWithOptions.Option it) {
        session.getOptions().addOption(it);
      }
    });

    return ListSequence.fromListAndArray(new ArrayList<BaseStep>(), new InitialStep(session), new MigrationStep(session));
  }

  @Override
  public boolean isAutoAdjustable() {
    return true;
  }

  @Override
  protected void updateButtons() {
    super.updateButtons();
    // our steps can provide different next/prev button texts
    getCancelButton().setEnabled((getStep()).canBeCancelled());

    String nextLabel = (getStep()).nextButtonLabel();
    if (nextLabel != null) {
      JButton nextButton = getNextButton();
      nextButton.setText(nextLabel);
      nextButton.setMnemonic(nextLabel.charAt(0));
    }
    String cancelLabel = (getStep()).cancelButtonLabel();
    if (cancelLabel != null) {
      getCancelButton().setText(cancelLabel);
    }
  }

  @Override
  protected void doNextAction() {
    getStep().nextButtonAction();
    // it's important to call step's listener first not to affect state in which it's called
    super.doNextAction();
  }

  @Override
  public void doCancelAction() {
    getStep().cancelButtonAction();
    // it's important to call step's listener first not to affect state in which it's called
    super.doCancelAction();
  }

  private BaseStep getStep() {
    return (BaseStep) getCurrentStepObject();
  }

  @Override
  protected String getHelpID() {
    return "migration.assistant";
  }

  @Override
  protected String getDimensionServiceKey() {
    return "#jetbrains.mps.ide.migration.MigrationAssistantWizard";
  }
}
