/*
 * Copyright 2017 The Chromium Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
package io.flutter.actions;


import com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder;
import com.android.tools.idea.wizard.model.ModelWizard;
import com.android.tools.idea.wizard.model.ModelWizardDialog;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.DumbAware;
import io.flutter.module.FlutterProjectType;
import io.flutter.project.ChoseProjectTypeStep;
import io.flutter.project.FlutterProjectModel;
import org.jetbrains.annotations.NotNull;

import java.util.NoSuchElementException;

public class FlutterNewProjectAction extends AnAction implements DumbAware {
  public FlutterNewProjectAction() {
    this("New Flutter Project...");
  }

  public FlutterNewProjectAction(@NotNull String text) {
    super(text);
  }

  @Override
  public void update(@NotNull AnActionEvent e) {
    // This can be used to change the icon on the welcome screen, if needed.
  }

  @Override
  public void actionPerformed(AnActionEvent e) {
    FlutterProjectModel model = new FlutterProjectModel(FlutterProjectType.APP);
    ModelWizard wizard = new ModelWizard.Builder()
      .addStep(new ChoseProjectTypeStep(model))
      .build();
    ModelWizardDialog dialog =
      new StudioWizardDialogBuilder(wizard, "Create New Flutter Project").setUseNewUx(true).build();
    try {
      dialog.show();
    }
    catch (NoSuchElementException ex) {
      // This happens if no Flutter SDK is installed and the user cancels the FlutterProjectStep.
    }
  }
}

@@ -487,16 +487,63 @@
 nEvent;%0A
+import com.intellij.openapi.diagnostic.Logger;%0A
 import c
@@ -780,114 +780,362 @@
 ava.
-util.NoSuchElementException;%0A%0Apublic class FlutterNewProjectAction extends AnAction implements DumbAware %7B
+lang.reflect.InvocationTargetException;%0Aimport java.lang.reflect.Method;%0Aimport java.util.NoSuchElementException;%0A%0Aimport static com.intellij.util.ReflectionUtil.getMethod;%0A%0Apublic class FlutterNewProjectAction extends AnAction implements DumbAware %7B%0A  private static final Logger LOG = Logger.getInstance(%22#io.flutter.actions.FlutterNewProjectAction%22);%0A
 %0A  p
@@ -1688,29 +1688,30 @@
 uild();%0A    
-Model
+Studio
 WizardDialog
@@ -1714,23 +1714,25 @@
 alog
- dialog =%0A     
+Builder builder =
  new
@@ -1799,26 +1799,423 @@
 ct%22)
-.setUseNewUx(true)
+;%0A    // TODO(messick) Remove this reflection call after 3.2 is stable.%0A    Method method = getMethod(builder.getClass(), %22setUseNewUx%22, Boolean.class);%0A    if (method != null) %7B%0A      try %7B%0A        method.invoke(builder, Boolean.TRUE);%0A      %7D%0A      catch (IllegalAccessException %7C InvocationTargetException e1) %7B%0A        LOG.error(e1);%0A      %7D%0A    %7D // End of code to remove%0A    ModelWizardDialog dialog = builder
 .bui

Remove hard dependency on deprecated method (#1894)