@Override
 public void onEnterKeyPressed() {
   if (wizard.hasNext() && currentPage.isCompleted()) {
     onNextClicked();
   } else if (wizard.canComplete()) {
     onImportClicked();
   }
 }
  /** Creates and returns 'default' project wizard with pre-defined pages only. */
  private ImportWizard createDefaultWizard() {
    final ProjectConfigDto dataObject =
        dtoFactory
            .createDto(ProjectConfigDto.class)
            .withSource(dtoFactory.createDto(SourceStorageDto.class).withType("").withLocation(""));

    final ImportWizard importWizard = importWizardFactory.newWizard(dataObject);
    importWizard.setUpdateDelegate(this);
    // add pre-defined first page
    importWizard.addPage(mainPage);
    return importWizard;
  }
 @Override
 public void onBackClicked() {
   final WizardPage prevPage = wizard.navigateToPrevious();
   if (prevPage != null) {
     showPage(prevPage);
   }
 }
 @Override
 public void onNextClicked() {
   final WizardPage nextPage = wizard.navigateToNext();
   if (nextPage != null) {
     showPage(nextPage);
   }
 }
  public void show() {
    resetState();

    wizard = createDefaultWizard();
    final WizardPage<ProjectConfigDto> firstPage = wizard.navigateToFirst();
    if (firstPage != null) {
      showPage(firstPage);
      view.showDialog();
    }
  }
  @Override
  public void onImporterSelected(ProjectImporterDescriptor importer) {
    final ProjectConfigDto prevData = wizard.getDataObject();
    wizard = getWizardForImporter(importer);
    final ProjectConfigDto dataObject = wizard.getDataObject();

    dataObject.getSource().setType(importer.getId());

    // some values should be shared between wizards for different project types
    dataObject.setName(prevData.getName());
    dataObject.setDescription(prevData.getDescription());

    WizardPage<ProjectConfigDto> firstPage = wizard.navigateToFirst();
    if (firstPage != null) {
      firstPage.init(dataObject);
    }

    WizardPage<ProjectConfigDto> importerPage = wizard.navigateToNext();
    importerPage.go(mainPage.getImporterPanel());
  }
  /** Creates or returns import wizard for the specified importer. */
  private ImportWizard getWizardForImporter(@NotNull ProjectImporterDescriptor importer) {
    if (wizardsCache.containsKey(importer)) {
      return wizardsCache.get(importer);
    }

    final ImportWizardRegistrar wizardRegistrar =
        wizardRegistry.getWizardRegistrar(importer.getId());
    if (wizardRegistrar == null) {
      // should never occur
      throw new IllegalStateException(
          "WizardRegistrar for the importer " + importer.getId() + " isn't registered.");
    }

    List<Provider<? extends WizardPage<ProjectConfigDto>>> pageProviders =
        wizardRegistrar.getWizardPages();
    final ImportWizard importWizard = createDefaultWizard();
    for (Provider<? extends WizardPage<ProjectConfigDto>> provider : pageProviders) {
      importWizard.addPage(provider.get(), 1, false);
    }

    wizardsCache.put(importer, importWizard);
    return importWizard;
  }
  @Override
  public void onImportClicked() {
    view.setLoaderVisibility(true);
    wizard.complete(
        new Wizard.CompleteCallback() {
          @Override
          public void onCompleted() {
            view.close();
          }

          @Override
          public void onFailure(Throwable e) {
            view.setLoaderVisibility(false);
            dialogFactory.createMessageDialog("", e.getMessage(), null).show();
          }
        });
  }
 @Override
 public void updateControls() {
   view.setBackButtonEnabled(false);
   view.setNextButtonEnabled(wizard.hasNext() && currentPage.isCompleted());
   view.setImportButtonEnabled(wizard.canComplete());
 }