// Path: src/org/idea/processing/plugin/ProcessingPluginUtil.java
// public enum ProcessingPluginUtil {
//     INSTANCE;
// 
//     public Collection<VirtualFile> filterFilesAtRoot(@NotNull String path, @NotNull Predicate<VirtualFile> predicate) {
//         VirtualFile importableRoot = LocalFileFinder.findFile(path);
// 
//         if (importableRoot == null) {
//             return new HashSet<>();
//         }
// 
//         return Arrays.stream(importableRoot.getChildren())
//                 .filter(predicate)
//                 .collect(Collectors.toSet());
//     }
// 
//     public GlobalSearchScope sketchesInModuleScope(Module[] modules) {
//         if (modules == null || modules.length == 0) return null;
// 
//         GlobalSearchScope scope = GlobalSearchScope.moduleScope(modules[0]);
// 
//         for (int i = 1; i < modules.length; i++) {
//             scope.uniteWith(GlobalSearchScope.moduleScope(modules[i]));
//         }
// 
//         return scope;
//     }
// }


import com.intellij.ide.impl.ProjectUtil;
import com.intellij.ide.util.projectWizard.WizardContext;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileVisitor;
import com.intellij.projectImport.ProjectImportWizardStep;
import com.intellij.ui.DocumentAdapter;
import com.intellij.ui.JBColor;
import com.intellij.util.PathUtil;
import org.idea.processing.plugin.ProcessingPluginUtil;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import java.awt.event.ItemEvent;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.StringJoiner;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Predicate;
                            customImportRootDirectoryBrowser.setVisible(true);
                            customImportRootDirectoryBrowser.setEnabled(true);
                        } else {
                            customImportRootDirectoryBrowser.setVisible(false);
                            customImportRootDirectoryBrowser.setEnabled(false);
                        }

                        refreshProjectCreationPreview();
                    });
                } else {
                    radioButton.addItemListener(e -> refreshProjectCreationPreview());
                }
            }
        }
    }

    @Override
    public void updateDataModel() {
        getWizardContext().setProjectName(PathUtil.getFileName(projectRootDirectoryBrowser.getText()));
        getWizardContext().setProjectFileDirectory(projectRootDirectoryBrowser.getText());

        if (importIntoDefaultProjectOption.isSelected()) {
            getParameters().projectCreationRoot = ProjectUtil.getBaseDir();
        } else if (createProjectInSelectedRootOption.isSelected()) {
            getParameters().projectCreationRoot = projectRootDirectoryBrowser.getText();
        } else if (importProjectIntoCustomRootOption.isSelected()) {
            getParameters().projectCreationRoot = customImportRootDirectoryBrowser.getText();
        }

        getParameters().root = projectRootDirectoryBrowser.getText();
// Path: src/org/idea/processing/plugin/ProcessingPluginUtil.java
// public enum ProcessingPluginUtil {
//     INSTANCE;
// 
//     public Collection<VirtualFile> filterFilesAtRoot(@NotNull String path, @NotNull Predicate<VirtualFile> predicate) {
//         VirtualFile importableRoot = LocalFileFinder.findFile(path);
// 
//         if (importableRoot == null) {
//             return new HashSet<>();
//         }
// 
//         return Arrays.stream(importableRoot.getChildren())
//                 .filter(predicate)
//                 .collect(Collectors.toSet());
//     }
// 
//     public GlobalSearchScope sketchesInModuleScope(Module[] modules) {
//         if (modules == null || modules.length == 0) return null;
// 
//         GlobalSearchScope scope = GlobalSearchScope.moduleScope(modules[0]);
// 
//         for (int i = 1; i < modules.length; i++) {
//             scope.uniteWith(GlobalSearchScope.moduleScope(modules[i]));
//         }
// 
//         return scope;
//     }
// }


// Path: src/org/idea/processing/plugin/pde_import/ProcessingSketchRootSelectStep.java
import com.intellij.ide.impl.ProjectUtil;
import com.intellij.ide.util.projectWizard.WizardContext;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileVisitor;
import com.intellij.projectImport.ProjectImportWizardStep;
import com.intellij.ui.DocumentAdapter;
import com.intellij.ui.JBColor;
import com.intellij.util.PathUtil;
import org.idea.processing.plugin.ProcessingPluginUtil;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import java.awt.event.ItemEvent;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.StringJoiner;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Predicate;

                            customImportRootDirectoryBrowser.setVisible(true);
                            customImportRootDirectoryBrowser.setEnabled(true);
                        } else {
                            customImportRootDirectoryBrowser.setVisible(false);
                            customImportRootDirectoryBrowser.setEnabled(false);
                        }

                        refreshProjectCreationPreview();
                    });
                } else {
                    radioButton.addItemListener(e -> refreshProjectCreationPreview());
                }
            }
        }
    }

    @Override
    public void updateDataModel() {
        getWizardContext().setProjectName(PathUtil.getFileName(projectRootDirectoryBrowser.getText()));
        getWizardContext().setProjectFileDirectory(projectRootDirectoryBrowser.getText());

        if (importIntoDefaultProjectOption.isSelected()) {
            getParameters().projectCreationRoot = ProjectUtil.getBaseDir();
        } else if (createProjectInSelectedRootOption.isSelected()) {
            getParameters().projectCreationRoot = projectRootDirectoryBrowser.getText();
        } else if (importProjectIntoCustomRootOption.isSelected()) {
            getParameters().projectCreationRoot = customImportRootDirectoryBrowser.getText();
        }

        getParameters().root = projectRootDirectoryBrowser.getText();
        getParameters().importablePdeFiles = ProcessingPluginUtil.INSTANCE.filterFilesAtRoot(projectRootDirectoryBrowser.getText(), isPdeFile());