private void populateView(RepositoryDTO repositoryDTO, Map<String, Engine> engines) { this.repositoryCache = repositoryDTO; this.enginesCache = engines; // show a waiting screen until the engines are loaded Platform.runLater(enginesView::showWait); // fetch all categories consisting of engines that are contained in the repository final List<CategoryDTO> categoryDTOS = repositoryDTO.getTypes().stream() .filter(type -> type.getId().equals("engines")) .flatMap(type -> type.getCategories().stream()) .collect(Collectors.toList()); Platform.runLater(() -> { // generate the necessary css for the engine categories setDefaultEngineIcons(categoryDTOS); }); // fetch the engine categories objects contained in the engine categories final Queue<EngineCategoryDTO> engineCategories = new ArrayDeque<>( enginesManager.getAvailableEngines(categoryDTOS)); // insert the missing engine subcategories into the engine categories fetchEngineSubcategories(engineCategories, ImmutableMap.of(), subcategoryMap -> { final List<EngineCategoryDTO> categories = subcategoryMap.entrySet().stream() .map(entry -> new EngineCategoryDTO.Builder(entry.getKey()) .withSubCategories(entry.getValue()) .build()) .collect(Collectors.toList()); Platform.runLater(() -> { // update the view enginesView.populate(categories, engines); }); }); }
/** * fetches all available engines from the repository * @param categoryDTOS engine categories from the repository * @return available engines */ public List<EngineCategoryDTO> getAvailableEngines(List<CategoryDTO> categoryDTOS) { List<EngineCategoryDTO> engines = new ArrayList<>(); for (CategoryDTO categoryDTO : categoryDTOS) { final String engineName = categoryDTO.getName(); final EngineCategoryDTO engineCategoryDTO = new EngineCategoryDTO.Builder() .withName(engineName) .withDescription(engineName) .withSubCategories(new ArrayList<>()) .build(); engines.add(engineCategoryDTO); } return engines; }
/** * updates available versions for a certain engine * * @param engineCategoryDTO engine * @param versions available versions for the engine */ public void updateVersions(EngineCategoryDTO engineCategoryDTO, List<EngineSubCategoryDTO> versions) { Platform.runLater(() -> { EngineCategoryDTO newEngineCategoryDTO = new EngineCategoryDTO.Builder(engineCategoryDTO) .withSubCategories(versions) .build(); this.engineCategories.remove(engineCategoryDTO); this.engineCategories.add(newEngineCategoryDTO); }); }
public Builder(EngineCategoryDTO categoryDTO) { this.withName(categoryDTO.getName()).withDescription(categoryDTO.getDescription()) .withSubCategories(categoryDTO.getSubCategories()).withIcon(categoryDTO.getIcon()); }