IDEA 插件开发-下载原生进度条

分享几种IDEA 插件开发时原生下载方式和进度条自定义方法。

下载文件到本地

DownloadableFileService fileService = DownloadableFileService.getInstance();

        String filename = FilenameUtils.getName(URL);
        DownloadableFileDescription fileDescription = fileService.createFileDescription(URL, filename);
        List<DownloadableFileDescription> fileDescriptions = new ArrayList<>();
        fileDescriptions.add(fileDescription);
        //同步下载,下载期间无法操作IDE
        fileService.createDownloader(fileDescriptions, "")
                .downloadFilesWithProgress(TARGET_PATH, project, null);

        //异步下载,下载期间可以操作IDE
        fileService .createDownloader(fileDescriptions, "")
                .downloadWithBackgroundProgress(TARGET_PATH, project);
异步后台下载
同步前台下载

进度条自定义

ProgressManager.getInstance().run(new Task.Backgroundable(project, "TitleKKKKK"){
            public void run(@NotNull ProgressIndicator progressIndicator) {

                // start your process

                // Set the progress bar percentage and text
                progressIndicator.setFraction(0.10);
                progressIndicator.setText("90% to finish");

                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

                // 50% done
                progressIndicator.setFraction(0.50);
                progressIndicator.setText("50% to finish");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

                // Finished
                progressIndicator.setFraction(1.0);
                progressIndicator.setText("finished");

                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            }});
进度条自定义
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容