Search in sources :

Example 56 with FileChooserDescriptor

use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.

the class ProjectSettingsStepBase method createLocationComponent.

protected final LabeledComponent<TextFieldWithBrowseButton> createLocationComponent() {
    myLocationField = new TextFieldWithBrowseButton();
    myProjectDirectory = findSequentNonExistingUntitled();
    final String projectLocation = myProjectDirectory.toString();
    myLocationField.setText(projectLocation);
    final int index = projectLocation.lastIndexOf(File.separator);
    if (index > 0) {
        JTextField textField = myLocationField.getTextField();
        textField.select(index + 1, projectLocation.length());
        textField.putClientProperty(DialogWrapperPeer.HAVE_INITIAL_SELECTION, true);
    }
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    myLocationField.addBrowseFolderListener("Select Base Directory", "Select base directory for the project", null, descriptor);
    return LabeledComponent.create(myLocationField, BundleBase.replaceMnemonicAmpersand("&Location"), BorderLayout.WEST);
}
Also used : FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor)

Example 57 with FileChooserDescriptor

use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.

the class ContentEntryTreeEditor method setContentEntryEditor.

/**
   * @param contentEntryEditor : null means to clear the editor
   */
public void setContentEntryEditor(final ContentEntryEditor contentEntryEditor) {
    if (myContentEntryEditor != null && myContentEntryEditor.equals(contentEntryEditor)) {
        return;
    }
    if (myFileSystemTree != null) {
        Disposer.dispose(myFileSystemTree);
        myFileSystemTree = null;
    }
    if (myContentEntryEditor != null) {
        myContentEntryEditor.removeContentEntryEditorListener(myContentEntryEditorListener);
        myContentEntryEditor = null;
    }
    if (contentEntryEditor == null) {
        ((DefaultTreeModel) myTree.getModel()).setRoot(EMPTY_TREE_ROOT);
        myTreePanel.setVisible(false);
        if (myFileSystemTree != null) {
            Disposer.dispose(myFileSystemTree);
        }
        return;
    }
    myTreePanel.setVisible(true);
    myContentEntryEditor = contentEntryEditor;
    myContentEntryEditor.addContentEntryEditorListener(myContentEntryEditorListener);
    final ContentEntry entry = contentEntryEditor.getContentEntry();
    assert entry != null : contentEntryEditor;
    final VirtualFile file = entry.getFile();
    if (file != null) {
        myDescriptor.setRoots(file);
    } else {
        String path = VfsUtilCore.urlToPath(entry.getUrl());
        myDescriptor.setTitle(FileUtil.toSystemDependentName(path));
    }
    final Runnable init = () -> {
        //noinspection ConstantConditions
        myFileSystemTree.updateTree();
        myFileSystemTree.select(file, null);
    };
    myFileSystemTree = new FileSystemTreeImpl(myProject, myDescriptor, myTree, getContentEntryCellRenderer(), init, null) {

        @Override
        protected AbstractTreeBuilder createTreeBuilder(JTree tree, DefaultTreeModel treeModel, AbstractTreeStructure treeStructure, Comparator<NodeDescriptor> comparator, FileChooserDescriptor descriptor, final Runnable onInitialized) {
            return new MyFileTreeBuilder(tree, treeModel, treeStructure, comparator, descriptor, onInitialized);
        }
    };
    myFileSystemTree.showHiddens(true);
    Disposer.register(myProject, myFileSystemTree);
    final NewFolderAction newFolderAction = new MyNewFolderAction();
    final DefaultActionGroup mousePopupGroup = new DefaultActionGroup();
    mousePopupGroup.add(myEditingActionsGroup);
    mousePopupGroup.addSeparator();
    mousePopupGroup.add(newFolderAction);
    myFileSystemTree.registerMouseListener(mousePopupGroup);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) AbstractTreeBuilder(com.intellij.ide.util.treeView.AbstractTreeBuilder) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) FileSystemTreeImpl(com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl) NewFolderAction(com.intellij.openapi.fileChooser.actions.NewFolderAction) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) ContentEntry(com.intellij.openapi.roots.ContentEntry) AbstractTreeStructure(com.intellij.ide.util.treeView.AbstractTreeStructure)

Example 58 with FileChooserDescriptor

use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.

the class ChooserBasedAttachRootButtonDescriptor method selectFiles.

@Override
public VirtualFile[] selectFiles(@NotNull final JComponent parent, @Nullable VirtualFile initialSelection, @Nullable final Module contextModule, @NotNull LibraryEditor libraryEditor) {
    final FileChooserDescriptor chooserDescriptor = createChooserDescriptor();
    chooserDescriptor.setTitle(getChooserTitle(libraryEditor.getName()));
    chooserDescriptor.setDescription(getChooserDescription());
    if (contextModule != null) {
        chooserDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, contextModule);
    }
    return FileChooser.chooseFiles(chooserDescriptor, parent, contextModule != null ? contextModule.getProject() : null, initialSelection);
}
Also used : FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor)

Example 59 with FileChooserDescriptor

use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.

the class SdkConfigurationUtil method selectSdkHome.

public static void selectSdkHome(@NotNull final SdkType sdkType, @NotNull final Consumer<String> consumer) {
    final FileChooserDescriptor descriptor = sdkType.getHomeChooserDescriptor();
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        Sdk sdk = ProjectJdkTable.getInstance().findMostRecentSdkOfType(sdkType);
        if (sdk == null)
            throw new RuntimeException("No SDK of type " + sdkType + " found");
        consumer.consume(sdk.getHomePath());
        return;
    }
    FileChooser.chooseFiles(descriptor, null, getSuggestedSdkRoot(sdkType), chosen -> {
        final String path = chosen.get(0).getPath();
        if (sdkType.isValidSdkHome(path)) {
            consumer.consume(path);
            return;
        }
        final String adjustedPath = sdkType.adjustSelectedSdkHome(path);
        if (sdkType.isValidSdkHome(adjustedPath)) {
            consumer.consume(adjustedPath);
        }
    });
}
Also used : FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 60 with FileChooserDescriptor

use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.

the class SdkType method getHomeChooserDescriptor.

@NotNull
public FileChooserDescriptor getHomeChooserDescriptor() {
    final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false) {

        @Override
        public void validateSelectedFiles(VirtualFile[] files) throws Exception {
            if (files.length != 0) {
                final String selectedPath = files[0].getPath();
                boolean valid = isValidSdkHome(selectedPath);
                if (!valid) {
                    valid = isValidSdkHome(adjustSelectedSdkHome(selectedPath));
                    if (!valid) {
                        String message = files[0].isDirectory() ? ProjectBundle.message("sdk.configure.home.invalid.error", getPresentableName()) : ProjectBundle.message("sdk.configure.home.file.invalid.error", getPresentableName());
                        throw new Exception(message);
                    }
                }
            }
        }
    };
    descriptor.setTitle(ProjectBundle.message("sdk.configure.home.title", getPresentableName()));
    return descriptor;
}
Also used : FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)143 VirtualFile (com.intellij.openapi.vfs.VirtualFile)97 NotNull (org.jetbrains.annotations.NotNull)35 Project (com.intellij.openapi.project.Project)21 TextFieldWithBrowseButton (com.intellij.openapi.ui.TextFieldWithBrowseButton)19 Nullable (org.jetbrains.annotations.Nullable)18 ActionEvent (java.awt.event.ActionEvent)17 File (java.io.File)17 ActionListener (java.awt.event.ActionListener)16 DocumentEvent (javax.swing.event.DocumentEvent)13 DocumentAdapter (com.intellij.ui.DocumentAdapter)10 ArrayList (java.util.ArrayList)10 FileChooser (com.intellij.openapi.fileChooser.FileChooser)9 List (java.util.List)9 IOException (java.io.IOException)8 JBLabel (com.intellij.ui.components.JBLabel)7 javax.swing (javax.swing)7 Module (com.intellij.openapi.module.Module)5 StringUtil (com.intellij.openapi.util.text.StringUtil)5 JBTable (com.intellij.ui.table.JBTable)5