com.intellij.openapi.fileChooser.FileChooserDescriptorFactory Java Examples
The following examples show how to use
com.intellij.openapi.fileChooser.FileChooserDescriptorFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestForm.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
TestForm(@NotNull Project project) { scope.setModel(new DefaultComboBoxModel<>(new Scope[]{DIRECTORY, FILE, NAME})); scope.addActionListener((ActionEvent e) -> { final Scope next = getScope(); updateFields(next); render(next); }); scope.setRenderer(new ListCellRendererWrapper<Scope>() { @Override public void customize(final JList list, final Scope value, final int index, final boolean selected, final boolean hasFocus) { setText(value.getDisplayName()); } }); initDartFileTextWithBrowse(project, testFile); testDir.addBrowseFolderListener("Test Directory", null, project, FileChooserDescriptorFactory.createSingleFolderDescriptor()); }
Example #2
Source File: ImportFlutterModuleStep.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
public ImportFlutterModuleStep(FlutterProjectModel model, String title, Icon icon, FlutterProjectType type) { super(model, title, icon); myValidatorPanel = new ValidatorPanel(this, myPanel); String initialLocation = WizardUtils.getProjectLocationParent().getPath(); // Directionality matters. Let the bindings set the model's value from the text field. myFlutterModuleLocationField.getChildComponent().setText(initialLocation); TextProperty locationText = new TextProperty(myFlutterModuleLocationField.getChildComponent()); myBindings.bind(model.projectLocation(), locationText); myFlutterModuleLocationField .addBrowseFolderListener(FlutterBundle.message("flutter.module.import.settings.location.select"), null, null, FileChooserDescriptorFactory.createSingleFolderDescriptor(), TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT); myValidatorPanel.registerValidator(model.projectLocation(), ImportFlutterModuleStep::validateFlutterModuleLocation); myRootPanel = new StudioWizardStepPanel(myValidatorPanel); FormScalingUtil.scaleComponentTree(this.getClass(), myRootPanel); }
Example #3
Source File: OpenSampleAction.java From mule-intellij-plugins with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(AnActionEvent anActionEvent) { logger.debug("Loading sample!"); final Project project = anActionEvent.getProject(); final PsiFile psiFile = anActionEvent.getData(CommonDataKeys.PSI_FILE); VirtualFile sample = FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(), project, null); if (sample == null) return; try { final String text = new String(sample.contentsToByteArray(), sample.getCharset()); new WriteCommandAction.Simple(project, psiFile) { @Override protected void run() throws Throwable { document.setText(text); } }.execute(); } catch (Exception e) { logger.error(e); } }
Example #4
Source File: ImportFlutterModuleStep.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
public ImportFlutterModuleStep(FlutterProjectModel model, String title, Icon icon, FlutterProjectType type) { super(model, title, icon); myValidatorPanel = new ValidatorPanel(this, myPanel); String initialLocation = WizardUtils.getProjectLocationParent().getPath(); // Directionality matters. Let the bindings set the model's value from the text field. myFlutterModuleLocationField.getChildComponent().setText(initialLocation); TextProperty locationText = new TextProperty(myFlutterModuleLocationField.getChildComponent()); myBindings.bind(model.projectLocation(), locationText); myFlutterModuleLocationField .addBrowseFolderListener(FlutterBundle.message("flutter.module.import.settings.location.select"), null, null, FileChooserDescriptorFactory.createSingleFolderDescriptor(), TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT); myValidatorPanel.registerValidator(model.projectLocation(), ImportFlutterModuleStep::validateFlutterModuleLocation); myRootPanel = new StudioWizardStepPanel(myValidatorPanel); FormScalingUtil.scaleComponentTree(this.getClass(), myRootPanel); }
Example #5
Source File: BuildElementsEditor.java From consulo with Apache License 2.0 | 6 votes |
private CommitableFieldPanel createOutputPathPanel(final String title, final CommitPathRunnable commitPathRunnable) { final JTextField textField = new JTextField(); final FileChooserDescriptor outputPathsChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); outputPathsChooserDescriptor.setHideIgnored(false); InsertPathAction.addTo(textField, outputPathsChooserDescriptor); FileChooserFactory.getInstance().installFileCompletion(textField, outputPathsChooserDescriptor, true, null); CommitableFieldPanel commitableFieldPanel = new CommitableFieldPanel(textField, null, null, new BrowseFilesListener(textField, title, "", outputPathsChooserDescriptor), null); commitableFieldPanel.myCommitRunnable = new Runnable() { @Override public void run() { if (!getModel().isWritable()) { return; } String url = commitableFieldPanel.getUrl(); commitPathRunnable.saveUrl(url); } }; return commitableFieldPanel; }
Example #6
Source File: TestForm.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
TestForm(@NotNull Project project) { scope.setModel(new DefaultComboBoxModel<>(new Scope[]{DIRECTORY, FILE, NAME})); scope.addActionListener((ActionEvent e) -> { final Scope next = getScope(); updateFields(next); render(next); }); scope.setRenderer(new ListCellRendererWrapper<Scope>() { @Override public void customize(final JList list, final Scope value, final int index, final boolean selected, final boolean hasFocus) { setText(value.getDisplayName()); } }); initDartFileTextWithBrowse(project, testFile); testDir.addBrowseFolderListener("Test Directory", null, project, FileChooserDescriptorFactory.createSingleFolderDescriptor()); }
Example #7
Source File: PsiUtil.java From CodeGen with MIT License | 6 votes |
public static PsiDirectory createDirectory(Project project, String title, String description) { final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); descriptor.setTitle(title); descriptor.setShowFileSystemRoots(false); descriptor.setDescription(description); descriptor.setHideIgnored(true); descriptor.setRoots(project.getBaseDir()); descriptor.setForcedToUseIdeaFileChooser(true); VirtualFile file = FileChooser.chooseFile(descriptor, project, project.getBaseDir()); if(Objects.isNull(file)){ Messages.showInfoMessage("Cancel " + title, "Error"); return null; } PsiDirectory psiDirectory = PsiDirectoryFactory.getInstance(project).createDirectory(file); if(PsiDirectoryFactory.getInstance(project).isPackage(psiDirectory)){ return psiDirectory; }else { Messages.showInfoMessage("请选择正确的 package 路径。", "Error"); return createDirectory(project, title, description); } }
Example #8
Source File: OclProjectJdkWizardStep.java From reasonml-idea-plugin with MIT License | 6 votes |
@Override public void _init() { for (String sdk : SDKS) { c_selDownload.addItem(sdk); } if (c_selExistingSdk.getItemCount() == 0) { c_rdSelectExisting.setEnabled(false); c_selExistingSdk.setEnabled(false); c_rdDownloadSdk.setSelected(true); } String value = PropertiesComponent.getInstance().getValue(SDK_HOME); if (value == null) { VirtualFile userHomeDir = VfsUtil.getUserHomeDir(); value = userHomeDir == null ? "" : userHomeDir.getCanonicalPath() + "/odk"; } c_sdkHome.setText(value); c_sdkHome.addBrowseFolderListener("Choose Sdk Home Directory: ", null, m_context.getProject(), FileChooserDescriptorFactory.createSingleFolderDescriptor()); }
Example #9
Source File: RootWindow.java From WIFIADB with Apache License 2.0 | 6 votes |
private void specifyADBPath() { final String adbPath = Global.instance().adbPath(); final VirtualFile toSelect; if (Utils.isBlank(adbPath)) { toSelect = null; } else { toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(adbPath); } final VirtualFile vFile = FileChooser.chooseFile( FileChooserDescriptorFactory.createSingleFileOrFolderDescriptor(), Global.instance().project(), toSelect); if (vFile == null || !vFile.exists()) { return; } mPresenter.chooseADBPath(vFile); }
Example #10
Source File: ExternalDiffSettingsConfigurable.java From consulo with Apache License 2.0 | 6 votes |
public ToolPath(JCheckBox checkBox, TextFieldWithBrowseButton textField, @javax.annotation.Nullable JTextField parameters, StringProperty pathProperty, BooleanProperty enabledProperty, @javax.annotation.Nullable StringProperty parametersProperty) { myCheckBox = checkBox; myTextField = textField; myPathProperty = pathProperty; myEnabledProperty = enabledProperty; myParameters = parameters; myParametersProperty = parametersProperty; final ButtonModel model = myCheckBox.getModel(); model.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateEnabledEffect(); } }); myTextField.addBrowseFolderListener(DiffBundle.message("select.external.diff.program.dialog.title"), null, null, FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(), TextComponentAccessor.TEXT_FIELD_SELECTED_TEXT); }
Example #11
Source File: ToolEditorDialog.java From consulo with Apache License 2.0 | 6 votes |
protected void addWorkingDirectoryBrowseAction(final JPanel pane, FixedSizeButton browseDirectoryButton, JTextField tfCommandWorkingDirectory) { browseDirectoryButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); PathChooserDialog chooser = FileChooserFactory.getInstance().createPathChooser(descriptor, myProject, pane); chooser.choose(null, new Consumer<List<VirtualFile>>() { @Override public void consume(List<VirtualFile> files) { VirtualFile file = files.size() > 0 ? files.get(0) : null; if (file != null) { myTfCommandWorkingDirectory.setText(file.getPresentableUrl()); } } }); } } ); }
Example #12
Source File: BuckSettingsUI.java From buck with Apache License 2.0 | 6 votes |
private void discoverCells() { final FileChooserDescriptor dirChooser = FileChooserDescriptorFactory.createSingleFolderDescriptor() .withTitle("Select any directory within a buck cell"); Project project = buckProjectSettingsProvider.getProject(); Optional.ofNullable( FileChooser.chooseFile(dirChooser, BuckSettingsUI.this, project, project.getBaseDir())) .ifPresent( defaultCell -> ProgressManager.getInstance() .run( new Modal(project, "Autodetecting buck cells", true) { @Override public void run(@NotNull ProgressIndicator progressIndicator) { discoverCells( buckExecutableForAutoDiscovery(), defaultCell, progressIndicator); } })); }
Example #13
Source File: VcsMappingConfigurationDialog.java From consulo with Apache License 2.0 | 6 votes |
public VcsMappingConfigurationDialog(final Project project, final String title) { super(project, false); myProject = project; myVcsManager = ProjectLevelVcsManager.getInstance(myProject); final VcsDescriptor[] vcsDescriptors = myVcsManager.getAllVcss(); myVcses = new HashMap<>(); for (VcsDescriptor vcsDescriptor : vcsDescriptors) { myVcses.put(vcsDescriptor.getName(), vcsDescriptor); } myVCSComboBox.setModel(VcsDirectoryConfigurationPanel.buildVcsWrappersModel(project)); myDirectoryTextField.addActionListener(new MyBrowseFolderListener("Select Directory", "Select directory to map to a VCS", myDirectoryTextField, project, FileChooserDescriptorFactory.createSingleFolderDescriptor())); myMappingCopy = new VcsDirectoryMapping("", ""); setTitle(title); init(); myVCSComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { updateVcsConfigurable(); } }); }
Example #14
Source File: RunAnythingChooseContextAction.java From consulo with Apache License 2.0 | 6 votes |
@RequiredUIAccess @Override public void actionPerformed(@Nonnull AnActionEvent e) { Application.get().invokeLater(() -> { Project project = e.getProject(); FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); descriptor.setUseApplicationDialog(); PathChooserDialog chooser = FileChooserFactory.getInstance().createPathChooser(descriptor, project, e.getDataContext().getData(PlatformDataKeys.CONTEXT_COMPONENT)); chooser.chooseAsync(project.getBaseDir()).doWhenDone(virtualFiles -> { List<String> recentDirectories = RunAnythingContextRecentDirectoryCache.getInstance(project).getState().paths; String path = ArrayUtil.getFirstElement(virtualFiles).getPath(); if (recentDirectories.size() >= Registry.intValue("run.anything.context.recent.directory.number")) { recentDirectories.remove(0); } recentDirectories.add(path); setSelectedContext(new RunAnythingContext.RecentDirectoryContext(path)); }); }); }
Example #15
Source File: ExportRunConfigurationDialog.java From intellij with Apache License 2.0 | 6 votes |
private void chooseDirectory() { FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor() .withTitle("Export Directory Location") .withDescription("Choose directory to export run configurations to") .withHideIgnored(false); FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null); final VirtualFile[] files; File existingLocation = new File(getOutputDirectoryPath()); if (existingLocation.exists()) { VirtualFile toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(existingLocation.getPath()); files = chooser.choose(null, toSelect); } else { files = chooser.choose(null); } if (files.length == 0) { return; } VirtualFile file = files[0]; outputDirectoryPanel.setText(file.getPath()); }
Example #16
Source File: SettingsForm.java From idea-php-symfony2-plugin with MIT License | 6 votes |
public JComponent createComponent() { pathToTranslationRootTextField.addBrowseFolderListener(createBrowseFolderListener(pathToTranslationRootTextField.getTextField(), FileChooserDescriptorFactory.createSingleFolderDescriptor())); pathToTranslationRootTextFieldReset.addMouseListener(createResetPathButtonMouseListener(pathToTranslationRootTextField.getTextField(), Settings.DEFAULT_TRANSLATION_PATH)); directoryToApp.addBrowseFolderListener(createBrowseFolderListener(directoryToApp.getTextField(), FileChooserDescriptorFactory.createSingleFolderDescriptor())); directoryToAppReset.addMouseListener(createResetPathButtonMouseListener(directoryToApp.getTextField(), Settings.DEFAULT_APP_DIRECTORY)); directoryToWeb.addBrowseFolderListener(createBrowseFolderListener(directoryToWeb.getTextField(), FileChooserDescriptorFactory.createSingleFolderDescriptor())); directoryToWebReset.addMouseListener(createResetPathButtonMouseListener(directoryToWeb.getTextField(), Settings.DEFAULT_WEB_DIRECTORY)); enableSchedulerCheckBox.setEnabled(WebDeploymentUtil.isEnabled(project)); buttonReindex.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { IndexUtil.forceReindex(); super.mouseClicked(e); } }); return panel1; }
Example #17
Source File: UiSettingsUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Nullable public static String getPathDialog(@NotNull Project project, @NotNull FileType fileType, @Nullable String current) { VirtualFile projectDirectory = ProjectUtil.getProjectDir(project); VirtualFile selectedFileBefore = null; if(current != null) { selectedFileBefore = VfsUtil.findRelativeFile(current, projectDirectory); } VirtualFile selectedFile = FileChooser.chooseFile( FileChooserDescriptorFactory.createSingleFileDescriptor(fileType), project, selectedFileBefore ); if (null == selectedFile) { return null; } String path = VfsUtil.getRelativePath(selectedFile, projectDirectory, '/'); if (null == path) { path = selectedFile.getPath(); } return path; }
Example #18
Source File: SimpleCreatePropertyQuickFix.java From intellij-sdk-docs with Apache License 2.0 | 6 votes |
@Override public void invoke(@NotNull final Project project, final Editor editor, PsiFile file) throws IncorrectOperationException { ApplicationManager.getApplication().invokeLater(() -> { Collection<VirtualFile> virtualFiles = FileTypeIndex.getFiles(SimpleFileType.INSTANCE, GlobalSearchScope.allScope(project) ); if (virtualFiles.size() == 1) { createProperty(project, virtualFiles.iterator().next()); } else { final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor(SimpleFileType.INSTANCE); descriptor.setRoots(ProjectUtil.guessProjectDir(project)); final VirtualFile file1 = FileChooser.chooseFile(descriptor, project, null); if (file1 != null) { createProperty(project, file1); } } }); }
Example #19
Source File: ShopwareSettingsForm.java From idea-php-shopware-plugin with MIT License | 6 votes |
@Nullable @Override public JComponent createComponent() { defaultCliToolsPathButton.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { cliToolsPharPathTextField.getTextField().setText(ShopwareApplicationSettings.DEFAULT_CLI_URL); } }); cliToolsPharPathTextField.getButton().addMouseListener(createPathButtonMouseListener( cliToolsPharPathTextField.getTextField(), FileChooserDescriptorFactory.createSingleFileDescriptor("phar")) ); return panel; }
Example #20
Source File: ESLintSettingsPage.java From eslint-plugin with MIT License | 5 votes |
private void configESLintRcField() { TextFieldWithHistory textFieldWithHistory = configWithDefaults(eslintrcFile); SwingHelper.addHistoryOnExpansion(textFieldWithHistory, new NotNullProducer<List<String>>() { @NotNull public List<String> produce() { return ESLintFinder.searchForESLintRCFiles(getProjectPath()); } }); SwingHelper.installFileCompletionAndBrowseDialog(project, eslintrcFile, "Select ESLint Config", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor()); }
Example #21
Source File: SvnToolBoxConfigurable.java From SVNToolBox with Apache License 2.0 | 5 votes |
@Nullable @Override public JComponent createComponent() { initComponent(); SvnToolBoxAppState state = SvnToolBoxAppState.getInstance(); form.setRegularColorState(state.customRegularColor, state.getRegularDecorationColor()); form.setDarkColorState(state.customDarkColor, state.getDarkDecorationColor()); form.getCsvFile().addBrowseFolderListener("", "", ProjectManager.getInstance().getDefaultProject(), FileChooserDescriptorFactory.createSingleFileDescriptor("csv")); return form.getContent(); }
Example #22
Source File: ESLintSettingsPage.java From eslint-plugin with MIT License | 5 votes |
private void configESLintBinField() { configWithDefaults(eslintBinField2); SwingHelper.addHistoryOnExpansion(eslintBinField2.getChildComponent(), new NotNullProducer<List<String>>() { @NotNull public List<String> produce() { List<File> newFiles = ESLintFinder.searchForESLintBin(getProjectPath()); return FileUtils.toAbsolutePath(newFiles); } }); SwingHelper.installFileCompletionAndBrowseDialog(project, eslintBinField2, "Select ESLint.js Cli", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor()); }
Example #23
Source File: ChooseComponentsToExportDialog.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @RequiredUIAccess public static AsyncResult<String> chooseSettingsFile(String oldPath, Component parent, final String title, final String description) { FileChooserDescriptor chooserDescriptor = FileChooserDescriptorFactory.createSingleLocalFileDescriptor(); chooserDescriptor.setDescription(description); chooserDescriptor.setHideIgnored(false); chooserDescriptor.setTitle(title); VirtualFile initialDir; if (oldPath != null) { final File oldFile = new File(oldPath); initialDir = LocalFileSystem.getInstance().findFileByIoFile(oldFile); if (initialDir == null && oldFile.getParentFile() != null) { initialDir = LocalFileSystem.getInstance().findFileByIoFile(oldFile.getParentFile()); } } else { initialDir = null; } final AsyncResult<String> result = AsyncResult.undefined(); AsyncResult<VirtualFile[]> fileAsyncResult = FileChooser.chooseFiles(chooserDescriptor, null, parent, initialDir); fileAsyncResult.doWhenDone(files -> { VirtualFile file = files[0]; if (file.isDirectory()) { result.setDone(file.getPath() + '/' + new File(DEFAULT_PATH).getName()); } else { result.setDone(file.getPath()); } }); fileAsyncResult.doWhenRejected((Runnable)result::setRejected); return result; }
Example #24
Source File: ApplyPatchDifferentiatedDialog.java From consulo with Apache License 2.0 | 5 votes |
public void run() { final FileChooserDescriptor descriptor = myDirectorySelector ? FileChooserDescriptorFactory.createSingleFolderDescriptor() : FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(); descriptor.setTitle(String.format("Select %s Base", myDirectorySelector ? "Directory" : "File")); VirtualFile selectedFile = FileChooser.chooseFile(descriptor, myProject, null); if (selectedFile == null) { return; } final List<AbstractFilePatchInProgress.PatchChange> selectedChanges = myChangesTreeList.getSelectedChanges(); if (selectedChanges.size() >= 1) { for (AbstractFilePatchInProgress.PatchChange patchChange : selectedChanges) { final AbstractFilePatchInProgress patch = patchChange.getPatchInProgress(); if (myDirectorySelector) { patch.setNewBase(selectedFile); } else { final FilePatch filePatch = patch.getPatch(); //if file was renamed in the patch but applied on another or already renamed local one then we shouldn't apply this rename/move filePatch.setAfterName(selectedFile.getName()); filePatch.setBeforeName(selectedFile.getName()); patch.setNewBase(selectedFile.getParent()); } } updateTree(false); } }
Example #25
Source File: ESLintSettingsPage.java From eslint-plugin with MIT License | 5 votes |
private void configESLintRulesField() { TextFieldWithHistory textFieldWithHistory = rulesPathField.getChildComponent(); SwingHelper.addHistoryOnExpansion(textFieldWithHistory, new NotNullProducer<List<String>>() { @NotNull public List<String> produce() { return ESLintFinder.tryFindRulesAsString(getProjectPath()); } }); SwingHelper.installFileCompletionAndBrowseDialog(project, rulesPathField, "Select Built in Rules", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor()); }
Example #26
Source File: GuiUtil.java From intellij-haskforce with Apache License 2.0 | 5 votes |
public static void addFolderListener(final TextFieldWithBrowseButton textField, final String name, final Project project, final Condition<VirtualFile> fileFilter) { textField.addBrowseFolderListener("Select " + name + " path", "", project, FileChooserDescriptorFactory.createSingleLocalFileDescriptor().withFileFilter(fileFilter)); }
Example #27
Source File: ImageEditorActionDialog.java From idea-latex with MIT License | 5 votes |
public ImageEditorActionDialog(@NotNull Project project) { super(project); path.addBrowseFolderListener(LatexBundle.message("editor.image.dialog.browse"), null, project, FileChooserDescriptorFactory.createSingleFileDescriptor()); setTitle(LatexBundle.message("editor.image.dialog.title")); init(); }
Example #28
Source File: ProfilerSettingsDialog.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Nullable @Override public JComponent createComponent() { textLocalProfilerCsvPath.addBrowseFolderListener(createBrowseFolderListener(textLocalProfilerCsvPath.getTextField(), FileChooserDescriptorFactory.createSingleFolderDescriptor())); return mainPanel; }
Example #29
Source File: ProfilerSettingsDialog.java From idea-php-symfony2-plugin with MIT License | 5 votes |
private TextBrowseFolderListener createBrowseFolderListener(final JTextField textField, final FileChooserDescriptor fileChooserDescriptor) { return new TextBrowseFolderListener(fileChooserDescriptor) { @Override public void actionPerformed(ActionEvent e) { VirtualFile projectDirectory = ProjectUtil.getProjectDir(project); String text = textField.getText(); VirtualFile toSelect = VfsUtil.findRelativeFile(text, projectDirectory); if(toSelect == null) { toSelect = projectDirectory; } VirtualFile selectedFile = FileChooser.chooseFile( FileChooserDescriptorFactory.createSingleFileDescriptor("csv"), project, toSelect ); if (null == selectedFile) { return; } String path = VfsUtil.getRelativePath(selectedFile, projectDirectory, '/'); if (null == path) { path = selectedFile.getPath(); } textField.setText(path); } }; }
Example #30
Source File: GuiUtil.java From intellij-haskforce with Apache License 2.0 | 5 votes |
/** * Creates a label and path selector and adds them to the configuration * window. * * @param settings Panel to add components to. * @param tool Which tool to configure. * @return The TextFieldWithBrowseButton created. */ public static TextFieldWithBrowseButton createExecutableOption(JPanel settings, String tool, Object constraints) { // Create UI elements. TextFieldWithBrowseButton tf = new TextFieldWithBrowseButton(); tf.addBrowseFolderListener("Select " + tool + " path", "", null, FileChooserDescriptorFactory.createSingleLocalFileDescriptor()); // Add elements to Panel. JPanel subPanel = new JPanel(new GridBagLayout()); subPanel.add(new JLabel(tool + " executable path:")); subPanel.add(tf, ExternalSystemUiUtil.getFillLineConstraints(0)); settings.add(subPanel, constraints); return tf; }