Example usage for com.intellij.openapi.fileChooser FileChooserDescriptor validateSelectedFiles

List of usage examples for com.intellij.openapi.fileChooser FileChooserDescriptor validateSelectedFiles

Introduction

In this page you can find the example usage for com.intellij.openapi.fileChooser FileChooserDescriptor validateSelectedFiles.

Prototype

public void validateSelectedFiles(VirtualFile @NotNull [] files) throws Exception 

Source Link

Document

the method is called upon pressing Ok in the FileChooserDialog Override the method in order to customize validation of user input

Usage

From source file:com.microsoft.azure.hdinsight.projects.SparkLibraryOptionsPanel.java

License:Open Source License

private NewLibraryEditor getNewLibraryEditor(@NotNull String path) {
    if (StringHelper.isNullOrWhiteSpace(path)) {
        return null;
    }/*from  w w  w  . j  av a  2s  .  c  o  m*/

    VirtualFile root = LocalFileSystem.getInstance().findFileByPath(path);
    if (root == null) {
        return null;
    }

    final FileChooserDescriptor chooserDescriptor = new FileChooserDescriptor(false, false, true, false, true,
            false);
    VirtualFile[] libraryFiles = VfsUtilCore
            .toVirtualFileArray(FileChooserUtil.getChosenFiles(chooserDescriptor, Arrays.asList(root)));

    try {
        chooserDescriptor.validateSelectedFiles(libraryFiles);
    } catch (Exception exception) {
        //do noting if check failed
        return null;
    }

    final List<OrderRoot> roots = RootDetectionUtil.detectRoots(Arrays.asList(libraryFiles), null, null,
            new DefaultLibraryRootsComponentDescriptor());
    if (roots.isEmpty()) {
        return null;
    }

    NewLibraryConfiguration configuration = new NewLibraryConfiguration(
            LibraryTypeServiceImpl.suggestLibraryName(roots), SparkLibraryType.getInstance(),
            new SparkLibraryProperties()) {
        @Override
        public void addRoots(@NotNull LibraryEditor libraryEditor) {
            libraryEditor.addRoots(roots);
        }
    };

    if (configuration != null) {
        NewLibraryEditor libraryEditor = new NewLibraryEditor(configuration.getLibraryType(),
                configuration.getProperties());
        libraryEditor.setName(suggestUniqueLibraryName(configuration.getDefaultLibraryName()));
        configuration.addRoots(libraryEditor);

        return libraryEditor;
    }

    return null;
}