List of usage examples for com.intellij.openapi.fileChooser FileChooser chooseFile
@Nullable public static VirtualFile chooseFile(@NotNull final FileChooserDescriptor descriptor, @Nullable final Project project, @Nullable final VirtualFile toSelect)
From source file:com.android.tools.idea.apk.viewer.AnalyzeApkAction.java
License:Apache License
@Nullable private static VirtualFile promptUserForApk(Project project) { FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor() .withDescription("Select APK to analyze") .withFileFilter(file -> ApkFileSystem.EXTENSIONS.contains(file.getExtension())); VirtualFile apk = FileChooser.chooseFile(descriptor, project, getLastSelectedApk(project)); if (apk != null) { saveLastSelectedApk(project, apk); }/*from w ww .jav a 2s . c o m*/ return apk; }
From source file:com.android.tools.idea.apk.viewer.ApkEditor.java
License:Apache License
@Override public void selectApkAndCompare() { FileChooserDescriptor desc = new FileChooserDescriptor(true, false, false, false, false, false); desc.withFileFilter(file -> ApkFileSystem.EXTENSIONS.contains(file.getExtension())); VirtualFile file = FileChooser.chooseFile(desc, myProject, null); if (file == null) { // user canceled return;//from w w w .j ava2 s . c o m } VirtualFile newApk = ApkFileSystem.getInstance().getRootByLocal(file); assert newApk != null; DialogBuilder builder = new DialogBuilder(myProject); builder.setTitle(myRoot.getName() + " vs " + newApk.getName()); ApkDiffParser parser = new ApkDiffParser(myRoot, newApk); ApkDiffPanel panel = new ApkDiffPanel(parser); builder.setCenterPanel(panel.getContainer()); builder.setPreferredFocusComponent(panel.getPreferredFocusedComponent()); builder.show(); }
From source file:com.android.tools.idea.gradle.structure.DefaultSdksConfigurable.java
License:Apache License
private void createSdkLocationTextField() { final FileChooserDescriptor descriptor = createSingleFolderDescriptor("Choose Android SDK Location", new Function<File, Void>() { @Override// ww w .j a v a 2s. c om public Void fun(File file) { if (!DefaultSdks.isValidAndroidSdkPath(file)) { throw new IllegalArgumentException(CHOOSE_VALID_SDK_DIRECTORY_ERR); } return null; } }); JTextField textField = new JTextField(10); mySdkLocationTextField = new TextFieldWithBrowseButton(textField, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { VirtualFile suggestedDir = null; File sdkLocation = getSdkLocation(); if (sdkLocation.isDirectory()) { suggestedDir = VfsUtil.findFileByIoFile(sdkLocation, false); } VirtualFile chosen = FileChooser.chooseFile(descriptor, null, suggestedDir); if (chosen != null) { File f = VfsUtilCore.virtualToIoFile(chosen); mySdkLocationTextField.setText(f.getPath()); } } }); installValidationListener(textField); }
From source file:com.android.tools.idea.gradle.structure.DefaultSdksConfigurable.java
License:Apache License
private void createJdkLocationTextField() { final FileChooserDescriptor descriptor = createSingleFolderDescriptor("Choose JDK Location", new Function<File, Void>() { @Override/* www. j a v a2 s . c o m*/ public Void fun(File file) { if (!JavaSdk.checkForJdk(file)) { throw new IllegalArgumentException(CHOOSE_VALID_JDK_DIRECTORY_ERR); } return null; } }); JTextField textField = new JTextField(10); myJdkLocationTextField = new TextFieldWithBrowseButton(textField, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { VirtualFile suggestedDir = null; File jdkLocation = getJdkLocation(); if (jdkLocation.isDirectory()) { suggestedDir = VfsUtil.findFileByIoFile(jdkLocation, false); } VirtualFile chosen = FileChooser.chooseFile(descriptor, null, suggestedDir); if (chosen != null) { File f = VfsUtilCore.virtualToIoFile(chosen); myJdkLocationTextField.setText(f.getPath()); } } }); installValidationListener(textField); }
From source file:com.android.tools.idea.gradle.structure.editors.ModuleDependenciesPanel.java
License:Apache License
private void addFileDependency() { FileChooserDescriptor descriptor = new FileChooserDescriptor(false, false, true, true, false, false); VirtualFile buildFile = myGradleBuildFile.getFile(); VirtualFile parent = buildFile.getParent(); descriptor.setRoots(parent);/*from ww w . ja v a 2 s .c om*/ VirtualFile virtualFile = FileChooser.chooseFile(descriptor, myProject, null); if (virtualFile != null) { String path = VfsUtilCore.getRelativePath(virtualFile, parent, '/'); if (path == null) { path = virtualFile.getPath(); } myModel.addItem(new ModuleDependenciesTableItem( new Dependency(Dependency.Scope.COMPILE, Dependency.Type.FILES, path))); } myModel.fireTableDataChanged(); }
From source file:com.android.tools.idea.structure.DefaultSdksConfigurable.java
License:Apache License
private TextFieldWithBrowseButton createTextFieldWithBrowseButton(String title, final String errorMessagae, final Function<File, ValidationResult> validation) { final FileChooserDescriptor descriptor = createSingleFolderDescriptor(title, new Function<File, Void>() { @Override/* ww w . j a v a 2 s . c om*/ public Void fun(File file) { ValidationResult validationResult = validation.fun(file); if (!validationResult.success) { String msg = validationResult.message; if (isEmpty(msg)) { msg = errorMessagae; } throw new IllegalArgumentException(msg); } return null; } }); final JTextField textField = new JTextField(10); installValidationListener(textField); return new TextFieldWithBrowseButton(textField, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { VirtualFile suggestedDir = null; File ndkLocation = getNdkLocation(); if (ndkLocation.isDirectory()) { suggestedDir = findFileByIoFile(ndkLocation, false); } VirtualFile chosen = FileChooser.chooseFile(descriptor, null, suggestedDir); if (chosen != null) { File f = virtualToIoFile(chosen); textField.setText(f.getPath()); } } }); }
From source file:com.android.tools.idea.structure.DefaultSdksConfigurable.java
License:Apache License
public void chooseJdkLocation() { myJdkLocationTextField.getTextField().requestFocus(); VirtualFile suggestedDir = null;//from w ww. j av a 2 s .c om File jdkLocation = getJdkLocation(); if (jdkLocation.isDirectory()) { suggestedDir = findFileByIoFile(jdkLocation, false); } VirtualFile chosen = FileChooser .chooseFile(createSingleFolderDescriptor("Choose JDK Location", new Function<File, Void>() { @Override public Void fun(File file) { if (!validateAndUpdateJdkPath(file)) { throw new IllegalArgumentException(CHOOSE_VALID_JDK_DIRECTORY_ERR); } return null; } }), null, suggestedDir); if (chosen != null) { File f = virtualToIoFile(chosen); myJdkLocationTextField.setText(f.getPath()); } }
From source file:com.intellij.codeInsight.ExternalAnnotationsManagerImpl.java
License:Apache License
private void setupRootAndAnnotateExternally(@NotNull final OrderEntry entry, @NotNull final Project project, @NotNull final PsiModifierListOwner listOwner, @NotNull final String annotationFQName, @NotNull final PsiFile fromFile, @NotNull final String packageName, @Nullable final PsiNameValuePair[] value) { final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); descriptor.setTitle(// w ww. j a va 2 s .co m ProjectBundle.message("external.annotations.root.chooser.title", entry.getPresentableName())); descriptor.setDescription(ProjectBundle.message("external.annotations.root.chooser.description")); final VirtualFile newRoot = FileChooser.chooseFile(descriptor, project, null); if (newRoot == null) { notifyAfterAnnotationChanging(listOwner, annotationFQName, false); return; } new WriteCommandAction(project) { @Override protected void run(final Result result) throws Throwable { appendChosenAnnotationsRoot(entry, newRoot); XmlFile xmlFileInRoot = findXmlFileInRoot(findExternalAnnotationsXmlFiles(listOwner), newRoot); if (xmlFileInRoot != null) { //file already exists under appeared content root if (!FileModificationService.getInstance().preparePsiElementForWrite(xmlFileInRoot)) { notifyAfterAnnotationChanging(listOwner, annotationFQName, false); return; } annotateExternally(listOwner, annotationFQName, xmlFileInRoot, fromFile, value); } else { final XmlFile annotationsXml = createAnnotationsXml(newRoot, packageName); if (annotationsXml != null) { List<PsiFile> createdFiles = new SmartList<PsiFile>(annotationsXml); cacheExternalAnnotations(packageName, fromFile, createdFiles); } annotateExternally(listOwner, annotationFQName, annotationsXml, fromFile, value); } } }.execute(); }
From source file:com.intellij.codeInspection.actions.ViewOfflineResultsAction.java
License:Apache License
@Override public void actionPerformed(AnActionEvent event) { final Project project = event.getData(CommonDataKeys.PROJECT); LOG.assertTrue(project != null);/*from ww w . jav a 2s . c om*/ final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false) { @Override public Icon getIcon(VirtualFile file) { if (file.isDirectory()) { if (file.findChild(InspectionApplication.DESCRIPTIONS + "." + InternalStdFileTypes.XML.getDefaultExtension()) != null) { return AllIcons.Nodes.InspectionResults; } } return super.getIcon(file); } }; descriptor.setTitle("Select Path"); descriptor.setDescription("Select directory which contains exported inspections results"); final VirtualFile virtualFile = FileChooser.chooseFile(descriptor, project, null); if (virtualFile == null || !virtualFile.isDirectory()) return; final Map<String, Map<String, Set<OfflineProblemDescriptor>>> resMap = new HashMap<String, Map<String, Set<OfflineProblemDescriptor>>>(); final String[] profileName = new String[1]; final Runnable process = new Runnable() { @Override public void run() { final VirtualFile[] files = virtualFile.getChildren(); try { for (final VirtualFile inspectionFile : files) { if (inspectionFile.isDirectory()) continue; final String shortName = inspectionFile.getNameWithoutExtension(); final String extension = inspectionFile.getExtension(); if (shortName.equals(InspectionApplication.DESCRIPTIONS)) { profileName[0] = ApplicationManager.getApplication() .runReadAction(new Computable<String>() { @Override @Nullable public String compute() { return OfflineViewParseUtil.parseProfileName( LoadTextUtil.loadText(inspectionFile).toString()); } }); } else if (XML_EXTENSION.equals(extension)) { resMap.put(shortName, ApplicationManager.getApplication() .runReadAction(new Computable<Map<String, Set<OfflineProblemDescriptor>>>() { @Override public Map<String, Set<OfflineProblemDescriptor>> compute() { return OfflineViewParseUtil .parse(LoadTextUtil.loadText(inspectionFile).toString()); } })); } } } catch (final Exception e) { //all parse exceptions SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Messages.showInfoMessage(e.getMessage(), InspectionsBundle.message("offline.view.parse.exception.title")); } }); throw new ProcessCanceledException(); //cancel process } } }; ProgressManager.getInstance().runProcessWithProgressAsynchronously(project, InspectionsBundle.message("parsing.inspections.dump.progress.title"), process, new Runnable() { @Override public void run() { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { final String name = profileName[0]; showOfflineView(project, name, resMap, InspectionsBundle.message("offline.view.title") + " (" + (name != null ? name : InspectionsBundle .message("offline.view.editor.settings.title")) + ")"); } }); } }, null, new PerformAnalysisInBackgroundOption(project)); }
From source file:com.intellij.diff.actions.CompareFilesAction.java
License:Apache License
@Nullable private static VirtualFile getOtherFile(@Nullable Project project, @NotNull VirtualFile file) { FileChooserDescriptor descriptor;/*from w ww . j a va 2 s . co m*/ String key; Type type = getType(file); if (type == Type.DIRECTORY || type == Type.ARCHIVE) { descriptor = new FileChooserDescriptor(false, true, true, false, false, false); key = LAST_USED_FOLDER_KEY; } else { descriptor = new FileChooserDescriptor(true, false, false, true, true, false); key = LAST_USED_FILE_KEY; } VirtualFile selectedFile = getDefaultSelection(project, key, file); VirtualFile otherFile = FileChooser.chooseFile(descriptor, project, selectedFile); if (otherFile != null) updateDefaultSelection(project, key, otherFile); return otherFile; }