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

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

下载文件到本地

DownloadableFileService fileService = DownloadableFileService.getInstance();

        String filename = FilenameUtils.getName(URL);
        DownloadableFileDescription fileDescription = fileService.createFileDescription(URL, filename);
        List 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);
                }

            }});
进度条自定义

你可能感兴趣的:(IDEA 插件开发-下载原生进度条)