Example usage for com.intellij.openapi.fileChooser FileChooserDescriptor setTitle

List of usage examples for com.intellij.openapi.fileChooser FileChooserDescriptor setTitle

Introduction

In this page you can find the example usage for com.intellij.openapi.fileChooser FileChooserDescriptor setTitle.

Prototype

public void setTitle(@Nls(capitalization = Nls.Capitalization.Title) String title) 

Source Link

Usage

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);
            }//  www .j  a  v a2 s  .  c om
        }
    }
    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.plugins.InstalledPluginsManagerMain.java

License:Apache License

public InstalledPluginsManagerMain(PluginManagerUISettings uiSettings) {
    super(uiSettings);
    init();// w  ww .ja  va2 s.co  m
    myActionsPanel.setLayout(new FlowLayout(FlowLayout.LEFT));

    final JButton button = new JButton("Browse repositories...");
    button.setMnemonic('b');
    button.addActionListener(new BrowseRepoListener(null));
    myActionsPanel.add(button);

    final JButton installPluginFromFileSystem = new JButton("Install plugin from disk...");
    installPluginFromFileSystem.setMnemonic('d');
    installPluginFromFileSystem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, false, true, true, false,
                    false) {
                @Override
                public boolean isFileSelectable(VirtualFile file) {
                    return file.getFileType() instanceof ArchiveFileType;
                }
            };
            descriptor.setTitle("Choose Plugin File");
            descriptor.setDescription("JAR and ZIP archives are accepted");
            FileChooser.chooseFile(descriptor, null, myActionsPanel, null, new Consumer<VirtualFile>() {
                @Override
                public void consume(@NotNull VirtualFile virtualFile) {
                    final File file = VfsUtilCore.virtualToIoFile(virtualFile);
                    try {
                        final IdeaPluginDescriptorImpl pluginDescriptor = PluginDownloader
                                .loadDescriptionFromJar(file);
                        if (pluginDescriptor == null) {
                            Messages.showErrorDialog(
                                    "Fail to load plugin descriptor from file " + file.getName(),
                                    CommonBundle.getErrorTitle());
                            return;
                        }
                        if (PluginManagerCore.isIncompatible(pluginDescriptor)) {
                            Messages.showErrorDialog(
                                    "Plugin " + pluginDescriptor.getName()
                                            + " is incompatible with current installation",
                                    CommonBundle.getErrorTitle());
                            return;
                        }
                        final IdeaPluginDescriptor alreadyInstalledPlugin = PluginManager
                                .getPlugin(pluginDescriptor.getPluginId());
                        if (alreadyInstalledPlugin != null) {
                            final File oldFile = alreadyInstalledPlugin.getPath();
                            if (oldFile != null) {
                                StartupActionScriptManager.addActionCommand(
                                        new StartupActionScriptManager.DeleteCommand(oldFile));
                            }
                        }
                        if (((InstalledPluginsTableModel) pluginsModel)
                                .appendOrUpdateDescriptor(pluginDescriptor)) {
                            PluginDownloader.install(file, file.getName(), false);
                            select(pluginDescriptor);
                            checkInstalledPluginDependencies(pluginDescriptor);
                            setRequireShutdown(true);
                        } else {
                            Messages.showInfoMessage(myActionsPanel,
                                    "Plugin " + pluginDescriptor.getName() + " was already installed",
                                    CommonBundle.getWarningTitle());
                        }
                    } catch (IOException ex) {
                        Messages.showErrorDialog(ex.getMessage(), CommonBundle.getErrorTitle());
                    }
                }
            });
        }
    });
    myActionsPanel.add(installPluginFromFileSystem);
    final StatusText emptyText = pluginTable.getEmptyText();
    emptyText.setText("Nothing to show.");
    emptyText.appendText(" Click ");
    emptyText.appendText("Browse", SimpleTextAttributes.LINK_ATTRIBUTES, new BrowseRepoListener(null));
    emptyText.appendText(" to search for non-bundled plugins.");
}

From source file:com.intellij.lang.ant.config.explorer.AntExplorer.java

License:Apache License

private void addBuildFile() {
    final FileChooserDescriptor descriptor = createXmlDescriptor();
    descriptor.setTitle(AntBundle.message("select.ant.build.file.dialog.title"));
    descriptor.setDescription(AntBundle.message("select.ant.build.file.dialog.description"));
    final VirtualFile[] files = FileChooser.chooseFiles(descriptor, myProject, null);
    addBuildFile(files);/*  w w  w.jav a  2 s  .  c  o m*/
}

From source file:com.intellij.packaging.impl.ManifestFileUtil.java

License:Apache License

public static FileChooserDescriptor createDescriptorForManifestDirectory() {
    FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    descriptor.setTitle("Select Directory for META-INF/MANIFEST.MF file");
    return descriptor;
}

From source file:com.intellij.packaging.impl.ui.properties.ElementWithManifestPropertiesPanel.java

License:Apache License

private void chooseManifest() {
    final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false,
            false) {//from   ww w. java 2  s  . c  om
        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory()
                    || file.getName().equalsIgnoreCase(ManifestFileUtil.MANIFEST_FILE_NAME));
        }
    };
    descriptor.setTitle("Specify Path to MANIFEST.MF file");
    final VirtualFile file = FileChooser.chooseFile(descriptor, myContext.getProject(), null);
    if (file == null) {
        return;
    }

    ManifestFileUtil.addManifestFileToLayout(file.getPath(), myContext, myElement);
    updateManifest();
    myContext.getThisArtifactEditor().updateLayoutTree();
}

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 . ja v a2  s  . co 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();
}

From source file:com.intellij.xml.actions.xmlbeans.UIUtils.java

License:Apache License

public static void configureBrowseButton(final Project myProject, final TextFieldWithBrowseButton wsdlUrl,
        final String[] _extensions, final String selectFileDialogTitle, final boolean multipleFileSelection) {
    wsdlUrl.getButton().setToolTipText(XmlBundle.message("browse.button.tooltip"));
    wsdlUrl.getButton().addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            final FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false,
                    false, false, multipleFileSelection) {
                private final List<String> extensions = Arrays.asList(_extensions);

                public boolean isFileSelectable(VirtualFile virtualFile) {
                    return extensions.contains(virtualFile.getExtension());
                }//  ww  w  . j av a2s  . c  om

                @Override
                public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
                    return super.isFileVisible(file, showHiddenFiles)
                            && (file.isDirectory() || isFileSelectable(file));
                }
            };

            fileChooserDescriptor.setTitle(selectFileDialogTitle);

            VirtualFile initialFile = myProject.getBaseDir();
            String selectedItem = wsdlUrl.getTextField().getText();
            if (selectedItem != null && selectedItem.startsWith(LocalFileSystem.PROTOCOL_PREFIX)) {
                VirtualFile fileByPath = VfsUtil.findRelativeFile(ExternalResourceManager.getInstance()
                        .getResourceLocation(VfsUtil.fixURLforIDEA(selectedItem)), null);
                if (fileByPath != null)
                    initialFile = fileByPath;
            }

            final VirtualFile[] virtualFiles = FileChooser.chooseFiles(fileChooserDescriptor, myProject,
                    initialFile);
            if (virtualFiles.length == 1) {
                String url = fixIDEAUrl(virtualFiles[0].getUrl());
                wsdlUrl.setText(url);
            }
        }
    });
}

From source file:com.jsrana.plugins.quicknotes.ui.OptionsDialog.java

OptionsDialog(Element element) {
    super();//from w  w  w . java  2 s.  c  om
    this.element = element;
    setContentPane(contentPane);
    setModal(true);
    getRootPane().setDefaultButton(buttonOK);
    setTitle("Quick Notes Options");
    logoLabel.setIcon(QuickNotesIcon.QUICKNOTES_48);

    buttonOK.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    buttonOK.setIcon(QuickNotesIcon.CLOSE);
    buttonOK.setBackground(JBColor.background());
    buttonOK.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            onOK();
        }
    });

    buttonComments.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    buttonComments.setIcon(QuickNotesIcon.COMMENT);
    buttonComments.setBackground(JBColor.background());
    buttonComments.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Utils.openURL("https://plugins.jetbrains.com/plugin/4456-quick-notes");
        }
    });

    buttonIssue.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    buttonIssue.setIcon(QuickNotesIcon.ALERT);
    buttonIssue.setBackground(JBColor.background());
    buttonIssue.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Utils.openURL("https://github.com/jrana/quicknotes/issues");
        }
    });

    buttonLicense.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    buttonLicense.setIcon(QuickNotesIcon.LICENSE);
    buttonLicense.setBackground(JBColor.background());
    buttonLicense.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    buttonLicense.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            LicenseDialog dialog = new LicenseDialog();
            dialog.setLocationRelativeTo(null);
            dialog.pack();
            dialog.setVisible(true);
        }
    });

    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            onCancel();
        }
    });

    contentPane.registerKeyboardAction(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            onCancel();
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    final QuickNotesManager manager = QuickNotesManager.getInstance();
    String currentFontName = manager.getNotesFont().getFontName();
    String currentFontSize = String.valueOf(manager.getNotesFont().getSize());
    String[] fontList = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    for (String aFontList : fontList) {
        comboBoxFont.addItem(aFontList);
    }
    comboBoxFont.setSelectedItem(currentFontName);

    String[] fontSizes = { "8", "10", "11", "12", "14", "16", "18", "20", "24", "28", "32", "36", "40", "48",
            "52", "56", "64", "72", "92" };
    for (String fontSize : fontSizes) {
        comboBoxFontSize.addItem(fontSize);
    }
    comboBoxFontSize.setSelectedItem(currentFontSize);

    comboBoxFont.setBackground(JBColor.background());
    comboBoxFont.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            manager.setNotesFont(new Font(String.valueOf(comboBoxFont.getSelectedItem()), Font.PLAIN,
                    Integer.parseInt(String.valueOf(comboBoxFontSize.getSelectedItem()))));
        }
    });

    comboBoxFontSize.setBackground(JBColor.background());
    comboBoxFontSize.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            manager.setNotesFont(new Font(String.valueOf(comboBoxFont.getSelectedItem()), Font.PLAIN,
                    Integer.parseInt(String.valueOf(comboBoxFontSize.getSelectedItem()))));
        }
    });

    if (manager.isWordWrap()) {
        checkBoxShowLineNumbers.setEnabled(false);
        checkBoxShowLineNumbers.setSelected(false);
    } else {
        checkBoxShowLineNumbers.setSelected(manager.isShowLineNumbers());
    }
    checkBoxShowLineNumbers.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AbstractButton abstractButton = (AbstractButton) e.getSource();
            if (!manager.isWordWrap()) {
                manager.setShowLineNumbers(abstractButton.getModel().isSelected());
            }
        }
    });

    checkBoxWordWrap.setSelected(manager.isWordWrap());
    checkBoxWordWrap.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AbstractButton abstractButton = (AbstractButton) e.getSource();
            manager.setWordWrap(abstractButton.getModel().isSelected());
            if (abstractButton.getModel().isSelected()) {
                manager.setShowLineNumbers(false);
                checkBoxShowLineNumbers.setSelected(false);
                checkBoxShowLineNumbers.setEnabled(false);
            } else {
                checkBoxShowLineNumbers.setEnabled(true);
            }
        }
    });

    labelWebsite.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    labelWebsite.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            Utils.openURL("https://github.com/jrana/quicknotes");
        }
    });

    labelManual.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    labelManual.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            Utils.openURL(
                    "http://docs.google.com/fileview?id=0B6GyR43t58eXNzQ1ZmUyOTktZDc5NS00ZWRkLTlmMGMtOGQ0ZGIyZjdhM2E0&hl=en");
        }
    });

    chooseFontColorButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            myFontColorRadio.setSelected(true);
            Color newColor = ColorChooser.chooseColor(OptionsDialog.this, "Choose Font Color",
                    manager.getFontColor());
            if (newColor != null) {
                manager.setFontColor(newColor, false);
            }
        }
    });

    defaultFontColorRadio.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            manager.setFontColor(QuickNotesPanel.EDITOR_COLOR_FONT, true);
        }
    });

    chooseBackgroundColorButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            myBackgroundColorRadio.setSelected(true);
            Color newColor = ColorChooser.chooseColor(OptionsDialog.this, "Choose Background Color",
                    manager.getBackgroundColor());
            if (newColor != null) {
                manager.setBackgroundColor(newColor, false);
            }
        }
    });

    defaultBackgroundColorRadio.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            manager.setBackgroundColor(QuickNotesPanel.EDITOR_COLOR_BACKGROUND, true);
        }
    });

    if (manager.isBackgroundColor_default()) {
        defaultBackgroundColorRadio.setSelected(true);
    } else {
        myBackgroundColorRadio.setSelected(true);
    }

    checkBoxShowBackgroundLines.setSelected(manager.isShowBackgroundLines());
    checkBoxShowBackgroundLines.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AbstractButton abstractButton = (AbstractButton) e.getSource();
            manager.setShowBackgroundLines(abstractButton.getModel().isSelected());
        }
    });

    if (manager.isBackgroundLineColor_default()) {
        defaultLineColorRadio.setSelected(true);
    } else {
        myLineColorRadio.setSelected(true);
    }

    chooseLineColorButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            myLineColorRadio.setSelected(true);
            Color newColor = ColorChooser.chooseColor(OptionsDialog.this, "Choose Line Color",
                    manager.getBackgroundLineColor());
            if (newColor != null) {
                manager.setBackgroundLineColor(newColor, false);
            }
        }
    });

    defaultLineColorRadio.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            manager.setBackgroundLineColor(QuickNotesPanel.EDITOR_COLOR_LINE, true);
        }
    });

    aboutVersionLabel.setText("Quick Notes " + QuickNotesManager.VERSION);

    /*
            labelFileLocation.setText( QuickNotesManager.getInstance().getFileLocation_default() );
            chooseFileLocationButton.addActionListener( new ActionListener() {
    @Override public void actionPerformed( ActionEvent e ) {
        final JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY );
        fileChooser.setCurrentDirectory( new File( QuickNotesManager.getInstance().getFileLocation_default() ) );
        int returnVal = fileChooser.showOpenDialog( null );
        if ( returnVal == JFileChooser.APPROVE_OPTION ) {
            File file = fileChooser.getSelectedFile();
            QuickNotesManager.getInstance().setFileLocation_default( file.getAbsolutePath() );
        }
    }
            } );
    */

    if (manager.isLineNumberColor_default()) {
        defaultLineNumberColorRadio.setSelected(true);
    } else {
        myLineNumberColorRadio.setSelected(true);
    }
    chooseLineNumberColorButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            myLineNumberColorRadio.setSelected(true);
            Color newColor = ColorChooser.chooseColor(OptionsDialog.this, "Choose Line Number Color",
                    manager.getLineNumberColor());
            if (newColor != null) {
                manager.setLineNumberColor(newColor, false);
            }
        }
    });
    defaultLineNumberColorRadio.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            manager.setLineNumberColor(QuickNotesPanel.EDITOR_COLOR_LINENUMBER, true);
        }
    });

    // file location
    fileLocationLabel.setText(QuickNotesManager.getFolderPath());
    buttonFileLocation.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(false, true, false, false,
                    false, false);
            fileChooserDescriptor.setTitle("Choose Plugin File Location");
            String fileLocationPath = QuickNotesManager.getFolderPath();

            VirtualFile virtualFile = FileChooser.chooseFile(fileChooserDescriptor, null,
                    new VirtualFileWrapper(new File(fileLocationPath)).getVirtualFile());
            if (virtualFile != null) {
                File newFolder = new File(virtualFile.getPath());
                if (!newFolder.getAbsolutePath().equals(fileLocationPath)) {
                    boolean persist = true;
                    if (!newFolder.exists()) {
                        if (!newFolder.mkdir()) {
                            JOptionPane.showMessageDialog(null, "Unable to make folder. Please try again",
                                    "Error", JOptionPane.ERROR_MESSAGE);
                            persist = false;
                        }
                    }
                    if (persist) {
                        moveQuickNotesFile(manager, newFolder);
                    }
                }
            }
            /*
                            fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                            fileChooser.setCurrentDirectory(new File(fileLocationPath));
                            int returnVal = fileChooser.showOpenDialog(null);
                            if (returnVal == JFileChooser.APPROVE_OPTION) {
            File newFolder = fileChooser.getSelectedFile();
            if (!newFolder.getAbsolutePath().equals(fileLocationPath)) {
                boolean persist = true;
                if (!newFolder.exists()) {
                    if (!newFolder.mkdir()) {
                        JOptionPane.showMessageDialog(null, "Unable to make folder. Please try again", "Error", JOptionPane.ERROR_MESSAGE);
                        persist = false;
                    }
                }
                if (persist) {
                    moveQuickNotesFile(manager, newFolder);
                }
            }
                            }
            */
        }
    });
}

From source file:com.machak.idea.plugins.config.PluginConfiguration.java

License:Apache License

private void chooseFolder(final TextAccessor field, final boolean chooseFiles, final boolean chooseFolders) {
    final FileChooserDescriptor descriptor = new FileChooserDescriptor(chooseFiles, chooseFolders, false, false,
            false, false) {/*from ww  w . j  ava  2 s .co  m*/
        @Override
        public String getName(VirtualFile virtualFile) {
            return virtualFile.getName();
        }

        @Override
        @Nullable
        public String getComment(VirtualFile virtualFile) {
            return virtualFile.getPresentableUrl();
        }
    };
    descriptor.setTitle("Select  Folder");

    final String selectedPath = field.getText();
    final VirtualFile preselectedFolder = LocalFileSystem.getInstance().findFileByPath(selectedPath);

    final VirtualFile[] files = FileChooser.chooseFiles(descriptor, mainPanel, getProject(mainPanel),
            preselectedFolder);
    if (files.length > 0) {
        field.setText(files[0].getPath());
    }
}

From source file:com.machak.idea.plugins.tomcat.config.PluginConfiguration.java

License:Apache License

private void chooseFolder(final TextAccessor field, final boolean chooseFiles) {
    final FileChooserDescriptor descriptor = new FileChooserDescriptor(chooseFiles, !chooseFiles, false, false,
            false, false) {/*  ww w . j  a  v a  2s.c o  m*/
        public String getName(VirtualFile virtualFile) {
            return virtualFile.getName();
        }

        @Nullable
        public String getComment(VirtualFile virtualFile) {
            return virtualFile.getPresentableUrl();
        }
    };
    descriptor.setTitle("Select Project Destination Folder");

    final String selectedPath = field.getText();
    final VirtualFile preselectedFolder = LocalFileSystem.getInstance().findFileByPath(selectedPath);

    final VirtualFile[] files = FileChooser.chooseFiles(descriptor, mainPanel, getProject(mainPanel),
            preselectedFolder);
    if (files.length > 0) {
        field.setText(files[0].getPath());
    }
}