List of usage examples for com.intellij.openapi.fileChooser FileChooser chooseFiles
public static void chooseFiles(@NotNull final FileChooserDescriptor descriptor, @Nullable final Project project, @Nullable final VirtualFile toSelect, @NotNull final Consumer<? super List<VirtualFile>> callback)
From source file:com.android.tools.idea.npw.project.ConfigureAndroidProjectStep.java
License:Apache License
@Nullable private static String browseForFile(@NotNull String initialPath) { FileChooserDescriptor fileSaverDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); File currentPath = new File(initialPath); File parentPath = currentPath.getParentFile(); if (parentPath == null) { String homePath = System.getProperty("user.home"); parentPath = new File(homePath == null ? File.separator : homePath); }//from w w w.ja v a 2 s. co m VirtualFile parent = LocalFileSystem.getInstance().findFileByIoFile(parentPath); OptionalProperty<String> finalPath = new OptionalValueProperty<>(); FileChooser.chooseFiles(fileSaverDescriptor, null, parent, virtualFiles -> { if (virtualFiles.size() == 1) { String result = virtualFiles.iterator().next().getCanonicalPath(); if (result != null) { finalPath.setValue(result); } } }); return finalPath.getValueOrNull(); }
From source file:com.github.rholder.gradle.intellij.DependencyViewer.java
License:Apache License
private void promptForGradleBaseDir() { FileChooserDescriptor fcd = FileChooserDescriptorFactory.createSingleFolderDescriptor(); fcd.setShowFileSystemRoots(true);//from w ww . jav a2s . c o m fcd.setTitle("Choose a Gradle folder..."); fcd.setDescription( "Pick the top level directory to use when viewing dependencies (in case you have a multi-module project)"); fcd.setHideIgnored(false); FileChooser.chooseFiles(fcd, project, project.getBaseDir(), new Consumer<List<VirtualFile>>() { @Override public void consume(List<VirtualFile> files) { gradleBaseDir = files.get(0).getPath(); } }); }
From source file:com.hp.alm.ali.idea.ui.editor.field.UploadField.java
License:Apache License
public UploadField(String label, boolean required, boolean editable) { super(label, required, ""); textFieldWithBrowseButton = new TextFieldWithBrowseButton(); textFieldWithBrowseButton.getTextField().setEditable(false); textFieldWithBrowseButton.getTextField().getDocument().addDocumentListener(new MyDocumentListener(this)); if (editable) { textFieldWithBrowseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { VirtualFile[] file = FileChooser.chooseFiles( new FileChooserDescriptor(true, false, true, true, false, false), textFieldWithBrowseButton.getTextField(), null, lastDir); if (file.length > 0) { textFieldWithBrowseButton.getTextField().setText(file[0].getPath()); lastDir = file[0].getParent(); }/*from w w w . j a va 2 s .com*/ } }); } else { textFieldWithBrowseButton.setEnabled(false); } }
From source file:com.intellij.compiler.options.ProcessorProfilePanel.java
License:Apache License
public ProcessorProfilePanel(Project project) { super(new GridBagLayout()); myProject = project;//w ww .j a v a 2 s .c om myCbEnableProcessing = new JCheckBox("Enable annotation processing"); { myRbClasspath = new JRadioButton("Obtain processors from project classpath"); myRbProcessorsPath = new JRadioButton("Processor path:"); ButtonGroup group = new ButtonGroup(); group.add(myRbClasspath); group.add(myRbProcessorsPath); } { myRbRelativeToContentRoot = new JRadioButton("Module content root"); myRbRelativeToOutputRoot = new JRadioButton("Module output directory"); final ButtonGroup group = new ButtonGroup(); group.add(myRbRelativeToContentRoot); group.add(myRbRelativeToOutputRoot); } myProcessorPathField = new TextFieldWithBrowseButton(new ActionListener() { public void actionPerformed(ActionEvent e) { final FileChooserDescriptor descriptor = FileChooserDescriptorFactory .createAllButJarContentsDescriptor(); final VirtualFile[] files = FileChooser.chooseFiles(descriptor, myProcessorPathField, myProject, null); if (files.length > 0) { final StringBuilder builder = new StringBuilder(); for (VirtualFile file : files) { if (builder.length() > 0) { builder.append(File.pathSeparator); } builder.append(FileUtil.toSystemDependentName(file.getPath())); } myProcessorPathField.setText(builder.toString()); } } }); myProcessorTablePanel = new JPanel(new BorderLayout()); myProcessorsModel = new ProcessorTableModel(); myProcessorTablePanel.setBorder(IdeBorderFactory.createTitledBorder("Annotation Processors", false)); myProcessorTable = new JBTable(myProcessorsModel); myProcessorTable.getEmptyText().setText("Compiler will run all automatically discovered processors"); myProcessorPanel = createTablePanel(myProcessorTable); myProcessorTablePanel.add(myProcessorPanel, BorderLayout.CENTER); myOptionsTablePanel = new JPanel(new BorderLayout()); myOptionsModel = new OptionsTableModel(); myOptionsTablePanel.setBorder(IdeBorderFactory.createTitledBorder("Annotation Processor options", false)); myOptionsTable = new JBTable(myOptionsModel); myOptionsTable.getEmptyText().setText("No processor-specific options configured"); myOptionsPanel = createTablePanel(myOptionsTable); myOptionsTablePanel.add(myOptionsPanel, BorderLayout.CENTER); myGeneratedProductionDirField = new JTextField(); myGeneratedTestsDirField = new JTextField(); myWarninglabel = new JLabel("<html>WARNING!<br>" + /*"All source files located in the generated sources output directory WILL BE EXCLUDED from annotation processing. " +*/ "If option 'Clear output directory on rebuild' is enabled, " + "the entire contents of directories where generated sources are stored WILL BE CLEARED on rebuild.</html>"); myWarninglabel.setFont(myWarninglabel.getFont().deriveFont(Font.BOLD)); add(myCbEnableProcessing, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 3, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); add(myRbClasspath, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 3, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 0, 0, 0), 0, 0)); add(myRbProcessorsPath, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 0, 0), 0, 0)); add(myProcessorPathField, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 0), 0, 0)); myStoreGenSourcesLabel = new JLabel("Store generated sources relative to: "); add(myStoreGenSourcesLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(15, 5, 0, 0), 0, 0)); add(myRbRelativeToOutputRoot, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(15, 5, 0, 0), 0, 0)); add(myRbRelativeToContentRoot, new GridBagConstraints(2, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(15, 5, 0, 0), 0, 0)); myProductionLabel = new JLabel("Production sources directory:"); add(myProductionLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 0, 0), 0, 0)); add(myGeneratedProductionDirField, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 0, 0), 0, 0)); myTestLabel = new JLabel("Test sources directory:"); add(myTestLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 0, 0), 0, 0)); add(myGeneratedTestsDirField, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 0, 0), 0, 0)); add(myProcessorTablePanel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 3, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(10, 0, 0, 0), 0, 0)); add(myOptionsTablePanel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 3, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(10, 0, 0, 0), 0, 0)); add(myWarninglabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 3, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 0, 0), 0, 0)); myRbClasspath.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { updateEnabledState(); } }); myProcessorTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { updateEnabledState(); } } }); myCbEnableProcessing.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { updateEnabledState(); } }); updateEnabledState(); }
From source file:com.intellij.find.impl.FindDialog.java
License:Apache License
@NotNull private JComponent createGlobalScopePanel() { JPanel scopePanel = new JPanel(); scopePanel.setLayout(new GridBagLayout()); scopePanel.setBorder(IdeBorderFactory.createTitledBorder(FindBundle.message("find.scope.group"), true)); GridBagConstraints gbConstraints = new GridBagConstraints(); gbConstraints.fill = GridBagConstraints.HORIZONTAL; gbConstraints.anchor = GridBagConstraints.WEST; gbConstraints.gridx = 0;//w w w. j a v a 2 s . c o m gbConstraints.gridy = 0; gbConstraints.gridwidth = 3; gbConstraints.weightx = 1; myRbProject = new JRadioButton(FindBundle.message("find.scope.whole.project.radio"), true); scopePanel.add(myRbProject, gbConstraints); ChangeListener l = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { findSettingsChanged(); } }; myRbProject.addChangeListener(l); gbConstraints.gridx = 0; gbConstraints.gridy++; gbConstraints.weightx = 0; gbConstraints.gridwidth = 1; myRbModule = new JRadioButton(FindBundle.message("find.scope.module.radio"), false); scopePanel.add(myRbModule, gbConstraints); myRbModule.addChangeListener(l); gbConstraints.gridx = 1; gbConstraints.gridwidth = 2; gbConstraints.weightx = 1; Module[] modules = ModuleManager.getInstance(myProject).getModules(); String[] names = new String[modules.length]; for (int i = 0; i < modules.length; i++) { names[i] = modules[i].getName(); } Arrays.sort(names, String.CASE_INSENSITIVE_ORDER); myModuleComboBox = new ComboBox(names); myModuleComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { findSettingsChanged(); } }); scopePanel.add(myModuleComboBox, gbConstraints); if (modules.length == 1) { myModuleComboBox.setVisible(false); myRbModule.setVisible(false); } gbConstraints.gridx = 0; gbConstraints.gridy++; gbConstraints.weightx = 0; gbConstraints.gridwidth = 1; myRbDirectory = new JRadioButton(FindBundle.message("find.scope.directory.radio"), false); scopePanel.add(myRbDirectory, gbConstraints); myRbDirectory.addChangeListener(l); gbConstraints.gridx = 1; gbConstraints.weightx = 1; myDirectoryComboBox = new ComboBox(200); Component editorComponent = myDirectoryComboBox.getEditor().getEditorComponent(); if (editorComponent instanceof JTextField) { JTextField field = (JTextField) editorComponent; field.setColumns(40); } initCombobox(myDirectoryComboBox); myDirectoryComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { findSettingsChanged(); } }); scopePanel.add(myDirectoryComboBox, gbConstraints); gbConstraints.weightx = 0; gbConstraints.gridx = 2; mySelectDirectoryButton = new FixedSizeButton(myDirectoryComboBox); TextFieldWithBrowseButton.MyDoClickAction.addTo(mySelectDirectoryButton, myDirectoryComboBox); mySelectDirectoryButton.setMargin(new Insets(0, 0, 0, 0)); scopePanel.add(mySelectDirectoryButton, gbConstraints); gbConstraints.gridx = 0; gbConstraints.gridy++; gbConstraints.weightx = 1; gbConstraints.gridwidth = 3; gbConstraints.insets = new Insets(0, 16, 0, 0); myCbWithSubdirectories = createCheckbox(true, FindBundle.message("find.scope.directory.recursive.checkbox")); myCbWithSubdirectories.setSelected(true); scopePanel.add(myCbWithSubdirectories, gbConstraints); gbConstraints.gridx = 0; gbConstraints.gridy++; gbConstraints.weightx = 0; gbConstraints.gridwidth = 1; gbConstraints.insets = new Insets(0, 0, 0, 0); myRbCustomScope = new JRadioButton(FindBundle.message("find.scope.custom.radio"), false); scopePanel.add(myRbCustomScope, gbConstraints); gbConstraints.gridx++; gbConstraints.weightx = 1; gbConstraints.gridwidth = 2; myScopeCombo = new ScopeChooserCombo(myProject, true, true, FindSettings.getInstance().getDefaultScopeName()); myRbCustomScope.addChangeListener(l); Disposer.register(myDisposable, myScopeCombo); scopePanel.add(myScopeCombo, gbConstraints); ButtonGroup bgScope = new ButtonGroup(); bgScope.add(myRbDirectory); bgScope.add(myRbProject); bgScope.add(myRbModule); bgScope.add(myRbCustomScope); ActionListener validateAll = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { validateScopeControls(); validateFindButton(); } }; myRbProject.addActionListener(validateAll); myRbCustomScope.addActionListener(validateAll); myRbDirectory.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { validateScopeControls(); validateFindButton(); myDirectoryComboBox.getEditor().getEditorComponent().requestFocusInWindow(); } }); myRbModule.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { validateScopeControls(); validateFindButton(); myModuleComboBox.requestFocusInWindow(); } }); mySelectDirectoryButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); FileChooser.chooseFiles(descriptor, myProject, null, new Consumer<List<VirtualFile>>() { @Override public void consume(final List<VirtualFile> files) { myDirectoryComboBox.setSelectedItem(files.get(0).getPresentableUrl()); } }); } }); return scopePanel; }
From source file:com.intellij.ide.actions.OpenFileAction.java
License:Apache License
@Override public void actionPerformed(AnActionEvent e) { @Nullable/* w w w . j a va 2 s . c om*/ final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); final boolean showFiles = project != null; final FileChooserDescriptor descriptor = new OpenProjectFileChooserDescriptor(true) { @Override public boolean isFileSelectable(VirtualFile file) { if (super.isFileSelectable(file)) { return true; } if (file.isDirectory()) { return false; } return showFiles && !FileElement.isArchive(file); } @Override public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) { if (!file.isDirectory() && isFileSelectable(file)) { if (!showHiddenFiles && FileElement.isFileHidden(file)) return false; return true; } return super.isFileVisible(file, showHiddenFiles); } @Override public boolean isChooseMultiple() { return showFiles; } }; descriptor.setTitle(showFiles ? "Open File or Project" : "Open Project"); VirtualFile userHomeDir = null; if (SystemInfo.isUnix) { userHomeDir = VfsUtil.getUserHomeDir(); } descriptor.putUserData(PathChooserDialog.PREFER_LAST_OVER_EXPLICIT, Boolean.TRUE); FileChooser.chooseFiles(descriptor, project, userHomeDir, new Consumer<List<VirtualFile>>() { @Override public void consume(final List<VirtualFile> files) { for (VirtualFile file : files) { if (!descriptor.isFileSelectable(file)) { // on Mac, it could be selected anyway Messages.showInfoMessage(project, file.getPresentableUrl() + " contains no " + ApplicationNamesInfo.getInstance().getFullProductName() + " project", "Cannot Open Project"); return; } } doOpenFile(project, files); } }); }
From source file:com.intellij.ide.actions.OpenProjectAction.java
License:Apache License
@Override public void actionPerformed(AnActionEvent e) { final FileChooserDescriptor descriptor = new OpenProjectFileChooserDescriptor(true); descriptor.setTitle(IdeBundle.message("title.open.project")); final Set<String> extensions = new LinkedHashSet<String>(); for (ProjectOpenProcessor openProcessor : ProjectOpenProcessor.EXTENSION_POINT_NAME.getExtensions()) { if (openProcessor instanceof ProjectOpenProcessorBase) { final String[] supportedExtensions = ((ProjectOpenProcessorBase) openProcessor) .getSupportedExtensions(); if (supportedExtensions != null) { Collections.addAll(extensions, supportedExtensions); }/* w w w . j av a2 s. c o m*/ } } if (extensions.isEmpty()) { descriptor.setDescription(IdeBundle.message("filter.project.directories")); } else { descriptor.setDescription(IdeBundle.message("filter.project.files", StringUtil.join(extensions, ", "))); } VirtualFile userHomeDir = null; if (SystemInfo.isUnix) { userHomeDir = VfsUtil.getUserHomeDir(); } descriptor.putUserData(PathChooserDialog.PREFER_LAST_OVER_EXPLICIT, Boolean.TRUE); final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); FileChooser.chooseFiles(descriptor, project, userHomeDir, new Consumer<List<VirtualFile>>() { @Override public void consume(final List<VirtualFile> files) { if (files.size() == 1) { ProjectUtil.openOrImport(files.get(0).getPath(), project, false); } } }); }
From source file:com.intellij.ide.util.BrowseFilesListener.java
License:Apache License
public void actionPerformed(ActionEvent e) { final VirtualFile fileToSelect = getFileToSelect(); myChooserDescriptor.setTitle(myTitle); // important to set title and description here because a shared descriptor instance can be used myChooserDescriptor.setDescription(myDescription); FileChooser.chooseFiles(myChooserDescriptor, null, fileToSelect, new Consumer<List<VirtualFile>>() { @Override//from w w w. jav a 2s .com public void consume(final List<VirtualFile> files) { doSetText(FileUtil.toSystemDependentName(files.get(0).getPath())); } }); }
From source file:com.intellij.ui.InsertPathAction.java
License:Apache License
@Override public void actionPerformed(AnActionEvent e) { String selectedText = myTextField.getSelectedText(); VirtualFile virtualFile;/* ww w . j a v a 2s . co m*/ if (selectedText != null) { virtualFile = LocalFileSystem.getInstance() .findFileByPath(selectedText.replace(File.separatorChar, '/')); } else { virtualFile = null; } //TODO use from openapi //FeatureUsageTracker.getInstance().triggerFeatureUsed("ui.commandLine.insertPath"); VirtualFile[] files = FileChooser.chooseFiles(myDescriptor, myTextField, getEventProject(e), virtualFile); if (files.length != 0) { myTextField.replaceSelection(files[0].getPresentableUrl()); } }
From source file:com.intellij.ui.PathsChooserComponent.java
License:Apache License
public PathsChooserComponent(@NotNull final List<String> collection, @NotNull final PathProcessor processor, @Nullable final Project project) { myList = new JBList(); myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myInitialCollection = collection;/*from w w w .j a v a2 s. c o m*/ myProject = project; myWorkingCollection = new ArrayList<String>(myInitialCollection); myListModel = new DefaultListModel(); myList.setModel(myListModel); myContentPane = ToolbarDecorator.createDecorator(myList).disableUpDownActions() .setAddAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { final FileChooserDescriptor dirChooser = FileChooserDescriptorFactory .createSingleFolderDescriptor(); dirChooser.setShowFileSystemRoots(true); dirChooser.setHideIgnored(true); dirChooser.setTitle(UIBundle.message("file.chooser.default.title")); FileChooser.chooseFiles(dirChooser, myProject, null, new Consumer<List<VirtualFile>>() { @Override public void consume(List<VirtualFile> files) { for (VirtualFile file : files) { // adding to the end final String path = file.getPath(); if (processor.addPath(myWorkingCollection, path)) { myListModel.addElement(path); } } } }); } }).setRemoveAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { int selected = myList.getSelectedIndex(); if (selected != -1) { // removing index final String path = (String) myListModel.get(selected); if (processor.removePath(myWorkingCollection, path)) { myListModel.remove(selected); } } } }).createPanel(); // fill list reset(); }