public boolean validate() throws ConfigurationException { final String moduleName = getModuleName(); if (myCreateModuleCb.isSelected() || !myWizardContext.isCreatingNewProject()) { final String moduleFileDirectory = myModuleFileLocation.getText(); if (moduleFileDirectory.length() == 0) { throw new ConfigurationException("Enter module file location"); } if (moduleName.length() == 0) { throw new ConfigurationException("Enter a module name"); } if (!ProjectWizardUtil.createDirectoryIfNotExists( IdeBundle.message("directory.module.file"), moduleFileDirectory, myImlLocationChangedByUser)) { return false; } if (!ProjectWizardUtil.createDirectoryIfNotExists( IdeBundle.message("directory.module.content.root"), myModuleContentRoot.getText(), myContentRootChangedByUser)) { return false; } File moduleFile = new File(moduleFileDirectory, moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION); if (moduleFile.exists()) { int answer = Messages.showYesNoDialog( IdeBundle.message( "prompt.overwrite.project.file", moduleFile.getAbsolutePath(), IdeBundle.message("project.new.wizard.module.identification")), IdeBundle.message("title.file.already.exists"), Messages.getQuestionIcon()); if (answer != 0) { return false; } } } if (!myWizardContext.isCreatingNewProject()) { 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."); } } return !myWizardContext.isCreatingNewProject() || super.validate(); }
private static NamePathComponent initNamePathComponent(WizardContext context) { NamePathComponent component = new NamePathComponent( IdeBundle.message("label.project.name"), IdeBundle.message("label.project.files.location"), IdeBundle.message( "title.select.project.file.directory", IdeBundle.message("project.new.wizard.project.identification")), IdeBundle.message( "description.select.project.file.directory", StringUtil.capitalize( IdeBundle.message("project.new.wizard.project.identification"))), true, false); final String baseDir = context.getProjectFileDirectory(); final String projectName = context.getProjectName(); final String initialProjectName = projectName != null ? projectName : ProjectWizardUtil.findNonExistingFileName(baseDir, "untitled", ""); component.setPath( projectName == null ? (baseDir + File.separator + initialProjectName) : baseDir); component.setNameValue(initialProjectName); component.getNameComponent().select(0, initialProjectName.length()); return component; }
private boolean validateModulePaths() throws ConfigurationException { final String moduleName = getModuleName(); final String moduleFileDirectory = myModuleFileLocation.getText(); if (moduleFileDirectory.length() == 0) { throw new ConfigurationException("Enter module file location"); } if (moduleName.length() == 0) { throw new ConfigurationException("Enter a module name"); } if (!ProjectWizardUtil.createDirectoryIfNotExists( IdeBundle.message("directory.module.file"), moduleFileDirectory, myImlLocationChangedByUser)) { return false; } if (!ProjectWizardUtil.createDirectoryIfNotExists( IdeBundle.message("directory.module.content.root"), myModuleContentRoot.getText(), myContentRootChangedByUser)) { return false; } File moduleFile = new File(moduleFileDirectory, moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION); if (moduleFile.exists()) { int answer = Messages.showYesNoDialog( IdeBundle.message( "prompt.overwrite.project.file", moduleFile.getAbsolutePath(), IdeBundle.message("project.new.wizard.module.identification")), IdeBundle.message("title.file.already.exists"), Messages.getQuestionIcon()); if (answer != 0) { return false; } } return true; }
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()); } } }
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); } }