@Nullable ProjectBuilder runModuleWizard(Component dialogParent, boolean anImport) { AbstractProjectWizard wizard; if (anImport) { wizard = ImportModuleAction.selectFileAndCreateWizard(myProject, dialogParent); if (wizard == null) return null; if (wizard.getStepCount() == 0) { ProjectBuilder builder = wizard.getProjectBuilder(); Disposer.dispose(wizard.getDisposable()); return builder; } } else { wizard = new NewProjectWizard(myProject, dialogParent, this); } if (wizard.showAndGet()) { final ProjectBuilder builder = wizard.getProjectBuilder(); if (builder instanceof ModuleBuilder) { final ModuleBuilder moduleBuilder = (ModuleBuilder) builder; if (moduleBuilder.getName() == null) { moduleBuilder.setName(wizard.getProjectName()); } if (moduleBuilder.getModuleFilePath() == null) { moduleBuilder.setModuleFilePath(wizard.getModuleFilePath()); } } if (!builder.validate(myProject, myProject)) { return null; } return wizard.getProjectBuilder(); } return null; }
private void updateSelection() { ProjectTemplate template = getSelectedTemplate(); if (template != null) { myContext.setProjectTemplate(template); } ModuleBuilder builder = getSelectedBuilder(); myContext.setProjectBuilder(builder); if (builder != null) { myWizard.getSequence().setType(builder.getBuilderId()); } }
private boolean showCustomOptions(@NotNull ModuleBuilder builder) { String card = builder.getBuilderId(); if (!myCustomSteps.containsKey(card)) { ModuleWizardStep step = builder.getCustomOptionsStep(myContext, this); if (step == null) return false; step.updateStep(); myCustomSteps.put(card, step); myOptionsPanel.add(step.getComponent(), card); } showCard(card); return true; }
private Dimension calcTypeListPreferredSize(final List<ModuleBuilder> allModuleTypes) { int width = 0; int height = 0; final FontMetrics fontMetrics = myTypesList.getFontMetrics(myTypesList.getFont()); final int fontHeight = fontMetrics.getMaxAscent() + fontMetrics.getMaxDescent(); for (final ModuleBuilder type : allModuleTypes) { final Icon icon = type.getBigIcon(); final int iconHeight = icon != null ? icon.getIconHeight() : 0; final int iconWidth = icon != null ? icon.getIconWidth() : 0; height += Math.max(iconHeight, fontHeight) + 6; width = Math.max(width, iconWidth + fontMetrics.stringWidth(type.getPresentableName()) + 10); } return new Dimension(width, height); }
public void updateDataModel() { if (!isCreateFromTemplateMode()) { mySequence.setType(myCreateModuleCb.isSelected() ? getSelectedBuilderId() : null); } super.updateDataModel(); if (!isCreateFromTemplateMode() && myCreateModuleCb.isSelected()) { final ModuleBuilder builder = (ModuleBuilder) myMode.getModuleBuilder(); assert builder != null; final String moduleName = getModuleName(); builder.setName(moduleName); builder.setModuleFilePath( FileUtil.toSystemIndependentName(myModuleFileLocation.getText()) + "/" + moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION); builder.setContentEntryPath(FileUtil.toSystemIndependentName(myModuleContentRoot.getText())); } }
// new TemplatesGroup selected public void projectTypeChanged() { TemplatesGroup group = getSelectedGroup(); if (group == null || group == myLastSelectedGroup) return; myLastSelectedGroup = group; PropertiesComponent.getInstance().setValue(PROJECT_WIZARD_GROUP, group.getId()); ModuleBuilder groupModuleBuilder = group.getModuleBuilder(); mySettingsStep = null; myHeaderPanel.removeAll(); if (groupModuleBuilder != null && groupModuleBuilder.getModuleType() != null) { mySettingsStep = groupModuleBuilder.modifyProjectTypeStep(this); } if (groupModuleBuilder == null || groupModuleBuilder.isTemplateBased()) { showTemplates(group); } else if (!showCustomOptions(groupModuleBuilder)) { List<FrameworkSupportInModuleProvider> providers = FrameworkSupportUtil.getProviders(groupModuleBuilder); final ProjectCategory category = group.getProjectCategory(); if (category != null) { List<FrameworkSupportInModuleProvider> filtered = ContainerUtil.filter( providers, new Condition<FrameworkSupportInModuleProvider>() { @Override public boolean value(FrameworkSupportInModuleProvider provider) { return matchFramework(category, provider); } }); // add associated Map<String, FrameworkSupportInModuleProvider> map = ContainerUtil.newMapFromValues(providers.iterator(), PROVIDER_STRING_CONVERTOR); Set<FrameworkSupportInModuleProvider> set = new HashSet<FrameworkSupportInModuleProvider>(filtered); for (FrameworkSupportInModuleProvider provider : filtered) { for (FrameworkSupportInModuleProvider.FrameworkDependency depId : provider.getDependenciesFrameworkIds()) { FrameworkSupportInModuleProvider dependency = map.get(depId.getFrameworkId()); set.add(dependency); } } myFrameworksPanel.setProviders( new ArrayList<FrameworkSupportInModuleProvider>(set), new HashSet<String>(Arrays.asList(category.getAssociatedFrameworkIds())), new HashSet<String>(Arrays.asList(category.getPreselectedFrameworkIds()))); } else { myFrameworksPanel.setProviders(providers); } getSelectedBuilder().addModuleConfigurationUpdater(myConfigurationUpdater); showCard(FRAMEWORKS_CARD); } myHeaderPanel.setVisible(myHeaderPanel.getComponentCount() > 0); // align header labels List<JLabel> labels = UIUtil.findComponentsOfType(myHeaderPanel, JLabel.class); int width = 0; for (JLabel label : labels) { int width1 = label.getPreferredSize().width; width = Math.max(width, width1); } for (JLabel label : labels) { label.setPreferredSize(new Dimension(width, label.getPreferredSize().height)); } myHeaderPanel.revalidate(); myHeaderPanel.repaint(); updateSelection(); }
private static ModuleType getModuleType(TemplatesGroup group) { ModuleBuilder moduleBuilder = group.getModuleBuilder(); return moduleBuilder == null ? null : moduleBuilder.getModuleType(); }
private List<TemplatesGroup> fillTemplatesMap(WizardContext context) { List<ModuleBuilder> builders = ModuleBuilder.getAllBuilders(); if (context.isCreatingNewProject()) { builders.add(new EmptyModuleBuilder()); } Map<String, TemplatesGroup> groupMap = new HashMap<String, TemplatesGroup>(); for (ModuleBuilder builder : builders) { BuilderBasedTemplate template = new BuilderBasedTemplate(builder); if (builder.isTemplate()) { TemplatesGroup group = groupMap.get(builder.getGroupName()); if (group == null) { group = new TemplatesGroup(builder); } myTemplatesMap.putValue(group, template); } else { TemplatesGroup group = new TemplatesGroup(builder); groupMap.put(group.getName(), group); myTemplatesMap.put(group, new ArrayList<ProjectTemplate>()); } } MultiMap<TemplatesGroup, ProjectTemplate> map = CreateFromTemplateMode.getTemplatesMap(context); myTemplatesMap.putAllValues(map); for (ProjectCategory category : ProjectCategory.EXTENSION_POINT_NAME.getExtensions()) { TemplatesGroup group = new TemplatesGroup(category); myTemplatesMap.remove(group); myTemplatesMap.put(group, new ArrayList<ProjectTemplate>()); } if (context.isCreatingNewProject()) { MultiMap<String, ProjectTemplate> localTemplates = loadLocalTemplates(); for (TemplatesGroup group : myTemplatesMap.keySet()) { myTemplatesMap.putValues(group, localTemplates.get(group.getId())); } } // remove Static Web group in IDEA Community if no specific templates found (IDEA-120593) if (PlatformUtils.isIdeaCommunity()) { for (TemplatesGroup group : myTemplatesMap.keySet()) { if (WebModuleTypeBase.WEB_MODULE.equals(group.getId()) && myTemplatesMap.get(group).isEmpty()) { myTemplatesMap.remove(group); break; } } } List<TemplatesGroup> groups = new ArrayList<TemplatesGroup>(myTemplatesMap.keySet()); // sorting by module type popularity final MultiMap<ModuleType, TemplatesGroup> moduleTypes = new MultiMap<ModuleType, TemplatesGroup>(); for (TemplatesGroup group : groups) { ModuleType type = getModuleType(group); moduleTypes.putValue(type, group); } Collections.sort( groups, new Comparator<TemplatesGroup>() { @Override public int compare(TemplatesGroup o1, TemplatesGroup o2) { int i = o2.getWeight() - o1.getWeight(); if (i != 0) return i; int i1 = moduleTypes.get(getModuleType(o2)).size() - moduleTypes.get(getModuleType(o1)).size(); if (i1 != 0) return i1; return o1.compareTo(o2); } }); Set<String> groupNames = ContainerUtil.map2Set( groups, new Function<TemplatesGroup, String>() { @Override public String fun(TemplatesGroup group) { return group.getParentGroup(); } }); // move subgroups MultiMap<String, TemplatesGroup> subGroups = new MultiMap<String, TemplatesGroup>(); for (ListIterator<TemplatesGroup> iterator = groups.listIterator(); iterator.hasNext(); ) { TemplatesGroup group = iterator.next(); String parentGroup = group.getParentGroup(); if (parentGroup != null && groupNames.contains(parentGroup) && !group.getName().equals(parentGroup) && groupMap.containsKey(parentGroup)) { subGroups.putValue(parentGroup, group); iterator.remove(); } } for (ListIterator<TemplatesGroup> iterator = groups.listIterator(); iterator.hasNext(); ) { TemplatesGroup group = iterator.next(); for (TemplatesGroup subGroup : subGroups.get(group.getName())) { iterator.add(subGroup); } } return groups; }
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); } }