@Override protected SettingsEditor<? extends RunConfiguration> createConfigurationEditor() { RestConfigurationEditor editor = new RestConfigurationEditor(getProject(), this, new SphinxTasksModel()); editor.setConfigurationName("Sphinx task"); editor.setOpenInBrowserVisible(false); editor.setInputDescriptor(FileChooserDescriptorFactory.createSingleFolderDescriptor()); editor.setOutputDescriptor(FileChooserDescriptorFactory.createSingleFolderDescriptor()); return editor; }
/** Init components */ private void initListeners() { FileChooserDescriptor fcd = FileChooserDescriptorFactory.createSingleFolderDescriptor(); fcd.setShowFileSystemRoots(true); fcd.setTitle(GitBundle.getString("clone.destination.directory.title")); fcd.setDescription(GitBundle.getString("clone.destination.directory.description")); fcd.setHideIgnored(false); myParentDirectory.addActionListener( new ComponentWithBrowseButton.BrowseFolderActionListener<JTextField>( fcd.getTitle(), fcd.getDescription(), myParentDirectory, myProject, fcd, TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT) { @Override protected VirtualFile getInitialFile() { // suggest project base directory only if nothing is typed in the component. String text = getComponentText(); if (text.length() == 0) { VirtualFile file = myProject.getBaseDir(); if (file != null) { return file; } } return super.getInitialFile(); } }); final DocumentListener updateOkButtonListener = new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { updateButtons(); } }; myParentDirectory.getChildComponent().getDocument().addDocumentListener(updateOkButtonListener); String parentDir = GitRememberedInputs.getInstance().getCloneParentDir(); if (StringUtil.isEmptyOrSpaces(parentDir)) { parentDir = ProjectUtil.getBaseDir(); } myParentDirectory.setText(parentDir); myDirectoryName.getDocument().addDocumentListener(updateOkButtonListener); myTestButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { test(); } }); setOKActionEnabled(false); myTestButton.setEnabled(false); }
@Nullable @Override protected JComponent createCenterPanel() { final JPanel content = new JPanel(new BorderLayout()); final JPanel topLine = new JPanel(new BorderLayout()); content.setBorder( IdeBorderFactory.createTitledBorder( "Thrift compiler " + myGenerator.getType().name(), false)); myOutputFolderChooser.addBrowseFolderListener( new TextBrowseFolderListener( FileChooserDescriptorFactory.createSingleFolderDescriptor(), myProject) { @Nullable @Override protected VirtualFile getInitialFile() { if (myGenerator.getOutputDir() != null) { return LocalFileFinder.findFile(myGenerator.getOutputDir()); } else { return null; } } @Override protected void onFileChosen(@NotNull VirtualFile chosenFile) { final String absolutePath = VfsUtil.virtualToIoFile(chosenFile).getAbsolutePath(); myOutputFolderChooser.setText(absolutePath); } }); topLine.add(new JBLabel("Output folder:"), BorderLayout.WEST); topLine.add(myOutputFolderChooser, BorderLayout.CENTER); content.add(topLine, BorderLayout.NORTH); final JPanel options = new JPanel(new BorderLayout()); content.add(options, BorderLayout.CENTER); myPane = AOptionPane.get(myGenerator.getType()); if (myPane != null) { options.setBorder(IdeBorderFactory.createTitledBorder("Additional options")); options.add(myPane.getPanel()); myPane.setValues(myGenerator); } else { options.setBorder(null); } final String url = myGenerator.getOutputDir(); final VirtualFile file = url == null ? null : VirtualFileManager.getInstance().findFileByUrl(url); myOutputFolderChooser.setText(file == null ? VfsUtil.urlToPath(url) : file.getPath()); return content; }
private void setupRootAndAnnotateExternally( @NotNull final OrderEntry entry, @NotNull final Project project, @NotNull final PsiModifierListOwner listOwner, @NotNull final String annotationFQName, @NotNull final PsiFile fromFile, @NotNull final String packageName, @Nullable final PsiNameValuePair[] value) { final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); descriptor.setTitle( ProjectBundle.message( "external.annotations.root.chooser.title", entry.getPresentableName())); descriptor.setDescription( ProjectBundle.message("external.annotations.root.chooser.description")); final VirtualFile newRoot = FileChooser.chooseFile(descriptor, project, null); if (newRoot == null) { notifyAfterAnnotationChanging(listOwner, annotationFQName, false); return; } new WriteCommandAction(project) { @Override protected void run(final Result result) throws Throwable { appendChosenAnnotationsRoot(entry, newRoot); XmlFile xmlFileInRoot = findXmlFileInRoot(findExternalAnnotationsXmlFiles(listOwner), newRoot); if (xmlFileInRoot != null) { // file already exists under appeared content root if (!CodeInsightUtilBase.preparePsiElementForWrite(xmlFileInRoot)) { notifyAfterAnnotationChanging(listOwner, annotationFQName, false); return; } annotateExternally(listOwner, annotationFQName, xmlFileInRoot, fromFile, value); } else { final XmlFile annotationsXml = createAnnotationsXml(newRoot, packageName); if (annotationsXml != null) { final List<PsiFile> createdFiles = new ArrayList<PsiFile>(); createdFiles.add(annotationsXml); String fqn = getFQN(packageName, fromFile); if (fqn != null) { myExternalAnnotations.put(fqn, createdFiles); } } annotateExternally(listOwner, annotationFQName, annotationsXml, fromFile, value); } } }.execute(); }
private AskForWorkDir(Project project) { super(project); setTitle("Set Sphinx Working Directory: "); init(); VirtualFile baseDir = project.getBaseDir(); String path = baseDir != null ? baseDir.getPath() : ""; myInputFile.setText(path); myInputFile.setEditable(false); myInputFile.addBrowseFolderListener( "Choose sphinx working directory (containing makefile): ", null, project, FileChooserDescriptorFactory.createSingleFolderDescriptor()); myPanel.setPreferredSize(new Dimension(600, 20)); }
@NotNull private JPanel createSelectDirectoryPanel( @NotNull Project project, @NotNull JTextField directoryTextField) { FileChooserDescriptor fileChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); String adapterName = getAssertFrameworkAdapterName(); String title = "Select a directory for " + adapterName + " files"; String description = adapterName + " source files will be copied to the selected directory"; TextFieldWithBrowseButton directoryTextFieldWithBrowseButton = new TextFieldWithBrowseButton(directoryTextField); directoryTextFieldWithBrowseButton.addBrowseFolderListener( title, description, project, fileChooserDescriptor); Dimension oldDimension = directoryTextFieldWithBrowseButton.getPreferredSize(); directoryTextFieldWithBrowseButton.setMaximumSize(oldDimension); JPanel panel = new JPanel(new BorderLayout(0, 2)); panel.add(new JLabel("Copy these files to directory:"), BorderLayout.NORTH); panel.add(directoryTextFieldWithBrowseButton, BorderLayout.CENTER); return SwingHelper.wrapWithHorizontalStretch(panel); }
public static FileChooserDescriptor createDescriptorForManifestDirectory() { FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); descriptor.setTitle("Select Directory for META-INF/MANIFEST.MF file"); return descriptor; }
@NotNull protected PsiElement[] invokeDialog(final Project project, final PsiDirectory directory) { final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); descriptor.setRoots(project.getBaseDir()); PsiDirectory currentDir = currentFile.getContainingDirectory(); PsiDirectory includeDir = currentDir.findSubdirectory("Includes"); VirtualFile selectDir = directory.getVirtualFile(); if (includeDir == null) { PsiDirectory parentDir = currentDir.getParentDirectory(); if (parentDir != null) { includeDir = parentDir.findSubdirectory("Includes"); } } if (includeDir != null) selectDir = includeDir.getVirtualFile(); final VirtualFile myFolder = FileChooser.chooseFile(descriptor, project, selectDir); if (myFolder != null) { PsiDirectory myDirectory = PsiManager.getInstance(project).findDirectory(myFolder); final MyInputValidator validator = new MyInputValidator(project, myDirectory); final String fileName = Messages.showInputDialog( project, getDialogPrompt(), getDialogTitle(), Messages.getQuestionIcon(), "", validator); final PsiElement[] elements = validator.getCreatedElements(); if (elements.length > 0) { ApplicationManager.getApplication() .invokeLater( new Runnable() { @Override public void run() { ApplicationManager.getApplication() .runWriteAction( new Runnable() { @Override public void run() { try { CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project); CaretModel caretModel = editor.getCaretModel(); int caretOffset = selectonModel.getSelectionStart(); EditorModificationUtil.deleteSelectedText(editor); PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project); caretModel.moveToOffset(caretOffset); EditorModificationUtil.insertStringAtCaret( editor, "<% include " + fileName + " %>", true, false); PsiFile createdFile = (PsiFile) elements[0]; codeStyleManager.reformat(createdFile); psiDocumentManager.commitDocument( psiDocumentManager.getDocument(currentFile)); FileEditorManager.getInstance(project) .openFile(currentFile.getVirtualFile(), true); codeStyleManager.adjustLineIndent(currentFile, caretOffset); psiDocumentManager.commitDocument( psiDocumentManager.getDocument(currentFile)); } catch (Exception e) { e.printStackTrace(); // To change body of catch statement use // File | Settings | File Templates. } } }); } }); } return elements; } return PsiElement.EMPTY_ARRAY; }
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)); } } } }); }
protected JComponent createNorthPanel() { JPanel panel = new JPanel(new GridBagLayout()); final GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.fill = GridBagConstraints.HORIZONTAL; c.insets = new Insets(0, 2, 0, 0); myNameLabel = new JLabel(); panel.add(myNameLabel, c); c.insets.top = 10; c.gridy++; panel.add(new JLabel(RefactoringBundle.message("move.files.to.directory.label")), c); c.insets.top = 0; myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton(); final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS); if (recentEntries != null) { myTargetDirectoryField.getChildComponent().setHistory(recentEntries); } final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); myTargetDirectoryField.addBrowseFolderListener( RefactoringBundle.message("select.target.directory"), RefactoringBundle.message("the.file.will.be.moved.to.this.directory"), myProject, descriptor, TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT); final JTextField textField = myTargetDirectoryField.getChildComponent().getTextEditor(); FileChooserFactory.getInstance() .installFileCompletion(textField, descriptor, true, getDisposable()); myTargetDirectoryField.setTextFieldPreferredWidth(60); c.insets.left = 0; c.gridy++; panel.add(myTargetDirectoryField, c); String shortcutText = KeymapUtil.getFirstKeyboardShortcutText( ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION)); final JLabel label = new JLabel(RefactoringBundle.message("path.completion.shortcut", shortcutText)); UIUtil.applyStyle(UIUtil.ComponentStyle.MINI, label); c.insets.left = 6; c.gridy++; panel.add(label, c); myCbSearchForReferences = new NonFocusableCheckBox(RefactoringBundle.message("search.for.references")); myCbSearchForReferences.setSelected( RefactoringSettings.getInstance().MOVE_SEARCH_FOR_REFERENCES_FOR_FILE); c.insets.top = 10; c.insets.left = 0; c.gridy++; panel.add(myCbSearchForReferences, c); textField .getDocument() .addDocumentListener( new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { validateOKButton(); } }); Disposer.register(getDisposable(), myTargetDirectoryField); return panel; }
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 NewLanguageSettings(String projectPath) { super(new GridLayoutManager(5, 1, new Insets(0, 5, 5, 5), -1, -1)); myProjectPath = projectPath; this.add(new JLabel("Language name:"), Util.getGridConstraints(0)); myLanguageName = new JTextField(); myLanguageName.setName("Name"); myLanguageName .getDocument() .addDocumentListener( new DocumentAdapter() { protected void textChanged(DocumentEvent p0) { if ((myProjectPath == null || myProjectPath.length() == 0)) { return; } String path = myProjectPath + File.separator + "languages" + File.separator; final String langName = getLanguageName(); if (!(langName.equals(getLanguageLocation()))) { path += langName; } if (!(myLangLocationChangedByUser)) { setLanguageLocation(path); } fireChanged(); } }); this.add(myLanguageName, Util.getGridConstraints(1)); myLanguageLocation = new JTextField(); myLanguageLocation.setName("Path"); myLanguageLocation .getDocument() .addDocumentListener( new DocumentAdapter() { protected void textChanged(DocumentEvent p0) { if (myLangLocationDocListenerEnabled) { myLangLocationChangedByUser = true; } } }); final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); InsertPathAction.addTo(myLanguageLocation, descriptor); BrowseFilesListener listener = new BrowseFilesListener( myLanguageLocation, "Choose Language Location Folder", "", descriptor); FieldPanel fieldPanel = new FieldPanel( myLanguageLocation, "Language location:", null, listener, EmptyRunnable.getInstance()); FileChooserFactory.getInstance() .installFileCompletion(fieldPanel.getTextField(), descriptor, false, null); this.add(fieldPanel, Util.getGridConstraints(2)); myRuntimeSolution = new JCheckBox("Create Runtime Solution"); this.add(myRuntimeSolution, Util.getGridConstraints(3)); mySandboxSolution = new JCheckBox("Create Sandbox Solution"); this.add(mySandboxSolution, Util.getGridConstraints(4)); this.setPreferredSize(new Dimension(400, 100)); reset(); }