コード例 #1
0
 @Nullable
 public static Sdk getNewProjectJdk(WizardContext context) {
   if (context.getProjectJdk() != null) {
     return context.getProjectJdk();
   }
   final Project project =
       context.getProject() == null
           ? ProjectManager.getInstance().getDefaultProject()
           : context.getProject();
   final Sdk projectJdk = ProjectRootManager.getInstance(project).getProjectSdk();
   if (projectJdk != null) {
     return projectJdk;
   }
   if (context.getProject() == null) {
     @Nullable final ProjectBuilder projectBuilder = context.getProjectBuilder();
     return ProjectJdkTable.getInstance()
         .findMostRecentSdk(
             new Condition<Sdk>() {
               public boolean value(Sdk sdk) {
                 return projectBuilder == null || projectBuilder.isSuitableSdk(sdk);
               }
             });
   }
   return null;
 }
コード例 #2
0
 @NotNull
 @Override
 protected LuaSdkChooserPanel compute() {
   return new LuaSdkChooserPanel(
       myContext.getProject() == null
           ? ProjectManager.getInstance().getDefaultProject()
           : myContext.getProject());
 }
コード例 #3
0
 private void validateExistingModuleName() throws ConfigurationException {
   final String moduleName = getModuleName();
   final Module module;
   final ProjectStructureConfigurable fromConfigurable =
       ProjectStructureConfigurable.getInstance(myWizardContext.getProject());
   if (fromConfigurable != null) {
     module = fromConfigurable.getModulesConfig().getModule(moduleName);
   } else {
     module = ModuleManager.getInstance(myWizardContext.getProject()).findModuleByName(moduleName);
   }
   if (module != null) {
     throw new ConfigurationException(
         "Module \'" + moduleName + "\' already exist in project. Please, specify another name.");
   }
 }
 /**
  * Allows to get {@link Project} instance to use. Basically, there are two alternatives - {@link
  * WizardContext#getProject() project from the current wizard context} and {@link
  * ProjectManager#getDefaultProject() default project}.
  *
  * @param wizardContext current wizard context
  * @return {@link Project} instance to use
  */
 @NotNull
 public Project getProject(@NotNull WizardContext wizardContext) {
   Project result = wizardContext.getProject();
   if (result == null) {
     result = ProjectManager.getInstance().getDefaultProject();
   }
   return result;
 }
コード例 #5
0
 private String getDefaultBaseDir(WizardContext wizardContext) {
   if (wizardContext.isCreatingNewProject()) {
     return myNamePathComponent.getPath();
   } else {
     final Project project = wizardContext.getProject();
     assert project != null;
     final VirtualFile baseDir = project.getBaseDir();
     if (baseDir != null) {
       return baseDir.getPath();
     }
     return "";
   }
 }
コード例 #6
0
 void loadRemoteTemplates(final ChooseTemplateStep chooseTemplateStep) {
   ProgressManager.getInstance()
       .run(
           new Task.Backgroundable(myContext.getProject(), "Loading Templates") {
             @Override
             public void run(@NotNull ProgressIndicator indicator) {
               try {
                 myTemplatesList.setPaintBusy(true);
                 chooseTemplateStep.getTemplateList().setPaintBusy(true);
                 RemoteTemplatesFactory factory = new RemoteTemplatesFactory();
                 String[] groups = factory.getGroups();
                 for (String group : groups) {
                   ProjectTemplate[] templates = factory.createTemplates(group, myContext);
                   for (ProjectTemplate template : templates) {
                     String id = ((ArchivedProjectTemplate) template).getCategory();
                     for (TemplatesGroup templatesGroup : myTemplatesMap.keySet()) {
                       if (Comparing.equal(id, templatesGroup.getId())
                           || Comparing.equal(group, templatesGroup.getName())) {
                         myTemplatesMap.putValue(templatesGroup, template);
                       }
                     }
                   }
                 }
                 //noinspection SSBasedInspection
                 SwingUtilities.invokeLater(
                     new Runnable() {
                       public void run() {
                         TemplatesGroup group = getSelectedGroup();
                         if (group == null) return;
                         Collection<ProjectTemplate> templates = myTemplatesMap.get(group);
                         setTemplatesList(group, templates, true);
                         chooseTemplateStep.updateStep();
                       }
                     });
               } finally {
                 myTemplatesList.setPaintBusy(false);
                 chooseTemplateStep.getTemplateList().setPaintBusy(false);
               }
             }
           });
 }
コード例 #7
0
  public ProjectTypeStep(
      WizardContext context, NewProjectWizard wizard, ModulesProvider modulesProvider) {
    myContext = context;
    myWizard = wizard;

    myTemplatesMap = new ConcurrentMultiMap<TemplatesGroup, ProjectTemplate>();
    final List<TemplatesGroup> groups = fillTemplatesMap(context);

    myProjectTypeList.setModel(new CollectionListModel<TemplatesGroup>(groups));
    myProjectTypeList.setSelectionModel(new SingleSelectionModel());
    myProjectTypeList.addListSelectionListener(
        new ListSelectionListener() {
          @Override
          public void valueChanged(ListSelectionEvent e) {
            updateSelection();
          }
        });
    myProjectTypeList.setCellRenderer(
        new GroupedItemsListRenderer(
            new ListItemDescriptorAdapter<TemplatesGroup>() {
              @Nullable
              @Override
              public String getTextFor(TemplatesGroup value) {
                return value.getName();
              }

              @Nullable
              @Override
              public String getTooltipFor(TemplatesGroup value) {
                return value.getDescription();
              }

              @Nullable
              @Override
              public Icon getIconFor(TemplatesGroup value) {
                return value.getIcon();
              }

              @Override
              public boolean hasSeparatorAboveOf(TemplatesGroup value) {
                int index = groups.indexOf(value);
                if (index < 1) return false;
                TemplatesGroup upper = groups.get(index - 1);
                if (upper.getParentGroup() == null && value.getParentGroup() == null) return true;
                return !Comparing.equal(upper.getParentGroup(), value.getParentGroup())
                    && !Comparing.equal(upper.getName(), value.getParentGroup());
              }
            }) {
          @Override
          protected JComponent createItemComponent() {
            JComponent component = super.createItemComponent();
            myTextLabel.setBorder(IdeBorderFactory.createEmptyBorder(3));
            return component;
          }
        });

    new ListSpeedSearch(myProjectTypeList) {
      @Override
      protected String getElementText(Object element) {
        return ((TemplatesGroup) element).getName();
      }
    };

    myModulesProvider = modulesProvider;
    Project project = context.getProject();
    final LibrariesContainer container =
        LibrariesContainerFactory.createContainer(context, modulesProvider);
    FrameworkSupportModelBase model =
        new FrameworkSupportModelBase(project, null, container) {
          @NotNull
          @Override
          public String getBaseDirectoryForLibrariesPath() {
            ModuleBuilder builder = getSelectedBuilder();
            return StringUtil.notNullize(builder.getContentEntryPath());
          }

          @Override
          public ModuleBuilder getModuleBuilder() {
            return getSelectedBuilder();
          }
        };
    myFrameworksPanel =
        new AddSupportForFrameworksPanel(
            Collections.<FrameworkSupportInModuleProvider>emptyList(), model, true, myHeaderPanel);
    Disposer.register(this, myFrameworksPanel);
    myFrameworksPanelPlaceholder.add(myFrameworksPanel.getMainPanel());

    myConfigurationUpdater =
        new ModuleBuilder.ModuleConfigurationUpdater() {
          @Override
          public void update(@NotNull Module module, @NotNull ModifiableRootModel rootModel) {
            if (isFrameworksMode()) {
              myFrameworksPanel.addSupport(module, rootModel);
            }
          }
        };

    myProjectTypeList
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e) {
                projectTypeChanged();
              }
            });

    myTemplatesList.addListSelectionListener(
        new ListSelectionListener() {
          @Override
          public void valueChanged(ListSelectionEvent e) {
            updateSelection();
          }
        });

    for (TemplatesGroup templatesGroup : myTemplatesMap.keySet()) {
      ModuleBuilder builder = templatesGroup.getModuleBuilder();
      if (builder != null) {
        myWizard.getSequence().addStepsForBuilder(builder, context, modulesProvider);
      }
      for (ProjectTemplate template : myTemplatesMap.get(templatesGroup)) {
        myWizard
            .getSequence()
            .addStepsForBuilder(myBuilders.get(template), context, modulesProvider);
      }
    }

    final String groupId = PropertiesComponent.getInstance().getValue(PROJECT_WIZARD_GROUP);
    if (groupId != null) {
      TemplatesGroup group =
          ContainerUtil.find(
              groups,
              new Condition<TemplatesGroup>() {
                @Override
                public boolean value(TemplatesGroup group) {
                  return groupId.equals(group.getId());
                }
              });
      if (group != null) {
        myProjectTypeList.setSelectedValue(group, true);
      }
    }
    if (myProjectTypeList.getSelectedValue() == null) {
      myProjectTypeList.setSelectedIndex(0);
    }
    myTemplatesList.restoreSelection();
  }
コード例 #8
0
 @NonNls
 public String getHelpId() {
   return myWizardContext.getProject() == null
       ? "reference.dialogs.new.project"
       : "reference.dialogs.new.module";
 }
コード例 #9
0
  public ProjectTypesList(
      JBList list,
      SearchTextField searchField,
      MultiMap<TemplatesGroup, ProjectTemplate> map,
      final WizardContext context) {
    myList = list;
    mySearchField = searchField;

    List<TemplateItem> items = buildItems(map);
    final RemoteTemplatesFactory factory = new RemoteTemplatesFactory();
    final String groupName = factory.getGroups()[0];
    final TemplatesGroup samplesGroup = new TemplatesGroup(groupName, "", null);
    myLoadingItem =
        new TemplateItem(new LoadingProjectTemplate(), samplesGroup) {
          @Override
          Icon getIcon() {
            return null;
          }

          @Override
          String getDescription() {
            return "";
          }
        };
    items.add(myLoadingItem);
    final CollectionListModel<TemplateItem> model = new CollectionListModel<TemplateItem>(items);
    myFilteringListModel = new FilteringListModel<TemplateItem>(model);

    ProgressManager.getInstance()
        .run(
            new Task.Backgroundable(context.getProject(), "Loading Samples") {
              @Override
              public void run(@NotNull ProgressIndicator indicator) {
                try {
                  myList.setPaintBusy(true);
                  final ProjectTemplate[] templates = factory.createTemplates(groupName, context);
                  Runnable runnable =
                      new Runnable() {
                        public void run() {
                          int index = myList.getSelectedIndex();
                          model.remove(myLoadingItem);
                          for (ProjectTemplate template : templates) {
                            model.add(new TemplateItem(template, samplesGroup));
                          }
                          myList.setSelectedIndex(index);
                        }
                      };
                  SwingUtilities.invokeLater(runnable);
                } finally {
                  myList.setPaintBusy(false);
                }
              }
            });

    myList.setCellRenderer(
        new GroupedItemsListRenderer(
            new ListItemDescriptor() {
              @Nullable
              @Override
              public String getTextFor(Object value) {
                return ((TemplateItem) value).getName();
              }

              @Nullable
              @Override
              public String getTooltipFor(Object value) {
                return null;
              }

              @Nullable
              @Override
              public Icon getIconFor(Object value) {
                return ((TemplateItem) value).getIcon();
              }

              @Override
              public boolean hasSeparatorAboveOf(Object value) {
                TemplateItem item = (TemplateItem) value;
                int index = myFilteringListModel.getElementIndex(item);
                return index == 0
                    || !myFilteringListModel
                        .getElementAt(index - 1)
                        .getGroupName()
                        .equals(item.getGroupName());
              }

              @Nullable
              @Override
              public String getCaptionAboveOf(Object value) {
                return ((TemplateItem) value).getGroupName();
              }
            }));

    myFilteringListModel.setFilter(
        new Condition<TemplateItem>() {
          @Override
          public boolean value(TemplateItem item) {
            return item.getMatchingDegree() > Integer.MIN_VALUE;
          }
        });

    myList.setModel(myFilteringListModel);
    mySearchField.addDocumentListener(
        new DocumentAdapter() {
          @Override
          protected void textChanged(DocumentEvent e) {
            String text = "*" + mySearchField.getText().trim();
            myMatcher = NameUtil.buildMatcher(text, NameUtil.MatchingCaseSensitivity.NONE);

            TemplateItem value = (TemplateItem) myList.getSelectedValue();
            int degree = value == null ? Integer.MIN_VALUE : value.getMatchingDegree();
            myBestMatch = Pair.create(degree > Integer.MIN_VALUE ? value : null, degree);

            myFilteringListModel.refilter();
            if (myBestMatch.first != null) {
              myList.setSelectedValue(myBestMatch.first, true);
            }
          }
        });

    new AnAction() {
      @Override
      public void actionPerformed(AnActionEvent e) {
        InputEvent event = e.getInputEvent();
        if (event instanceof KeyEvent) {
          int row = myList.getSelectedIndex();
          int toSelect;
          switch (((KeyEvent) event).getKeyCode()) {
            case KeyEvent.VK_UP:
              toSelect = row == 0 ? myList.getItemsCount() - 1 : row - 1;
              myList.setSelectedIndex(toSelect);
              myList.ensureIndexIsVisible(toSelect);
              break;
            case KeyEvent.VK_DOWN:
              toSelect = row < myList.getItemsCount() - 1 ? row + 1 : 0;
              myList.setSelectedIndex(toSelect);
              myList.ensureIndexIsVisible(toSelect);
              break;
          }
        }
      }
    }.registerCustomShortcutSet(
        new CustomShortcutSet(KeyEvent.VK_UP, KeyEvent.VK_DOWN), mySearchField);
  }
コード例 #10
0
  public void bindModuleSettings() {

    myNamePathComponent
        .getNameComponent()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (!myModuleNameChangedByUser) {
                  setModuleName(myNamePathComponent.getNameValue());
                }
              }
            });

    myModuleContentRoot.addBrowseFolderListener(
        ProjectBundle.message("project.new.wizard.module.content.root.chooser.title"),
        ProjectBundle.message("project.new.wizard.module.content.root.chooser.description"),
        myWizardContext.getProject(),
        BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR);

    myNamePathComponent
        .getPathComponent()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (!myContentRootChangedByUser) {
                  setModuleContentRoot(myNamePathComponent.getPath());
                }
              }
            });
    myModuleName
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (myModuleNameDocListenerEnabled) {
                  myModuleNameChangedByUser = true;
                }
                String path = getDefaultBaseDir(myWizardContext);
                final String moduleName = getModuleName();
                if (path.length() > 0
                    && !Comparing.strEqual(moduleName, myNamePathComponent.getNameValue())) {
                  path += "/" + moduleName;
                }
                if (!myContentRootChangedByUser) {
                  final boolean f = myModuleNameChangedByUser;
                  myModuleNameChangedByUser = true;
                  setModuleContentRoot(path);
                  myModuleNameChangedByUser = f;
                }
                if (!myImlLocationChangedByUser) {
                  setImlFileLocation(path);
                }
              }
            });
    myModuleContentRoot
        .getTextField()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (myContentRootDocListenerEnabled) {
                  myContentRootChangedByUser = true;
                }
                if (!myImlLocationChangedByUser) {
                  setImlFileLocation(getModuleContentRoot());
                }
                if (!myModuleNameChangedByUser) {
                  final String path = FileUtil.toSystemIndependentName(getModuleContentRoot());
                  final int idx = path.lastIndexOf("/");

                  boolean f = myContentRootChangedByUser;
                  myContentRootChangedByUser = true;

                  boolean i = myImlLocationChangedByUser;
                  myImlLocationChangedByUser = true;

                  setModuleName(idx >= 0 ? path.substring(idx + 1) : "");

                  myContentRootChangedByUser = f;
                  myImlLocationChangedByUser = i;
                }
              }
            });

    myModuleFileLocation.addBrowseFolderListener(
        ProjectBundle.message("project.new.wizard.module.file.chooser.title"),
        ProjectBundle.message("project.new.wizard.module.file.description"),
        myWizardContext.getProject(),
        BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR);
    myModuleFileLocation
        .getTextField()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (myImlLocationDocListenerEnabled) {
                  myImlLocationChangedByUser = true;
                }
              }
            });
    myNamePathComponent
        .getPathComponent()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (!myImlLocationChangedByUser) {
                  setImlFileLocation(myNamePathComponent.getPath());
                }
              }
            });
    if (myWizardContext.isCreatingNewProject()) {
      setModuleName(myNamePathComponent.getNameValue());
      setModuleContentRoot(myNamePathComponent.getPath());
      setImlFileLocation(myNamePathComponent.getPath());
    } else {
      final Project project = myWizardContext.getProject();
      assert project != null;
      VirtualFile baseDir = project.getBaseDir();
      if (baseDir != null) { // e.g. was deleted
        final String baseDirPath = baseDir.getPath();
        String moduleName = ProjectWizardUtil.findNonExistingFileName(baseDirPath, "untitled", "");
        String contentRoot = baseDirPath + "/" + moduleName;
        if (!Comparing.strEqual(project.getName(), myWizardContext.getProjectName())
            && !myWizardContext.isCreatingNewProject()
            && myWizardContext.getProjectName() != null) {
          moduleName =
              ProjectWizardUtil.findNonExistingFileName(
                  myWizardContext.getProjectFileDirectory(), myWizardContext.getProjectName(), "");
          contentRoot = myWizardContext.getProjectFileDirectory();
        }
        setModuleName(moduleName);
        setModuleContentRoot(contentRoot);
        setImlFileLocation(contentRoot);
        myModuleName.select(0, moduleName.length());
      }
    }
  }
コード例 #11
0
  public ProjectNameWithTypeStep(
      final WizardContext wizardContext, StepSequence sequence, final WizardMode mode) {
    super(wizardContext, mode);
    mySequence = sequence;
    myAdditionalContentPanel.add(
        myModulePanel,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1,
            1,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));
    myHeader.setVisible(myWizardContext.isCreatingNewProject() && !isCreateFromTemplateMode());
    myCreateModuleCb.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent e) {
            UIUtil.setEnabled(myInternalPanel, myCreateModuleCb.isSelected(), true);
            fireStateChanged();
          }
        });
    myCreateModuleCb.setSelected(true);
    if (!myWizardContext.isCreatingNewProject()) {
      myInternalPanel.setBorder(null);
    }
    myModuleDescriptionPane.setContentType(UIUtil.HTML_MIME);
    myModuleDescriptionPane.addHyperlinkListener(
        new HyperlinkListener() {
          public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
              try {
                BrowserUtil.launchBrowser(e.getURL().toString());
              } catch (IllegalThreadStateException ex) {
                // it's nnot a problem
              }
            }
          }
        });
    myModuleDescriptionPane.setEditable(false);

    final DefaultListModel defaultListModel = new DefaultListModel();
    for (ModuleBuilder builder : ModuleBuilder.getAllBuilders()) {
      defaultListModel.addElement(builder);
    }
    myTypesList.setModel(defaultListModel);
    myTypesList.setSelectionModel(new PermanentSingleSelectionModel());
    myTypesList.setCellRenderer(
        new DefaultListCellRenderer() {
          public Component getListCellRendererComponent(
              final JList list,
              final Object value,
              final int index,
              final boolean isSelected,
              final boolean cellHasFocus) {
            final Component rendererComponent =
                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            final ModuleBuilder builder = (ModuleBuilder) value;
            setIcon(builder.getBigIcon());
            setDisabledIcon(builder.getBigIcon());
            setText(builder.getPresentableName());
            return rendererComponent;
          }
        });
    myTypesList.addListSelectionListener(
        new ListSelectionListener() {
          @SuppressWarnings({"HardCodedStringLiteral"})
          public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
              return;
            }

            final ModuleBuilder typeSelected = (ModuleBuilder) myTypesList.getSelectedValue();

            final StringBuilder sb = new StringBuilder("<html><body><font face=\"Verdana\" ");
            sb.append(SystemInfo.isMac ? "" : "size=\"-1\"").append('>');
            sb.append(typeSelected.getDescription()).append("</font></body></html>");

            myModuleDescriptionPane.setText(sb.toString());

            boolean focusOwner = myTypesList.isFocusOwner();
            fireStateChanged();
            if (focusOwner) {
              SwingUtilities.invokeLater(
                  new Runnable() {
                    public void run() {
                      myTypesList.requestFocusInWindow();
                    }
                  });
            }
          }
        });
    myTypesList.setSelectedIndex(0);
    new DoubleClickListener() {
      @Override
      protected boolean onDoubleClick(MouseEvent e) {
        myWizardContext.requestNextStep();
        return true;
      }
    }.installOn(myTypesList);

    final Dimension preferredSize = calcTypeListPreferredSize(ModuleBuilder.getAllBuilders());
    final JBScrollPane pane = IJSwingUtilities.findParentOfType(myTypesList, JBScrollPane.class);
    pane.setPreferredSize(preferredSize);
    pane.setMinimumSize(preferredSize);

    myNamePathComponent
        .getNameComponent()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (!myModuleNameChangedByUser) {
                  setModuleName(myNamePathComponent.getNameValue());
                }
              }
            });

    myModuleContentRoot.addBrowseFolderListener(
        ProjectBundle.message("project.new.wizard.module.content.root.chooser.title"),
        ProjectBundle.message("project.new.wizard.module.content.root.chooser.description"),
        myWizardContext.getProject(),
        BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR);

    myNamePathComponent
        .getPathComponent()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (!myContentRootChangedByUser) {
                  setModuleContentRoot(myNamePathComponent.getPath());
                }
              }
            });
    myModuleName
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (myModuleNameDocListenerEnabled) {
                  myModuleNameChangedByUser = true;
                }
                String path = getDefaultBaseDir(wizardContext);
                final String moduleName = getModuleName();
                if (path.length() > 0
                    && !Comparing.strEqual(moduleName, myNamePathComponent.getNameValue())) {
                  path += "/" + moduleName;
                }
                if (!myContentRootChangedByUser) {
                  final boolean f = myModuleNameChangedByUser;
                  myModuleNameChangedByUser = true;
                  setModuleContentRoot(path);
                  myModuleNameChangedByUser = f;
                }
                if (!myImlLocationChangedByUser) {
                  setImlFileLocation(path);
                }
              }
            });
    myModuleContentRoot
        .getTextField()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (myContentRootDocListenerEnabled) {
                  myContentRootChangedByUser = true;
                }
                if (!myImlLocationChangedByUser) {
                  setImlFileLocation(myModuleContentRoot.getText());
                }
                if (!myModuleNameChangedByUser) {
                  final String path =
                      FileUtil.toSystemIndependentName(myModuleContentRoot.getText());
                  final int idx = path.lastIndexOf("/");

                  boolean f = myContentRootChangedByUser;
                  myContentRootChangedByUser = true;

                  boolean i = myImlLocationChangedByUser;
                  myImlLocationChangedByUser = true;

                  setModuleName(idx >= 0 ? path.substring(idx + 1) : "");

                  myContentRootChangedByUser = f;
                  myImlLocationChangedByUser = i;
                }
              }
            });

    myModuleFileLocation.addBrowseFolderListener(
        ProjectBundle.message("project.new.wizard.module.file.chooser.title"),
        ProjectBundle.message("project.new.wizard.module.file.description"),
        myWizardContext.getProject(),
        BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR);
    myModuleFileLocation
        .getTextField()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (myImlLocationDocListenerEnabled) {
                  myImlLocationChangedByUser = true;
                }
              }
            });
    myNamePathComponent
        .getPathComponent()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (!myImlLocationChangedByUser) {
                  setImlFileLocation(myNamePathComponent.getPath());
                }
              }
            });
    if (wizardContext.isCreatingNewProject()) {
      setModuleName(myNamePathComponent.getNameValue());
      setModuleContentRoot(myNamePathComponent.getPath());
      setImlFileLocation(myNamePathComponent.getPath());
    } else {
      final Project project = wizardContext.getProject();
      assert project != null;
      VirtualFile baseDir = project.getBaseDir();
      if (baseDir != null) { // e.g. was deleted
        final String baseDirPath = baseDir.getPath();
        String moduleName = ProjectWizardUtil.findNonExistingFileName(baseDirPath, "untitled", "");
        String contentRoot = baseDirPath + "/" + moduleName;
        if (!Comparing.strEqual(project.getName(), wizardContext.getProjectName())
            && !wizardContext.isCreatingNewProject()
            && wizardContext.getProjectName() != null) {
          moduleName =
              ProjectWizardUtil.findNonExistingFileName(
                  wizardContext.getProjectFileDirectory(), wizardContext.getProjectName(), "");
          contentRoot = wizardContext.getProjectFileDirectory();
        }
        setModuleName(moduleName);
        setModuleContentRoot(contentRoot);
        setImlFileLocation(contentRoot);
        myModuleName.select(0, moduleName.length());
      }
    }

    if (isCreateFromTemplateMode()) {
      replaceModuleTypeOptions(new JPanel());
    } else {
      final AnAction arrow =
          new AnAction() {
            @Override
            public void actionPerformed(AnActionEvent e) {
              if (e.getInputEvent() instanceof KeyEvent) {
                final int code = ((KeyEvent) e.getInputEvent()).getKeyCode();
                if (!myCreateModuleCb.isSelected()) return;
                int i = myTypesList.getSelectedIndex();
                if (code == KeyEvent.VK_DOWN) {
                  if (++i == myTypesList.getModel().getSize()) return;
                } else if (code == KeyEvent.VK_UP) {
                  if (--i == -1) return;
                }
                myTypesList.setSelectedIndex(i);
              }
            }
          };
      CustomShortcutSet shortcutSet = new CustomShortcutSet(KeyEvent.VK_UP, KeyEvent.VK_DOWN);
      arrow.registerCustomShortcutSet(shortcutSet, myNamePathComponent.getNameComponent());
      arrow.registerCustomShortcutSet(shortcutSet, myModuleName);
    }
  }