List of usage examples for com.intellij.openapi.fileChooser FileChooserDialog choose
VirtualFile @NotNull [] choose(@Nullable Project project, VirtualFile @NotNull... toSelect);
From source file:com.android.tools.idea.actions.AndroidImportProjectAction.java
License:Apache License
@Nullable private AddModuleWizard selectFileAndCreateWizard(@NotNull FileChooserDescriptor descriptor) throws IOException, ConfigurationException { FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null); VirtualFile toSelect = null;//from w w w. j a va 2s.c om String lastLocation = PropertiesComponent.getInstance().getValue(LAST_IMPORTED_LOCATION); if (lastLocation != null) { toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(lastLocation); } VirtualFile[] files = chooser.choose(null, toSelect); if (files.length == 0) { return null; } VirtualFile file = files[0]; PropertiesComponent.getInstance().setValue(LAST_IMPORTED_LOCATION, file.getPath()); return createImportWizard(file); }
From source file:com.android.tools.idea.wizard.GetSdkStep.java
License:Apache License
@Nullable private String getSdkPath(@Nullable String currentPath) { VirtualFile currentFile = null;//from w w w . ja va 2 s . c o m if (currentPath != null && !currentPath.isEmpty()) { currentFile = VfsUtil.findFileByIoFile(new File(currentPath), false); } FileChooserDescriptor chooserDescriptor = AndroidSdkType.getInstance().getHomeChooserDescriptor(); FileChooserDialog chooser = new FileChooserDialogImpl(chooserDescriptor, (Project) null); VirtualFile[] files = chooser.choose(null, currentFile); if (files.length == 0) { return null; } else { return files[0].getPath(); } }
From source file:com.goide.configuration.GoLibrariesConfigurable.java
License:Apache License
public GoLibrariesConfigurable(@NotNull String displayName, @NotNull GoLibrariesService librariesService, String... urls) {// w ww.j av a 2s . co m myDisplayName = displayName; myLibrariesService = librariesService; myReadOnlyPaths = urls; final JBList filesList = new JBList(myListModel); filesList.setCellRenderer(new ColoredListCellRenderer() { @Override protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) { ListItem item = (ListItem) value; String url = item.url; if (item.readOnly) { append("[GOPATH] ", SimpleTextAttributes.GRAY_ATTRIBUTES); } VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url); if (file != null) { append(file.getPresentableUrl(), item.readOnly ? SimpleTextAttributes.GRAY_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES); setIcon(IconUtil.getIcon(file, Iconable.ICON_FLAG_READ_STATUS, null)); } else { append(VfsUtilCore.urlToPath(url), SimpleTextAttributes.ERROR_ATTRIBUTES); } } }); ToolbarDecorator decorator = ToolbarDecorator.createDecorator(filesList) .setAddAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { FileChooserDialog fileChooser = FileChooserFactory.getInstance() .createFileChooser(createMultipleFoldersDescriptor(), null, filesList); VirtualFile fileToSelect = null; ListItem lastItem = ContainerUtil.getLastItem(myListModel.getItems()); if (lastItem != null) { fileToSelect = VirtualFileManager.getInstance().findFileByUrl(lastItem.url); } VirtualFile[] newDirectories = fileChooser.choose(null, fileToSelect); if (newDirectories.length > 0) { for (VirtualFile newDirectory : newDirectories) { String newDirectoryUrl = newDirectory.getUrl(); boolean alreadyAdded = false; for (ListItem item : myListModel.getItems()) { if (newDirectoryUrl.equals(item.url) && !item.readOnly) { filesList.clearSelection(); filesList.setSelectedValue(item, true); scrollToSelection(filesList); alreadyAdded = true; break; } } if (!alreadyAdded) { myListModel.add(new ListItem(newDirectoryUrl, false)); } } } } }).setRemoveActionUpdater(new AnActionButtonUpdater() { @Override public boolean isEnabled(AnActionEvent event) { for (Object selectedValue : filesList.getSelectedValues()) { if (((ListItem) selectedValue).readOnly) { return false; } } return true; } }).setRemoveAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { for (Object selectedValue : filesList.getSelectedValues()) { myListModel.remove((ListItem) selectedValue); } } }); myPanel.add(decorator.createPanel(), BorderLayout.CENTER); if (librariesService instanceof GoApplicationLibrariesService) { myUseEnvGoPathCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(@NotNull ActionEvent event) { if (myUseEnvGoPathCheckBox.isSelected()) { addReadOnlyPaths(); } else { removeReadOnlyPaths(); } } }); myPanel.add(myUseEnvGoPathCheckBox, BorderLayout.SOUTH); } }
From source file:com.google.idea.blaze.base.run.exporter.ExportRunConfigurationDialog.java
License:Open Source License
private void chooseDirectory() { FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor() .withTitle("Export Directory Location") .withDescription("Choose directory to export run configurations to").withHideIgnored(false); FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null); final VirtualFile[] files; File existingLocation = new File(getOutputDirectoryPath()); if (existingLocation.exists()) { VirtualFile toSelect = LocalFileSystem.getInstance() .refreshAndFindFileByPath(existingLocation.getPath()); files = chooser.choose(null, toSelect); } else {//from www . ja v a 2 s.co m files = chooser.choose(null); } if (files.length == 0) { return; } VirtualFile file = files[0]; outputDirectoryPanel.setText(file.getPath()); }
From source file:com.google.idea.blaze.base.wizard.BlazeImportFileChooser.java
License:Open Source License
@Nullable public static VirtualFile getFileToImport() { FileChooserDescriptor descriptor = createFileChooserDescriptor(); FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null); VirtualFile toSelect = null;//from ww w .j a va2s . c om String lastLocation = PropertiesComponent.getInstance().getValue(LAST_IMPORTED_LOCATION); if (lastLocation != null) { toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(lastLocation); } VirtualFile[] files = chooser.choose(null, toSelect); if (files.length == 0) { return null; } VirtualFile file = files[0]; PropertiesComponent.getInstance().setValue(LAST_IMPORTED_LOCATION, file.getPath()); return file; }
From source file:com.google.idea.blaze.base.wizard2.CopyExternalProjectViewOption.java
License:Open Source License
private void chooseWorkspacePath() { FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) .withShowHiddenFiles(true) // Show root project view file .withHideIgnored(false).withTitle("Select Project View File") .withDescription("Select a project view file to import.") .withFileFilter(virtualFile -> ProjectViewStorageManager .isProjectViewFile(new File(virtualFile.getPath()))); FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null); File startingLocation = null; String projectViewPath = getProjectViewPath(); if (!projectViewPath.isEmpty()) { File fileLocation = new File(projectViewPath); if (fileLocation.exists()) { startingLocation = fileLocation; }//from w ww .j av a 2 s. c om } final VirtualFile[] files; if (startingLocation != null) { VirtualFile toSelect = LocalFileSystem.getInstance() .refreshAndFindFileByPath(startingLocation.getPath()); files = chooser.choose(null, toSelect); } else { files = chooser.choose(null); } if (files.length == 0) { return; } VirtualFile file = files[0]; projectViewPathField.setText(file.getPath()); }
From source file:com.google.idea.blaze.base.wizard2.GenerateFromBuildFileSelectProjectViewOption.java
License:Open Source License
private void chooseWorkspacePath() { BuildSystemProvider buildSystem = BuildSystemProvider.getBuildSystemProvider(builder.getBuildSystem()); FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) .withShowHiddenFiles(true) // Show root project view file .withHideIgnored(false).withTitle("Select BUILD File") .withDescription("Select a BUILD file to synthesize a project view from.") .withFileFilter(virtualFile -> buildSystem.isBuildFile(virtualFile.getName())); FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null); WorkspacePathResolver workspacePathResolver = builder.getWorkspaceOption().getWorkspacePathResolver(); File fileBrowserRoot = builder.getWorkspaceOption().getFileBrowserRoot(); File startingLocation = fileBrowserRoot; String buildFilePath = getBuildFilePath(); if (!buildFilePath.isEmpty() && WorkspacePath.validate(buildFilePath)) { // If the user has typed part of the path then clicked the '...', try to start from the // partial state buildFilePath = StringUtil.trimEnd(buildFilePath, '/'); if (WorkspacePath.validate(buildFilePath)) { File fileLocation = workspacePathResolver.resolveToFile(new WorkspacePath(buildFilePath)); if (fileLocation.exists() && FileUtil.isAncestor(fileBrowserRoot, fileLocation, true)) { startingLocation = fileLocation; }//from ww w . j av a 2s .c o m } } VirtualFile toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(startingLocation.getPath()); VirtualFile[] files = chooser.choose(null, toSelect); if (files.length == 0) { return; } VirtualFile file = files[0]; String newWorkspacePath = FileUtil.getRelativePath(fileBrowserRoot, new File(file.getPath())); buildFilePathField.setText(newWorkspacePath); }
From source file:com.google.idea.blaze.base.wizard2.ImportFromWorkspaceProjectViewOption.java
License:Open Source License
private void chooseWorkspacePath() { FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) .withShowHiddenFiles(true) // Show root project view file .withHideIgnored(false).withTitle("Select Project View File") .withDescription("Select a project view file to import.") .withFileFilter(virtualFile -> ProjectViewStorageManager .isProjectViewFile(new File(virtualFile.getPath()))); FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null); WorkspacePathResolver workspacePathResolver = builder.getWorkspaceOption().getWorkspacePathResolver(); File fileBrowserRoot = builder.getWorkspaceOption().getFileBrowserRoot(); File startingLocation = fileBrowserRoot; String projectViewPath = getProjectViewPath(); if (!projectViewPath.isEmpty()) { // If the user has typed part of the path then clicked the '...', try to start from the // partial state projectViewPath = StringUtil.trimEnd(projectViewPath, '/'); if (WorkspacePath.validate(projectViewPath)) { File fileLocation = workspacePathResolver.resolveToFile(new WorkspacePath(projectViewPath)); if (fileLocation.exists() && FileUtil.isAncestor(fileBrowserRoot, fileLocation, true)) { startingLocation = fileLocation; }/*from ww w . jav a2s . c o m*/ } } VirtualFile toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(startingLocation.getPath()); VirtualFile[] files = chooser.choose(null, toSelect); if (files.length == 0) { return; } VirtualFile file = files[0]; if (!FileUtil.isAncestor(fileBrowserRoot.getPath(), file.getPath(), true)) { Messages.showErrorDialog(String.format( "You must choose a project view file under %s. " + "To use an external project view, please use the 'Copy external' option.", fileBrowserRoot.getPath()), "Cannot Use Project View File"); return; } String newWorkspacePath = FileUtil.getRelativePath(fileBrowserRoot, new File(file.getPath())); projectViewPathField.setText(newWorkspacePath); }
From source file:com.google.idea.blaze.base.wizard2.UseExistingBazelWorkspaceOption.java
License:Open Source License
private void chooseDirectory() { FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false) { @Override/* w w w .ja v a2 s .co m*/ public boolean isFileSelectable(VirtualFile file) { // Default implementation doesn't filter directories, // we want to make sure only workspace roots are selectable return super.isFileSelectable(file) && isWorkspaceRoot(file); } }.withHideIgnored(false).withTitle("Select Workspace Root") .withDescription("Select the directory of the workspace you want to use.") .withFileFilter(UseExistingBazelWorkspaceOption::isWorkspaceRoot); FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null); final VirtualFile[] files; File existingLocation = new File(getDirectory()); if (existingLocation.exists()) { VirtualFile toSelect = LocalFileSystem.getInstance() .refreshAndFindFileByPath(existingLocation.getPath()); files = chooser.choose(null, toSelect); } else { files = chooser.choose(null); } if (files.length == 0) { return; } VirtualFile file = files[0]; directoryField.setText(file.getPath()); }
From source file:com.google.idea.blaze.base.wizard2.UseExistingWorkspaceOption.java
License:Open Source License
private void chooseDirectory() { FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false) { @Override/*from w w w . j a v a2s.co m*/ public boolean isFileSelectable(VirtualFile file) { // Default implementation doesn't filter directories, we want to make sure only workspace roots are selectable return super.isFileSelectable(file) && isWorkspaceRoot(file); } @Override public Icon getIcon(VirtualFile file) { if (buildSystem == BuildSystem.Bazel) { // isWorkspaceRoot requires file system calls -- it's too expensive return super.getIcon(file); } if (isWorkspaceRoot(file)) { return AllIcons.Nodes.SourceFolder; } return super.getIcon(file); } }.withHideIgnored(false).withTitle("Select Workspace Root").withDescription(fileChooserDescription()) .withFileFilter(this::isWorkspaceRoot); FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null); final VirtualFile[] files; File existingLocation = new File(getDirectory()); if (existingLocation.exists()) { VirtualFile toSelect = LocalFileSystem.getInstance() .refreshAndFindFileByPath(existingLocation.getPath()); files = chooser.choose(null, toSelect); } else { files = chooser.choose(null); } if (files.length == 0) { return; } VirtualFile file = files[0]; directoryField.setText(file.getPath()); }