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;
}
Aggregations