I am creating a plugin in IntelliJ IDEA using Jetbrains plugin SDK. I have created a Dialog box that shows a button to select a Directory. In the ActionListener of the button, I am calling FileChooser dialog. After i select a directory from this dialog, i get the following error
java.lang.Throwable: Slow operations are prohibited on EDT. See SlowOperations.assertSlowOperationsAreAllowed javadoc.
at com.intellij.openapi.diagnostic.Logger.error(Logger.java:376)
at com.intellij.util.SlowOperations.assertSlowOperationsAreAllowed(SlowOperations.java:101)
at com.intellij.openapi.vfs.newvfs.persistent.FSRecordsImpl.update(FSRecordsImpl.java:718)
at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl.findChildInfo(PersistentFSImpl.java:598)
at com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl.findInPersistence(VirtualDirectoryImpl.java:154)
at com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl.doFindChild(VirtualDirectoryImpl.java:137)
at com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl.findChild(VirtualDirectoryImpl.java:83)
at com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl.refreshAndFindChild(VirtualDirectoryImpl.java:352)
at com.intellij.openapi.vfs.newvfs.VfsImplUtil.refreshAndFindFileByPath(VfsImplUtil.java:118)
at com.intellij.openapi.vfs.impl.local.LocalFileSystemBase.refreshAndFindFileByPath(LocalFileSystemBase.java:129)
at com.intellij.ui.PathChooserDialogHelper$Companion.fileToVirtualFile(PathChooserDialogHelper.kt:52)
at com.intellij.ui.PathChooserDialogHelper$Companion.access$fileToVirtualFile(PathChooserDialogHelper.kt:50)
at com.intellij.ui.PathChooserDialogHelper.fileToVirtualFile(PathChooserDialogHelper.kt:47)
at com.intellij.ui.PathChooserDialogHelper.getChosenFiles(PathChooserDialogHelper.kt:35)
at com.intellij.ui.mac.MacPathChooserDialog.choose(MacPathChooserDialog.java:131)
at com.intellij.ui.mac.MacPathChooserDialog.choose(MacPathChooserDialog.java:171)
at com.intellij.ui.mac.MacPathChooserDialog.choose(MacPathChooserDialog.java:177)
at com.intellij.openapi.fileChooser.FileChooser.chooseFiles(FileChooser.java:46)
at com.intellij.openapi.fileChooser.FileChooser.chooseFiles(FileChooser.java:38)
This is how I am adding the FileChooser dialog in the button's ActionListener
JButton directorySelectorButton = new JButton("", AllIcons.Nodes.Folder);
directorySelectorButton.addActionListener(e -> {
FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false);
VirtualFile[] chosenFiles = FileChooser.chooseFiles(descriptor, null, null);
System.out.println(chosenFiles[0].getPath());
});