Search in sources :

Example 1 with TreeFileChooserDialog

use of com.intellij.ide.util.TreeFileChooserDialog in project intellij-plugins by JetBrains.

the class ConfigFileRunSettingsSection method createComponent.

@NotNull
@Override
protected JComponent createComponent(@NotNull CreationContext creationContext) {
    JPanel panel = new JPanel(new GridBagLayout());
    {
        GridBagConstraints c = new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(UIUtil.DEFAULT_VGAP, 0, 0, UIUtil.DEFAULT_HGAP), 0, 0);
        myLabel.setDisplayedMnemonic('C');
        myLabel.setHorizontalAlignment(SwingConstants.RIGHT);
        myLabel.setLabelFor(myConfigFileTextFieldWithBrowseButton.getTextField());
        panel.add(myLabel, c);
    }
    {
        GridBagConstraints c = new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(UIUtil.DEFAULT_VGAP, 0, 0, 0), 0, 0);
        final Project project = creationContext.getProject();
        final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) {

            @Override
            public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
                boolean visible = super.isFileVisible(file, showHiddenFiles);
                if (visible && !file.isDirectory() && !showHiddenFiles) {
                    visible = JstdConfigFileUtils.isJstdConfigFile(file);
                }
                return visible;
            }
        };
        final JTextField configFileTextField = myConfigFileTextFieldWithBrowseButton.getTextField();
        FileChooserFactory.getInstance().installFileCompletion(configFileTextField, descriptor, false, null);
        myConfigFileTextFieldWithBrowseButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                PsiFile initialPsiFile = getConfigFile(project);
                TreeFileChooserDialog fileChooser = new TreeFileChooserDialog(project, "Select JsTestDriver configuration file", initialPsiFile, JstdConfigFileType.INSTANCE, new TreeFileChooser.PsiFileFilter() {

                    @Override
                    public boolean accept(PsiFile psiFile) {
                        return true;
                    }
                }, false, false);
                boolean jstdConfigFilesExists = JstdSettingsUtil.areJstdConfigFilesInProject(project);
                if (jstdConfigFilesExists) {
                    fileChooser.selectSearchByNameTab();
                }
                fileChooser.showDialog();
                PsiFile psiFile = fileChooser.getSelectedFile();
                if (psiFile != null) {
                    VirtualFile vFile = psiFile.getVirtualFile();
                    if (vFile != null) {
                        String path = FileUtil.toSystemDependentName(vFile.getPath());
                        configFileTextField.setText(path);
                    }
                }
            }
        });
        panel.add(myConfigFileTextFieldWithBrowseButton, c);
    }
    SwingUtils.addGreedyBottomRow(panel);
    return panel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ActionEvent(java.awt.event.ActionEvent) Project(com.intellij.openapi.project.Project) TreeFileChooser(com.intellij.ide.util.TreeFileChooser) ActionListener(java.awt.event.ActionListener) PsiFile(com.intellij.psi.PsiFile) TreeFileChooserDialog(com.intellij.ide.util.TreeFileChooserDialog) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

TreeFileChooser (com.intellij.ide.util.TreeFileChooser)1 TreeFileChooserDialog (com.intellij.ide.util.TreeFileChooserDialog)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 NotNull (org.jetbrains.annotations.NotNull)1