Example usage for com.intellij.openapi.fileChooser FileChooserDescriptorFactory createMultipleFoldersDescriptor

List of usage examples for com.intellij.openapi.fileChooser FileChooserDescriptorFactory createMultipleFoldersDescriptor

Introduction

In this page you can find the example usage for com.intellij.openapi.fileChooser FileChooserDescriptorFactory createMultipleFoldersDescriptor.

Prototype

public static FileChooserDescriptor createMultipleFoldersDescriptor() 

Source Link

Usage

From source file:com.intellij.packaging.impl.elements.DirectoryCopyElementType.java

License:Apache License

@NotNull
public List<? extends DirectoryCopyPackagingElement> chooseAndCreate(@NotNull ArtifactEditorContext context,
        @NotNull Artifact artifact, @NotNull CompositePackagingElement<?> parent) {
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createMultipleFoldersDescriptor();
    final VirtualFile[] files = FileChooser.chooseFiles(descriptor, context.getProject(), null);
    final List<DirectoryCopyPackagingElement> list = new ArrayList<DirectoryCopyPackagingElement>();
    for (VirtualFile file : files) {
        list.add(new DirectoryCopyPackagingElement(file.getPath()));
    }/*  w w  w  .  j  av a 2  s.  c  o m*/
    return list;
}

From source file:com.perl5.lang.perl.idea.configuration.settings.sdk.Perl5ProjectConfigurable.java

License:Apache License

private void doAddExternalLibrary(AnActionButton button) {
    FileChooserFactory.getInstance()/*from www.  j  ava2s .  co m*/
            .createPathChooser(FileChooserDescriptorFactory.createMultipleFoldersDescriptor()
                    .withTreeRootVisible(true).withTitle(PerlBundle.message("perl.settings.select.libs")),
                    myProject, myLibsList)
            .choose(null, virtualFiles -> {
                Ref<Boolean> notifyInternals = new Ref<>(false);

                List<VirtualFile> rootsToAdd = new ArrayList<>();

                for (VirtualFile virtualFile : virtualFiles) {
                    if (!virtualFile.isValid()) {
                        continue;
                    }
                    if (!virtualFile.isDirectory()) {
                        virtualFile = virtualFile.getParent();
                        if (virtualFile == null || !virtualFile.isValid()) {
                            continue;
                        }
                    }

                    if (ModuleUtilCore.findModuleForFile(virtualFile, myProject) != null) {
                        notifyInternals.set(true);
                        continue;
                    }
                    rootsToAdd.add(virtualFile);
                }

                myLibsModel.add(rootsToAdd);

                if (notifyInternals.get()) {
                    Messages.showErrorDialog(myLibsList,
                            PerlBundle.message("perl.settings.external.libs.internal.text"),
                            PerlBundle.message("perl.settings.external.libs.internal.title"));
                }
            });
}

From source file:com.perl5.lang.perl.idea.configuration.settings.sdk.PerlContentEntriesTreeEditor.java

License:Apache License

public PerlContentEntriesTreeEditor(@NotNull Module module, @NotNull Disposable parentDisposable) {
    Disposer.register(parentDisposable, this);

    List<PerlSourceRootType> types = ContainerUtil.newArrayList();
    Perl5SettingsConfigurableExtension.forEach(extension -> types.addAll(extension.getSourceRootTypes()));

    for (PerlSourceRootType type : types) {
        myEditingActionsGroup.add(new PerlToggleSourceRootAction(this, type.getEditHandler()));
    }/*from   w w w. j  a  v a  2 s  .c o m*/

    myModule = module;

    VirtualFile[] contentRoots = ModuleRootManager.getInstance(myModule).getContentRoots();
    myTree.setRootVisible(contentRoots.length < 2);
    myTree.setShowsRootHandles(true);
    TreeUtil.installActions(myTree);
    new TreeSpeedSearch(myTree);
    //myTree.setPreferredSize(new Dimension(250, -1));

    myTreePanel = new JPanel(new GridBagLayout());

    ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar("PerlContentEntries",
            myEditingActionsGroup, true);
    myTreePanel.add(new JLabel("Mark as:"),
            new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, 0, JBUI.insets(0, 10), 0, 0));
    myTreePanel.add(actionToolbar.getComponent(), new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0,
            GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, JBUI.emptyInsets(), 0, 0));

    final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree, true);
    myTreePanel.add(scrollPane, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 1.0,
            GridBagConstraints.WEST, GridBagConstraints.BOTH, JBUI.emptyInsets(), 0, 0));

    myTreePanel.setVisible(true);
    FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createMultipleFoldersDescriptor();
    descriptor.setShowFileSystemRoots(false);
    descriptor.setRoots(contentRoots);

    myFileSystemTree = new FileSystemTreeImpl(module.getProject(), descriptor, myTree, new MyTreeCellRenderer(),
            () -> {
                myFileSystemTree.updateTree();
                //myFileSystemTree.select(file, null);
            }, null) {
        @Override
        protected AbstractTreeBuilder createTreeBuilder(JTree tree, DefaultTreeModel treeModel,
                AbstractTreeStructure treeStructure, Comparator<NodeDescriptor> comparator,
                FileChooserDescriptor descriptor, @Nullable Runnable onInitialized) {
            return new MyFileTreeBuilder(tree, treeModel, treeStructure, comparator, descriptor, onInitialized);
        }
    };
    myFileSystemTree.showHiddens(true);
    Disposer.register(this, myFileSystemTree);

    final NewFolderAction newFolderAction = new MyNewFolderAction();
    final DefaultActionGroup mousePopupGroup = new DefaultActionGroup();
    mousePopupGroup.add(myEditingActionsGroup);
    mousePopupGroup.addSeparator();
    mousePopupGroup.add(newFolderAction);
    myFileSystemTree.registerMouseListener(mousePopupGroup);
}

From source file:com.perl5.lang.perl.util.PerlConfigurationUtil.java

License:Apache License

public static JPanel createProjectPathsSelection(@NotNull final Project myProject,
        @NotNull final JBList rootsList, @NotNull final CollectionListModel<String> rootsModel,
        @NotNull @Nls final String dialogTitle) {
    return ToolbarDecorator.createDecorator(rootsList).setAddAction(new AnActionButtonRunnable() {
        @Override//w w  w .  j a  v  a  2 s  .  c om
        public void run(AnActionButton anActionButton) {
            //rootsModel.add("New element");
            FileChooserFactory.getInstance()
                    .createPathChooser(FileChooserDescriptorFactory.createMultipleFoldersDescriptor()
                            .withRoots(myProject.getBaseDir()).withTreeRootVisible(true).withTitle(dialogTitle),
                            myProject, rootsList)
                    .choose(null, new Consumer<List<VirtualFile>>() {
                        @Override
                        public void consume(List<VirtualFile> virtualFiles) {
                            String rootPath = myProject.getBasePath();
                            if (rootPath != null) {
                                VirtualFile rootFile = VfsUtil.findFileByIoFile(new File(rootPath), true);

                                if (rootFile != null) {
                                    for (VirtualFile file : virtualFiles) {
                                        String relativePath = VfsUtil.getRelativePath(file, rootFile);
                                        if (!rootsModel.getItems().contains(relativePath)) {
                                            rootsModel.add(relativePath);
                                        }
                                    }
                                }
                            }
                        }
                    });
        }
    }).setPreferredSize(JBUI.size(0, WIDGET_HEIGHT)).createPanel();
}