Ejemplo n.º 1
0
  private void initModuleWizard(
      final Project project,
      final ModulesProvider modulesProvider,
      @Nullable final String defaultPath) {
    myWizardContext = new WizardContext(project);
    if (defaultPath != null) {
      myWizardContext.setProjectFileDirectory(defaultPath);
      myWizardContext.setProjectName(
          defaultPath.substring(
              FileUtil.toSystemIndependentName(defaultPath).lastIndexOf("/") + 1));
    }
    myWizardContext.addContextListener(
        new WizardContext.Listener() {
          public void buttonsUpdateRequested() {
            updateButtons();
          }

          public void nextStepRequested() {
            doNextAction();
          }
        });

    myRootStep =
        new ProjectCreateModeStep(defaultPath, myWizardContext) {
          protected void update() {
            updateButtons();
          }
        };
    addStep(myRootStep);
    for (WizardMode mode : myRootStep.getModes()) {
      appendSteps(mode.getSteps(myWizardContext, modulesProvider));
    }
    init();
  }
 /**
  * Instructs current step to use given mode.
  *
  * @param mode mode to set active
  * @throws IllegalArgumentException if given mode is not registered at the current step (not
  *     contained at {@link #getModes()})
  */
 public void setMode(@NotNull WizardMode mode) throws IllegalArgumentException {
   if (!myModes.contains(mode)) {
     throw new IllegalArgumentException(
         String.format(
             "Can't activate given mode (%s) to the %s object. Reason: it's not contained in registered modes (%s)",
             mode, getClass().getName(), myModes));
   }
   myMode.onChosen(false);
   myMode = mode;
   myMode.onChosen(true);
   update();
 }
  public ProjectCreateModeStep(final String defaultPath, final WizardContext wizardContext) {
    final StringBuilder buf = new StringBuilder();
    for (WizardMode mode : Extensions.getExtensions(WizardMode.MODES)) {
      if (mode.isAvailable(wizardContext)) {
        myModes.add(mode);
        if (defaultPath != null && wizardContext.isCreatingNewProject()) {
          if (mode instanceof CreateFromSourcesMode) {
            myMode = mode;
          }
        } else if (mode instanceof CreateFromScratchMode) {
          myMode = mode;
        }
      }
      final String footnote = mode.getFootnote(wizardContext);
      if (footnote != null) {
        if (buf.length() > 0) buf.append("<br>");
        buf.append(footnote);
      }
    }

    if (myMode == null) {
      myMode = myModes.get(0);
    }

    myWizardContext = wizardContext;
    myWholePanel = new JPanel(new GridBagLayout());
    myWholePanel.setBorder(BorderFactory.createEtchedBorder());

    final Insets insets = new Insets(0, 0, 0, 5);
    GridBagConstraints gc =
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1,
            0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            insets,
            0,
            0);
    final ButtonGroup group = new ButtonGroup();
    for (final WizardMode mode : myModes) {
      insets.top = 15;
      insets.left = 5;
      final JRadioButton rb = new JRadioButton(mode.getDisplayName(wizardContext), mode == myMode);
      rb.setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD));
      rb.addActionListener(
          new ActionListener() {
            public void actionPerformed(final ActionEvent e) {
              setMode(mode);
            }
          });
      rb.addMouseListener(
          new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
              if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
                wizardContext.requestNextStep();
              }
            }
          });

      myWholePanel.add(rb, gc);
      group.add(rb);
      insets.top = 5;
      insets.left = 20;
      final JLabel description = new JLabel(mode.getDescription(wizardContext));
      myWholePanel.add(description, gc);
      final JComponent settings = mode.getAdditionalSettings(wizardContext);
      if (settings != null) {
        myWholePanel.add(settings, gc);
      }
    }
    myMode.onChosen(true);
    gc.weighty = 1;
    gc.fill = GridBagConstraints.BOTH;
    myWholePanel.add(Box.createVerticalBox(), gc);
    final JLabel note =
        new JLabel(
            "<html>" + buf.toString() + "</html>",
            IconLoader.getIcon("/nodes/warningIntroduction.png"),
            SwingConstants.LEFT);
    note.setVisible(buf.length() > 0);
    gc.weighty = 0;
    gc.fill = GridBagConstraints.HORIZONTAL;
    gc.insets.bottom = 5;
    myWholePanel.add(note, gc);
  }
 @Override
 public boolean validate() throws ConfigurationException {
   return super.validate() && myMode.validate();
 }
 public void updateDataModel() {
   myWizardContext.setProjectBuilder(myMode.getModuleBuilder());
 }