@Override
  public void startWizard() {
    getWizardPanel().addStyleClass("JobWizardPanel");
    getWizardPanel().showWizard();

    final WizardIdentifier wizardIdentifier = getWizardIdentifier();

    if (_datastoreIdentifier == null) {
      if (wizardIdentifier == null || wizardIdentifier.isDatastoreConsumer()) {
        showDatastoreSelection();
        return;
      }
    }

    if (wizardIdentifier == null) {
      showWizardSelection();
      return;
    }

    getWizardPanel().setHeader("Build job: " + wizardIdentifier.getDisplayName());
    setLoading();

    WizardServiceAsync wizardService = getWizardService();
    wizardService.startJobWizard(
        getTenant(),
        wizardIdentifier,
        _datastoreIdentifier,
        getLocaleName(),
        createNextPageCallback());
  }
  private void showNonDatastoreConsumingWizardSelection(
      final FlowPanel panel, final List<WizardIdentifier> wizards, final List<RadioButton> radios) {
    if (wizards == null || wizards.isEmpty()) {
      // do nothing
      return;
    }

    panel.add(new Label("Or select a different job type ..."));
    for (final WizardIdentifier wizard : wizards) {
      final RadioButton radio = new RadioButton("initialSelection", wizard.getDisplayName());
      radio.addClickHandler(
          new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
              GWT.log(
                  "Clicked: " + wizard + " - expected " + wizard.getExpectedPageCount() + " pages");
              _stepsBeforeWizardPages = 1;
              setSteps(wizard.getExpectedPageCount() + getStepsBeforeWizardPages(), false);
              setProgress(0);
            }
          });
      panel.add(radio);
      radios.add(radio);
    }

    getWizardPanel().refreshUI();
  }
  private void showWizardSelection(final List<WizardIdentifier> wizards) {
    final int progress = _stepsBeforeWizardPages - 1;

    final FlowPanel panel = new FlowPanel();

    panel.add(new Label("Please select the type of job to build:"));

    final List<RadioButton> radios = new ArrayList<RadioButton>(wizards.size());

    if (wizards == null || wizards.isEmpty()) {
      panel.add(new Label("(no job wizards available)"));
    } else {
      for (final WizardIdentifier wizard : wizards) {
        final RadioButton radio = new RadioButton("wizardIdentifier", wizard.getDisplayName());
        radio.addClickHandler(
            new ClickHandler() {
              @Override
              public void onClick(ClickEvent event) {
                setSteps(wizard.getExpectedPageCount() + getStepsBeforeWizardPages());
                setProgress(progress);
              }
            });
        panel.add(radio);
        radios.add(radio);
      }
    }

    setNextClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            for (int i = 0; i < radios.size(); i++) {
              final RadioButton radio = radios.get(i);
              if (radio.getValue().booleanValue()) {
                final WizardIdentifier wizard = wizards.get(i);
                setWizardIdentifier(wizard);
                startWizard();
                return;
              }
            }

            // no job wizard is selected if we reach this point
            throw new DCUserInputException("Please select a job type to create");
          }
        });

    setProgress(progress);
    setContent(panel);
  }
  public JobWizardController(
      WizardPanel wizardPanel,
      TenantIdentifier tenant,
      WizardIdentifier wizardIdentifier,
      DatastoreIdentifier datastoreIdentifier,
      WizardServiceAsync wizardService) {
    super(wizardPanel, tenant, wizardIdentifier, wizardService);
    _datastoreIdentifier = datastoreIdentifier;

    _stepsBeforeWizardPages = 0;
    if (wizardIdentifier == null) {
      _stepsBeforeWizardPages++;
    }
    if (datastoreIdentifier == null) {
      if (wizardIdentifier == null || wizardIdentifier.isDatastoreConsumer()) {
        _stepsBeforeWizardPages++;
      }
    }
  }