本文整理汇总了Java中com.intellij.openapi.fileChooser.FileChooser类的典型用法代码示例。如果您正苦于以下问题:Java FileChooser类的具体用法?Java FileChooser怎么用?Java FileChooser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileChooser类属于com.intellij.openapi.fileChooser包,在下文中一共展示了FileChooser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unpackCourseArchive
import com.intellij.openapi.fileChooser.FileChooser; //导入依赖的package包/类
private static void unpackCourseArchive(final Project project) {
FileChooserDescriptor descriptor =
new FileChooserDescriptor(true, true, true, true, true, false);
final VirtualFile virtualFile = FileChooser.chooseFile(descriptor, project, null);
if (virtualFile == null) {
return;
}
final String basePath = project.getBasePath();
if (basePath == null) return;
Course course = StudyProjectGenerator.getCourse(virtualFile.getPath());
if (course == null) {
Messages.showErrorDialog("This course is incompatible with current version", "Failed to Unpack Course");
return;
}
generateFromStudentCourse(project, course);
}
示例2: createDirectory
import com.intellij.openapi.fileChooser.FileChooser; //导入依赖的package包/类
public static PsiDirectory createDirectory(Project project, String title, String description) {
final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
descriptor.setTitle(title);
descriptor.setShowFileSystemRoots(false);
descriptor.setDescription(description);
descriptor.setHideIgnored(true);
descriptor.setRoots(project.getBaseDir());
descriptor.setForcedToUseIdeaFileChooser(true);
VirtualFile file = FileChooser.chooseFile(descriptor, project, project.getBaseDir());
if(Objects.isNull(file)){
Messages.showInfoMessage("Cancel " + title, "Error");
return null;
}
PsiDirectory psiDirectory = PsiDirectoryFactory.getInstance(project).createDirectory(file);
if(PsiDirectoryFactory.getInstance(project).isPackage(psiDirectory)){
return psiDirectory;
}else {
Messages.showInfoMessage("请选择正确的 package 路径。", "Error");
return createDirectory(project, title, description);
}
}
示例3: selectSdk
import com.intellij.openapi.fileChooser.FileChooser; //导入依赖的package包/类
@Nullable public static MuleSdk selectSdk(@NotNull JComponent parentComponent)
{
final VirtualFile initial = findFile(System.getenv("MULE_HOME"));
final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false)
{
@Override
public boolean isFileSelectable(VirtualFile file)
{
return super.isFileSelectable(file) && MuleSdk.isValidMuleHome(file.getCanonicalPath());
}
};
descriptor.setTitle("Mule SDK");
descriptor.setDescription("Choose a directory containing Mule distribution");
final VirtualFile dir = FileChooser.chooseFile(descriptor, parentComponent, null, initial);
if (dir == null || !MuleSdk.isValidMuleHome(dir.getCanonicalPath()))
{
return null;
}
return new MuleSdk(dir.getCanonicalPath());
}
示例4: actionPerformed
import com.intellij.openapi.fileChooser.FileChooser; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
logger.debug("Loading sample!");
final Project project = anActionEvent.getProject();
final PsiFile psiFile = anActionEvent.getData(CommonDataKeys.PSI_FILE);
VirtualFile sample = FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(),
project, null);
if (sample == null)
return;
try {
final String text = new String(sample.contentsToByteArray(), sample.getCharset());
new WriteCommandAction.Simple(project, psiFile) {
@Override
protected void run() throws Throwable {
document.setText(text);
}
}.execute();
} catch (Exception e) {
logger.error(e);
}
}
示例5: onExportAction
import com.intellij.openapi.fileChooser.FileChooser; //导入依赖的package包/类
@Override
public void onExportAction(String path) {
VirtualFile[] files = FileChooser.chooseFiles(FileReaderUtil.getDirectoryDescriptor(), project,
null);
//todo remove
// LocalFileSystem.getInstance().findFileByIoFile(new File("E:" + File.separator + "Downloads")));
if (files.length <= 0) {
return;
}
PackageTemplate pt = PackageTemplateHelper.getPackageTemplate(path);
VirtualFile directoryToExport = files[0];
PackageTemplateHelper.exportPackageTemplate(project, pt, directoryToExport.getPath());
}
示例6: specifyADBPath
import com.intellij.openapi.fileChooser.FileChooser; //导入依赖的package包/类
private void specifyADBPath() {
final String adbPath = Global.instance().adbPath();
final VirtualFile toSelect;
if (Utils.isBlank(adbPath)) {
toSelect = null;
} else {
toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(adbPath);
}
final VirtualFile vFile = FileChooser.chooseFile(
FileChooserDescriptorFactory.createSingleFileOrFolderDescriptor(), Global.instance().project(), toSelect);
if (vFile == null || !vFile.exists()) {
return;
}
mPresenter.chooseADBPath(vFile);
}
示例7: actionPerformed
import com.intellij.openapi.fileChooser.FileChooser; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent event) {
final Project project = event.getProject();
if (project == null) {
return;
}
FileChooserDescriptor chooserDescriptor = new FileChooserDescriptor(true, false, true, false, false, false);
VirtualFile virtualFile = FileChooser.chooseFile(chooserDescriptor, project, null);
if (virtualFile != null && virtualFile.isValid() && !virtualFile.isDirectory()) {
DeltaHexVirtualFile deltaHexVirtualFile = new DeltaHexVirtualFile(virtualFile);
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, deltaHexVirtualFile, 0);
FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
List<FileEditor> editors = fileEditorManager.openEditor(descriptor, true);
fileEditorManager.setSelectedEditor(virtualFile, DeltaHexWindowProvider.DELTAHEX_EDITOR_TYPE_ID);
for (FileEditor fileEditor : editors) {
if (fileEditor instanceof DeltaHexFileEditor) {
((DeltaHexFileEditor) fileEditor).openFile(deltaHexVirtualFile);
}
}
}
}
示例8: createLogFileChooser
import com.intellij.openapi.fileChooser.FileChooser; //导入依赖的package包/类
private void createLogFileChooser() {
myLogFile = new TextFieldWithHistory();
JPanel panel = GuiUtils.constructFieldWithBrowseButton(myLogFile, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor();
FileChooser.chooseFiles(descriptor, myProject, null, new Consumer<List<VirtualFile>>() {
@Override
public void consume(List<VirtualFile> files) {
myLogFile.setText(FileUtil.toSystemDependentName(files.get(files.size() - 1).getPath()));
}
});
}
});
myLogFileChooserPanel.setLayout(new BorderLayout());
myLogFileChooserPanel.add(panel, BorderLayout.CENTER);
}
示例9: downloadJar
import com.intellij.openapi.fileChooser.FileChooser; //导入依赖的package包/类
private void downloadJar(String jarUrl, String jarName) {
final Project project = myModule.getProject();
final String dirPath = PropertiesComponent.getInstance(project).getValue("findjar.last.used.dir");
VirtualFile toSelect = dirPath == null ? null : LocalFileSystem.getInstance().findFileByIoFile(new File(dirPath));
final VirtualFile file = FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFolderDescriptor(), project, toSelect);
if (file != null) {
PropertiesComponent.getInstance(project).setValue("findjar.last.used.dir", file.getPath());
final DownloadableFileService downloader = DownloadableFileService.getInstance();
final DownloadableFileDescription description = downloader.createFileDescription(jarUrl, jarName);
final List<VirtualFile> jars =
downloader.createDownloader(Arrays.asList(description), jarName)
.downloadFilesWithProgress(file.getPath(), project, myEditorComponent);
if (jars != null && jars.size() == 1) {
AccessToken token = WriteAction.start();
try {
OrderEntryFix.addJarToRoots(jars.get(0).getPresentableUrl(), myModule, myRef);
}
finally {
token.finish();
}
}
}
}
示例10: createNewLibrary
import com.intellij.openapi.fileChooser.FileChooser; //导入依赖的package包/类
@Override
public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, VirtualFile contextDirectory) {
final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, false, true, false, false, true);
descriptor.setTitle(IdeBundle.message("new.library.file.chooser.title"));
descriptor.setDescription(IdeBundle.message("new.library.file.chooser.description"));
final VirtualFile[] files = FileChooser.chooseFiles(descriptor, parentComponent, null, contextDirectory);
if (files.length == 0) {
return null;
}
return new NewLibraryConfiguration(myDefaultLibraryName, getDownloadableLibraryType(), new LibraryVersionProperties()) {
@Override
public void addRoots(@NotNull LibraryEditor editor) {
for (VirtualFile file : files) {
editor.addRoot(file, OrderRootType.CLASSES);
}
}
};
}
示例11: constructFileURLBrowserField
import com.intellij.openapi.fileChooser.FileChooser; //导入依赖的package包/类
public static JPanel constructFileURLBrowserField(final TextFieldWithHistory field, final String objectName) {
return constructFieldWithBrowseButton(field, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
FileChooserDescriptor descriptor =
FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor().withTitle("Select " + objectName);
VirtualFile file = FileChooser.chooseFile(descriptor, field, null, null);
if (file != null) {
try {
field.setText(VfsUtilCore.virtualToIoFile(file).toURI().toURL().toString());
}
catch (MalformedURLException e1) {
field.setText("");
}
}
}
});
}
示例12: actionPerformed
import com.intellij.openapi.fileChooser.FileChooser; //导入依赖的package包/类
public void actionPerformed(AnActionEvent e) {
String selectedText = myTextField.getSelectedText();
VirtualFile virtualFile;
if (selectedText != null ) {
virtualFile = LocalFileSystem.getInstance().findFileByPath(selectedText.replace(File.separatorChar, '/'));
}
else {
virtualFile = null;
}
//TODO use from openapi
//FeatureUsageTracker.getInstance().triggerFeatureUsed("ui.commandLine.insertPath");
VirtualFile[] files = FileChooser.chooseFiles(myDescriptor, myTextField, getEventProject(e), virtualFile);
if (files.length != 0) {
myTextField.replaceSelection(files[0].getPresentableUrl());
}
}
示例13: createActionListener
import com.intellij.openapi.fileChooser.FileChooser; //导入依赖的package包/类
protected ActionListener createActionListener(final JTable table) {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String initial = (String)getCellEditorValue();
VirtualFile initialFile = StringUtil.isNotEmpty(initial) ? LocalFileSystem.getInstance().findFileByPath(initial) : null;
FileChooser.chooseFile(getFileChooserDescriptor(), myProject, table, initialFile, new Consumer<VirtualFile>() {
@Override
public void consume(VirtualFile file) {
String path = file.getPresentableUrl();
if (SystemInfo.isWindows && path.length() == 2 && Character.isLetter(path.charAt(0)) && path.charAt(1) == ':') {
path += "\\"; // make path absolute
}
myComponent.getChildComponent().setText(path);
}
});
}
};
}
示例14: actionPerformed
import com.intellij.openapi.fileChooser.FileChooser; //导入依赖的package包/类
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final Project project = e.getProject();
final boolean showFiles = project != null || PlatformProjectOpenProcessor.getInstanceIfItExists() != null;
final FileChooserDescriptor descriptor = showFiles ? new ProjectOrFileChooserDescriptor() : new ProjectOnlyFileChooserDescriptor();
descriptor.putUserData(PathChooserDialog.PREFER_LAST_OVER_EXPLICIT, showFiles);
FileChooser.chooseFiles(descriptor, project, VfsUtil.getUserHomeDir(), new Consumer<List<VirtualFile>>() {
@Override
public void consume(final List<VirtualFile> files) {
for (VirtualFile file : files) {
if (!descriptor.isFileSelectable(file)) {
String message = IdeBundle.message("error.dir.contains.no.project", file.getPresentableUrl());
Messages.showInfoMessage(project, message, IdeBundle.message("title.cannot.open.project"));
return;
}
}
doOpenFile(project, files);
}
});
}
示例15: run
import com.intellij.openapi.fileChooser.FileChooser; //导入依赖的package包/类
public void run() {
final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
VirtualFile selectedFile = FileChooser.chooseFile(descriptor, myProject, null);
if (selectedFile == null) {
return;
}
final List<AbstractFilePatchInProgress.PatchChange> selectedChanges = myChangesTreeList.getSelectedChanges();
if (selectedChanges.size() >= 1) {
for (AbstractFilePatchInProgress.PatchChange patchChange : selectedChanges) {
final AbstractFilePatchInProgress patch = patchChange.getPatchInProgress();
patch.setNewBase(selectedFile);
}
updateTree(false);
}
}