From acfedcab649f4a5031eb902e9b6916cf3ef58c3e Mon Sep 17 00:00:00 2001 From: Anton Lobov Date: Fri, 27 Jul 2018 12:46:20 +0200 Subject: [PATCH] WEB-34093 JSON Schema: improve the status for not yet downloaded schemas + fix rewriting urls when file extension is already provided --- .../jsonSchema/remote/JsonFileResolver.java | 3 +- .../widget/JsonSchemaStatusWidget.java | 38 +++++++++++-------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/json/src/com/jetbrains/jsonSchema/remote/JsonFileResolver.java b/json/src/com/jetbrains/jsonSchema/remote/JsonFileResolver.java index 013d2ad1276d..76cbff166919 100644 --- a/json/src/com/jetbrains/jsonSchema/remote/JsonFileResolver.java +++ b/json/src/com/jetbrains/jsonSchema/remote/JsonFileResolver.java @@ -40,7 +40,8 @@ public class JsonFileResolver { return JsonSchemaCatalogManager.DEFAULT_CATALOG_HTTPS; } if (StringUtil.startsWithIgnoreCase(urlString, JsonSchemaRemoteContentProvider.STORE_URL_PREFIX_HTTP)) { - return StringUtil.replace(urlString, "http://json.schemastore.org/", "https://schemastore.azurewebsites.net/schemas/json/") + ".json"; + String newUrl = StringUtil.replace(urlString, "http://json.schemastore.org/", "https://schemastore.azurewebsites.net/schemas/json/"); + return newUrl.endsWith(".json") ? newUrl : newUrl + ".json"; } return urlString; } diff --git a/json/src/com/jetbrains/jsonSchema/widget/JsonSchemaStatusWidget.java b/json/src/com/jetbrains/jsonSchema/widget/JsonSchemaStatusWidget.java index 343d109069a2..85e528ee87b4 100644 --- a/json/src/com/jetbrains/jsonSchema/widget/JsonSchemaStatusWidget.java +++ b/json/src/com/jetbrains/jsonSchema/widget/JsonSchemaStatusWidget.java @@ -126,23 +126,10 @@ class JsonSchemaStatusWidget extends EditorBasedStatusBarPopup { //noinspection EnumSwitchStatementWhichMissesCases switch (info.getState()) { case DOWNLOADING_NOT_STARTED: + addDownloadingUpdateListener(info); + return getNoSchemaState(); case DOWNLOADING_IN_PROGRESS: - info.addDownloadingListener(new FileDownloadingAdapter() { - @Override - public void fileDownloaded(VirtualFile localFile) { - update(); - } - - @Override - public void errorOccurred(@NotNull String errorMessage) { - update(); - } - - @Override - public void downloadingCancelled() { - update(); - } - }); + addDownloadingUpdateListener(info); return new MyWidgetState("Download is scheduled or in progress", "Downloading JSON schema", false); case ERROR_OCCURRED: return getDownloadErrorState(info.getErrorMessage()); @@ -171,6 +158,25 @@ class JsonSchemaStatusWidget extends EditorBasedStatusBarPopup { true); } + private void addDownloadingUpdateListener(@NotNull RemoteFileInfo info) { + info.addDownloadingListener(new FileDownloadingAdapter() { + @Override + public void fileDownloaded(VirtualFile localFile) { + update(); + } + + @Override + public void errorOccurred(@NotNull String errorMessage) { + update(); + } + + @Override + public void downloadingCancelled() { + update(); + } + }); + } + private boolean isValidSchemaFile(VirtualFile schemaFile) { if (schemaFile == null || !myService.isApplicableToFile(schemaFile) || !myService.isSchemaFile(schemaFile)) return false; FileType type = schemaFile.getFileType();