@Nullable @Override protected ValidationInfo doValidate() { if (StringUtils.isBlank(myOutputFolderChooser.getText())) { return new ValidationInfo("Target path can't be blank", myOutputFolderChooser.getTextField()); } return null; }
private static TextFieldWithBrowseButton createBrowseField() { TextFieldWithBrowseButton textField = new TextFieldWithBrowseButton(); textField.setPreferredSize(new Dimension(200, textField.getPreferredSize().height)); textField.setMinimumSize(new Dimension(200, textField.getPreferredSize().height)); final FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false, false, false, false) { public boolean isFileSelectable(VirtualFile file) { //noinspection HardCodedStringLiteral return file.getName().endsWith(".png"); } }; textField.addBrowseFolderListener( IdeBundle.message("title.browse.icon"), IdeBundle.message("prompt.browse.icon.for.selected.action"), null, fileChooserDescriptor); InsertPathAction.addTo(textField.getTextField(), fileChooserDescriptor); return textField; }
public PathMacroEditor(String title, String macroName, String value, Validator validator) { super(true); setTitle(title); myValidator = validator; myNameField.setText(macroName); DocumentListener documentListener = new DocumentAdapter() { public void textChanged(DocumentEvent event) { updateControls(); } }; myNameField.getDocument().addDocumentListener(documentListener); myValueField.setText(value); myValueField.addBrowseFolderListener( null, null, null, new FileChooserDescriptor(false, true, true, false, true, false), new TextComponentAccessor<JTextField>() { public String getText(JTextField component) { return component.getText(); } public void setText(JTextField component, String text) { final int len = text.length(); if (len > 0 && text.charAt(len - 1) == File.separatorChar) { text = text.substring(0, len - 1); } component.setText(text); } }); myValueField.getTextField().getDocument().addDocumentListener(documentListener); init(); updateControls(); }
private void setUpChooseGenerateFilePath() { FileChooserDescriptor fileChooserDescriptor = FileChooserDescriptorFactory.getDirectoryChooserDescriptor( "directory where generated files will be stored"); fileChooserDescriptor.setRoots(ProjectRootManager.getInstance(project).getContentRoots()); generatedChooseFile.addBrowseFolderListener(null, null, project, fileChooserDescriptor); final JTextField textField = generatedChooseFile.getTextField(); textField .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { onChange(); } @Override public void removeUpdate(DocumentEvent e) { onChange(); } @Override public void changedUpdate(DocumentEvent e) { onChange(); } private void onChange() { File file = new File(generatedChooseFile.getText()); if (!file.isDirectory()) { textField.setForeground(Color.RED); } else { textField.setForeground(Color.BLACK); } } }); }
public ElementWithManifestPropertiesPanel(E element, final ArtifactEditorContext context) { myElement = element; myContext = context; ManifestFileUtil.setupMainClassField(context.getProject(), myMainClassField); myClasspathField.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { Messages.showTextAreaDialog( myClasspathField.getTextField(), "Edit Classpath", "classpath-attribute-editor"); } }); myClasspathField .getTextField() .getDocument() .addDocumentListener( new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { myContext.queueValidation(); } }); myUseExistingManifestButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { chooseManifest(); } }); myCreateManifestButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { createManifest(); } }); }
@Override public JComponent getPreferredFocusedComponent() { return myDestDirectoryField.getTextField(); }
protected JComponent createCenterPanel() { Group rootGroup = ActionsTreeUtil.createMainGroup( null, null, QuickListsManager.getInstance().getAllQuickLists()); DefaultMutableTreeNode root = ActionsTreeUtil.createNode(rootGroup); DefaultTreeModel model = new DefaultTreeModel(root); myTree = new Tree(); myTree.setModel(model); myTree.setCellRenderer(new MyTreeCellRenderer()); final ActionManager actionManager = ActionManager.getInstance(); mySetIconButton = new JButton(IdeBundle.message("button.set.icon")); mySetIconButton.setEnabled(false); mySetIconButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { final TreePath selectionPath = myTree.getSelectionPath(); if (selectionPath != null) { doSetIcon( (DefaultMutableTreeNode) selectionPath.getLastPathComponent(), myTextField.getText(), getContentPane()); myTree.repaint(); } } }); myTextField = createBrowseField(); myTextField .getTextField() .getDocument() .addDocumentListener( new DocumentAdapter() { protected void textChanged(DocumentEvent e) { enableSetIconButton(actionManager); } }); JPanel northPanel = new JPanel(new BorderLayout()); northPanel.add(myTextField, BorderLayout.CENTER); final JLabel label = new JLabel(IdeBundle.message("label.icon.path")); label.setLabelFor(myTextField.getChildComponent()); northPanel.add(label, BorderLayout.WEST); northPanel.add(mySetIconButton, BorderLayout.EAST); northPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0)); JPanel panel = new JPanel(new BorderLayout()); panel.add(northPanel, BorderLayout.NORTH); panel.add(ScrollPaneFactory.createScrollPane(myTree), BorderLayout.CENTER); myTree .getSelectionModel() .addTreeSelectionListener( new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { enableSetIconButton(actionManager); final TreePath selectionPath = myTree.getSelectionPath(); if (selectionPath != null) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath.getLastPathComponent(); final String actionId = getActionId(node); if (actionId != null) { final String iconPath = mySelectedSchema.getIconPath(actionId); myTextField.setText(FileUtil.toSystemDependentName(iconPath)); } } } }); return panel; }
@NotNull @Override protected JComponent createComponent(@NotNull CreationContext creationContext) { JPanel panel = new JPanel(new GridBagLayout()); { GridBagConstraints c = new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(UIUtil.DEFAULT_VGAP, 0, 0, UIUtil.DEFAULT_HGAP), 0, 0); myLabel.setDisplayedMnemonic('C'); myLabel.setHorizontalAlignment(SwingConstants.RIGHT); myLabel.setLabelFor(myConfigFileTextFieldWithBrowseButton.getTextField()); panel.add(myLabel, c); } { GridBagConstraints c = new GridBagConstraints( 1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(UIUtil.DEFAULT_VGAP, 0, 0, 0), 0, 0); final Project project = creationContext.getProject(); final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) { @Override public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) { boolean visible = super.isFileVisible(file, showHiddenFiles); if (visible && !file.isDirectory() && !showHiddenFiles) { visible = JstdConfigFileUtils.isJstdConfigFile(file); } return visible; } }; final JTextField configFileTextField = myConfigFileTextFieldWithBrowseButton.getTextField(); FileChooserFactory.getInstance() .installFileCompletion(configFileTextField, descriptor, false, null); myConfigFileTextFieldWithBrowseButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { PsiFile initialPsiFile = getConfigFile(project); TreeFileChooserDialog fileChooser = new TreeFileChooserDialog( project, "Select JsTestDriver configuration file", initialPsiFile, JstdConfigFileType.INSTANCE, new TreeFileChooser.PsiFileFilter() { @Override public boolean accept(PsiFile psiFile) { return true; } }, false, false); boolean jstdConfigFilesExists = JstdSettingsUtil.areJstdConfigFilesInProject(project); if (jstdConfigFilesExists) { fileChooser.selectSearchByNameTab(); } fileChooser.showDialog(); PsiFile psiFile = fileChooser.getSelectedFile(); if (psiFile != null) { VirtualFile vFile = psiFile.getVirtualFile(); if (vFile != null) { String path = FileUtil.toSystemDependentName(vFile.getPath()); configFileTextField.setText(path); } } } }); panel.add(myConfigFileTextFieldWithBrowseButton, c); } SwingUtils.addGreedyBottomRow(panel); return panel; }
public static void initDartSdkAndDartiumControls( final @Nullable Project project, final @NotNull TextFieldWithBrowseButton dartSdkPathComponent, final @NotNull JBLabel versionLabel, final @NotNull TextFieldWithBrowseButton dartiumPathComponent, final @NotNull Computable<Boolean> isResettingControlsComputable) { final TextComponentAccessor<JTextField> textComponentAccessor = new TextComponentAccessor<JTextField>() { @Override public String getText(final JTextField component) { return component.getText(); } @Override public void setText(final JTextField component, @NotNull String text) { if (!text.isEmpty() && !isDartSdkHome(text)) { final String probablySdkPath = text + "/dart-sdk"; if (isDartSdkHome(probablySdkPath)) { component.setText(FileUtilRt.toSystemDependentName(probablySdkPath)); return; } } component.setText(FileUtilRt.toSystemDependentName(text)); } }; final ComponentWithBrowseButton.BrowseFolderActionListener<JTextField> browseFolderListener = new ComponentWithBrowseButton.BrowseFolderActionListener<JTextField>( "Select Dart SDK path", null, dartSdkPathComponent, project, FileChooserDescriptorFactory.createSingleFolderDescriptor(), textComponentAccessor); dartSdkPathComponent.addBrowseFolderListener(project, browseFolderListener); dartiumPathComponent.addBrowseFolderListener( "Select Dartium browser path", null, project, FileChooserDescriptorFactory.createSingleFileOrExecutableAppDescriptor()); dartSdkPathComponent .getTextField() .getDocument() .addDocumentListener( new DocumentAdapter() { @Override protected void textChanged(final DocumentEvent e) { final String sdkHomePath = dartSdkPathComponent.getText().trim(); versionLabel.setText(sdkHomePath.isEmpty() ? "" : getSdkVersion(sdkHomePath)); if (!isResettingControlsComputable.compute() && isDartSdkHome(sdkHomePath)) { final String dartiumPath = DartiumUtil.getDartiumPathForSdk(sdkHomePath); if (dartiumPath != null) { dartiumPathComponent.setText(FileUtilRt.toSystemDependentName(dartiumPath)); } } } }); }
public JComponent createComponent() { final JPanel panel = new JPanel(new GridBagLayout()); myClassNameField = new TextFieldWithBrowseButton( new ActionListener() { public void actionPerformed(ActionEvent e) { PsiClass psiClass = DebuggerUtils.getInstance() .chooseClassDialog( DebuggerBundle.message( "title.compound.renderer.configurable.choose.renderer.reference.type"), myProject); if (psiClass != null) { myClassNameField.setText(JVMNameUtil.getNonAnonymousClassName(psiClass)); } } }); myClassNameField .getTextField() .addFocusListener( new FocusAdapter() { public void focusLost(FocusEvent e) { final String qName = myClassNameField.getText(); updateContext(qName); } }); myRbDefaultLabel = new JRadioButton( DebuggerBundle.message("label.compound.renderer.configurable.use.default.renderer")); myRbExpressionLabel = new JRadioButton( DebuggerBundle.message("label.compound.renderer.configurable.use.expression")); final ButtonGroup labelButtonsGroup = new ButtonGroup(); labelButtonsGroup.add(myRbDefaultLabel); labelButtonsGroup.add(myRbExpressionLabel); myRbDefaultChildrenRenderer = new JRadioButton( DebuggerBundle.message("label.compound.renderer.configurable.use.default.renderer")); myRbExpressionChildrenRenderer = new JRadioButton( DebuggerBundle.message("label.compound.renderer.configurable.use.expression")); myRbListChildrenRenderer = new JRadioButton( DebuggerBundle.message("label.compound.renderer.configurable.use.expression.list")); final ButtonGroup childrenButtonGroup = new ButtonGroup(); childrenButtonGroup.add(myRbDefaultChildrenRenderer); childrenButtonGroup.add(myRbExpressionChildrenRenderer); childrenButtonGroup.add(myRbListChildrenRenderer); myLabelEditor = new DebuggerExpressionTextField(myProject, null, "ClassLabelExpression"); myChildrenEditor = new DebuggerExpressionTextField(myProject, null, "ClassChildrenExpression"); myChildrenExpandedEditor = new DebuggerExpressionTextField(myProject, null, "ClassChildrenExpression"); myChildrenListEditor = createChildrenListEditor(); final ItemListener updateListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { updateEnabledState(); } }; myRbExpressionLabel.addItemListener(updateListener); myRbListChildrenRenderer.addItemListener(updateListener); myRbExpressionChildrenRenderer.addItemListener(updateListener); panel.add( new JLabel(DebuggerBundle.message("label.compound.renderer.configurable.apply.to")), new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); panel.add( myClassNameField, new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(4, 0, 0, 0), 0, 0)); panel.add( new JLabel(DebuggerBundle.message("label.compound.renderer.configurable.when.rendering")), new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(20, 0, 0, 0), 0, 0)); panel.add( myRbDefaultLabel, new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 10, 0, 0), 0, 0)); panel.add( myRbExpressionLabel, new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 10, 0, 0), 0, 0)); panel.add( myLabelEditor, new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 30, 0, 0), 0, 0)); panel.add( new JLabel(DebuggerBundle.message("label.compound.renderer.configurable.when.expanding")), new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(20, 0, 0, 0), 0, 0)); panel.add( myRbDefaultChildrenRenderer, new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 10, 0, 0), 0, 0)); panel.add( myRbExpressionChildrenRenderer, new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 10, 0, 0), 0, 0)); panel.add( myChildrenEditor, new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 30, 0, 0), 0, 0)); myExpandedLabel = new JLabel(DebuggerBundle.message("label.compound.renderer.configurable.test.can.expand")); panel.add( myExpandedLabel, new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(4, 30, 0, 0), 0, 0)); panel.add( myChildrenExpandedEditor, new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 30, 0, 0), 0, 0)); panel.add( myRbListChildrenRenderer, new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 0), 0, 0)); panel.add( myChildrenListEditor, new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(4, 30, 0, 0), 0, 0)); myMainPanel = new JPanel(new CardLayout()); myMainPanel.add(new JPanel(), EMPTY_PANEL_ID); myMainPanel.add(panel, DATA_PANEL_ID); return myMainPanel; }
public LocationNameFieldsBinding( Project project, final TextFieldWithBrowseButton locationTextField, final JTextField nameTextField, String baseDir, final String browseFolderTitle) { myBaseDir = baseDir; File suggestedProjectDirectory = FileUtil.findSequentNonexistentFile(new File(baseDir), "untitled", ""); locationTextField.setText(suggestedProjectDirectory.toString()); nameTextField.setDocument(new NameFieldDocument(nameTextField, locationTextField)); mySuggestedProjectName = suggestedProjectDirectory.getName(); nameTextField.setText(mySuggestedProjectName); nameTextField.selectAll(); FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); ComponentWithBrowseButton.BrowseFolderActionListener<JTextField> listener = new ComponentWithBrowseButton.BrowseFolderActionListener<JTextField>( browseFolderTitle, "", locationTextField, project, descriptor, TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT) { protected void onFileChoosen(VirtualFile chosenFile) { myBaseDir = chosenFile.getPath(); if (isProjectNameChanged(nameTextField.getText()) && !nameTextField.getText().equals(chosenFile.getName())) { myExternalModify = true; locationTextField.setText( new File(chosenFile.getPath(), nameTextField.getText()).toString()); myExternalModify = false; } else { myExternalModify = true; locationTextField.setText(chosenFile.getPath()); nameTextField.setText(chosenFile.getName()); myExternalModify = false; } } }; locationTextField.addActionListener(listener); locationTextField .getTextField() .getDocument() .addDocumentListener( new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { if (myExternalModify) { return; } myModifyingLocation = true; String path = locationTextField.getText().trim(); if (path.endsWith(File.separator)) { path = path.substring(0, path.length() - File.separator.length()); } int ind = path.lastIndexOf(File.separator); if (ind != -1) { String projectName = path.substring(ind + 1, path.length()); if (!nameTextField.getText().trim().isEmpty()) { myBaseDir = path.substring(0, ind); } if (!projectName.equals(nameTextField.getText())) { if (!myModifyingProjectName) { nameTextField.setText(projectName); } } } myModifyingLocation = false; } }); }
protected JComponent createNorthPanel() { JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); panel.setBorder(IdeBorderFactory.createBorder()); myNameLabel = new JLabel(); panel.add( myNameLabel, new GridBagConstraints( 0, 0, 2, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 8, 4, 8), 0, 0)); panel.add( new JLabel(RefactoringBundle.message("move.files.to.directory.label")), new GridBagConstraints( 0, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 8, 4, 8), 0, 0)); myTargetDirectoryField = new TextFieldWithBrowseButton(); myTargetDirectoryField.addBrowseFolderListener( RefactoringBundle.message("select.target.directory"), RefactoringBundle.message("the.file.will.be.moved.to.this.directory"), null, FileChooserDescriptorFactory.createSingleFolderDescriptor()); myTargetDirectoryField.setTextFieldPreferredWidth(60); panel.add( myTargetDirectoryField, new GridBagConstraints( 1, 1, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 0, 4, 8), 0, 0)); myTargetDirectoryField .getTextField() .getDocument() .addDocumentListener( new DocumentAdapter() { public void textChanged(DocumentEvent event) { validateOKButton(); } }); return panel; }
public JComponent getPreferredFocusedComponent() { return myTargetDirectoryField.getTextField(); }
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); } }