WidgetState (@NotNull VirtualFile file, boolean isJsonFile) { JsonSchemaService service = getService(); JsonSchemaMappingsProjectConfiguration userMappingsConfiguration = JsonSchemaMappingsProjectConfiguration.getInstance(myProject); if (service == null || userMappingsConfiguration.isIgnoredFile(file)) { return getNoSchemaState(); } Collection<VirtualFile> schemaFiles = service.getSchemaFilesForFile(file); if (schemaFiles.size() == 0) { return getNoSchemaState(); } if (schemaFiles.size() != 1) { final List<VirtualFile> userSchemas = new ArrayList<>(); if (hasConflicts(userSchemas, service, file)) { MyWidgetState state = new MyWidgetState(createMessage(schemaFiles, service, "<br/>", JsonBundle.message("schema.widget.conflict.message.prefix"), ""), schemaFiles.size() + " " + JsonBundle.message("schema.widget.conflict.message.postfix"), true); state.setWarning(true); state.setConflict(); return state; } schemaFiles = userSchemas; if (schemaFiles.size() == 0) { return getNoSchemaState(); } } VirtualFile schemaFile = schemaFiles.iterator().next(); schemaFile = ((JsonSchemaServiceImpl)service).replaceHttpFileWithBuiltinIfNeeded(schemaFile); String tooltip = isJsonFile ? JsonBundle.message("schema.widget.tooltip.json.files") : JsonBundle.message("schema.widget.tooltip.other.files"); String bar = isJsonFile ? JsonBundle.message("schema.widget.prefix.json.files") : JsonBundle.message("schema.widget.prefix.other.files"); if (schemaFile instanceof HttpVirtualFile) { RemoteFileInfo info = ((HttpVirtualFile)schemaFile).getFileInfo(); if (info == null) return getDownloadErrorState(null); //noinspection EnumSwitchStatementWhichMissesCases switch (info.getState()) { case DOWNLOADING_NOT_STARTED -> { addDownloadingUpdateListener(info); return new MyWidgetState(tooltip + getSchemaFileDesc(schemaFile), bar + getPresentableNameForFile(schemaFile), true); } case DOWNLOADING_IN_PROGRESS -> { addDownloadingUpdateListener(info); return new MyWidgetState(JsonBundle.message("schema.widget.download.in.progress.tooltip"), JsonBundle.message("schema.widget.download.in.progress.label"), false); } case ERROR_OCCURRED -> { return getDownloadErrorState(info.getErrorMessage()); } } } if (!isValidSchemaFile(schemaFile)) { MyWidgetState state = new MyWidgetState(JsonBundle.message("schema.widget.error.not.a.schema"), JsonBundle.message("schema.widget.error.label"), true); state.setWarning(true); return state; } JsonSchemaFileProvider provider = service.getSchemaProvider(schemaFile); if (provider != null) { final boolean preferRemoteSchemas = JsonSchemaCatalogProjectConfiguration.getInstance(getProject()).isPreferRemoteSchemas(); final String remoteSource = provider.getRemoteSource(); boolean useRemoteSource = preferRemoteSchemas && remoteSource != null && !JsonFileResolver.isSchemaUrl(remoteSource) && !remoteSource.endsWith("!"); String providerName = useRemoteSource ? remoteSource : provider.getPresentableName(); String shortName = StringUtil.trimEnd(StringUtil.trimEnd(providerName, ".json"), "-schema"); String name = useRemoteSource ? provider.getPresentableName() : (shortName.contains(JsonBundle.message("schema.of.version", "")) ? shortName : (bar + shortName)); String kind = !useRemoteSource && (provider.getSchemaType() == SchemaType.embeddedSchema || provider.getSchemaType() == SchemaType.schema) ? JsonBundle.message("schema.widget.bundled.postfix") : ""; return new MyWidgetState(tooltip + providerName + kind, name, true); } return new MyWidgetState(tooltip + getSchemaFileDesc(schemaFile), bar + getPresentableNameForFile(schemaFile), true); }