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);
}
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);
}
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);
}
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);
}
});
}
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;
}
Aggregations