Search in sources :

Example 6 with EngineCategoryDTO

use of org.phoenicis.engines.dto.EngineCategoryDTO in project POL-POM-5 by PlayOnLinux.

the class EnginesController method fetchEngineSubcategories.

/**
 * Fetches all engine subcategories that belong to a given list of engine categories
 *
 * @param engineCategories The engine categories
 * @param result The temporary transport variable
 * @param callback A callback method, which is called after all engine subcategories have been fetched
 */
private void fetchEngineSubcategories(Queue<EngineCategoryDTO> engineCategories, Map<EngineCategoryDTO, List<EngineSubCategoryDTO>> result, Consumer<Map<EngineCategoryDTO, List<EngineSubCategoryDTO>>> callback) {
    final Queue<EngineCategoryDTO> queue = new ArrayDeque<>(engineCategories);
    if (queue.isEmpty()) {
        // recursion anchor
        callback.accept(result);
    } else {
        final EngineCategoryDTO engineCategory = queue.poll();
        final String engineId = engineCategory.getName().toLowerCase();
        enginesManager.fetchAvailableVersions(engineId, versions -> {
            // recursively process the remaining engine categories
            fetchEngineSubcategories(queue, ImmutableMap.<EngineCategoryDTO, List<EngineSubCategoryDTO>>builder().putAll(result).put(engineCategory, versions).build(), callback);
        }, e -> Platform.runLater(() -> {
            final ErrorDialog errorDialog = ErrorDialog.builder().withMessage(tr("Error")).withException(e).withOwner(this.enginesView.getContent().getScene().getWindow()).build();
            errorDialog.showAndWait();
        }));
    }
}
Also used : EngineCategoryDTO(org.phoenicis.engines.dto.EngineCategoryDTO) ErrorDialog(org.phoenicis.javafx.dialogs.ErrorDialog)

Example 7 with EngineCategoryDTO

use of org.phoenicis.engines.dto.EngineCategoryDTO in project POL-POM-5 by PlayOnLinux.

the class EnginesSource method fetchAvailableEngines.

public void fetchAvailableEngines(Consumer<List<EngineCategoryDTO>> callback) {
    final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
    List<EngineCategoryDTO> engines = new ArrayList<>();
    interactiveScriptSession.eval("include([\"Functions\", \"Engines\", \"Wine\"]);", ignored -> interactiveScriptSession.eval("new Wine().getAvailableVersions()", output -> {
        EngineCategoryDTO wine = new EngineCategoryDTO.Builder().withName("Wine").withDescription("Wine").withSubCategories(unSerialize(output)).build();
        engines.add(wine);
        callback.accept(engines);
    }, this::throwError), this::throwError);
}
Also used : Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) IOException(java.io.IOException) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) EngineCategoryDTO(org.phoenicis.engines.dto.EngineCategoryDTO) TypeReference(com.fasterxml.jackson.core.type.TypeReference) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) EngineSubCategoryDTO(org.phoenicis.engines.dto.EngineSubCategoryDTO) Collections(java.util.Collections) EngineCategoryDTO(org.phoenicis.engines.dto.EngineCategoryDTO) ArrayList(java.util.ArrayList) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession)

Example 8 with EngineCategoryDTO

use of org.phoenicis.engines.dto.EngineCategoryDTO in project phoenicis by PhoenicisOrg.

the class EnginesSource method fetchAvailableEngines.

public void fetchAvailableEngines(List<CategoryDTO> categoryDTOS, Consumer<List<EngineCategoryDTO>> callback) {
    final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
    StringBuilder includesBuilder = new StringBuilder();
    StringBuilder constructorsBuilder = new StringBuilder();
    constructorsBuilder.append("function fetchEngines() {\n");
    constructorsBuilder.append("var engines = [];\n");
    for (CategoryDTO categoryDTO : categoryDTOS) {
        final String engineName = categoryDTO.getName();
        includesBuilder.append("include([\"Engines\", \"" + engineName + "\", \"Engine\", \"Object\"]);\n");
        constructorsBuilder.append("engines[\"" + engineName + "\"] = new " + engineName + "().getAvailableVersions();\n");
    }
    constructorsBuilder.append("return engines;\n");
    constructorsBuilder.append("}\n");
    constructorsBuilder.append("fetchEngines();");
    interactiveScriptSession.eval(includesBuilder.toString(), ignored -> interactiveScriptSession.eval(constructorsBuilder.toString(), output -> {
        List<EngineCategoryDTO> engines = new ArrayList<>();
        for (Map.Entry<String, Object> entry : ((Map<String, Object>) output).entrySet()) {
            final EngineCategoryDTO engineCategoryDTO = new EngineCategoryDTO.Builder().withName(entry.getKey()).withDescription(entry.getKey()).withSubCategories(unSerialize(entry.getValue())).build();
            engines.add(engineCategoryDTO);
        }
        callback.accept(engines);
    }, this::throwError), this::throwError);
}
Also used : CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) EngineCategoryDTO(org.phoenicis.engines.dto.EngineCategoryDTO) EngineSubCategoryDTO(org.phoenicis.engines.dto.EngineSubCategoryDTO) CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) IOException(java.io.IOException) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) EngineCategoryDTO(org.phoenicis.engines.dto.EngineCategoryDTO) Safe(org.phoenicis.configuration.security.Safe) Map(java.util.Map) TypeReference(com.fasterxml.jackson.core.type.TypeReference) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) EngineSubCategoryDTO(org.phoenicis.engines.dto.EngineSubCategoryDTO) Collections(java.util.Collections) EngineCategoryDTO(org.phoenicis.engines.dto.EngineCategoryDTO) ArrayList(java.util.ArrayList) List(java.util.List) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession)

Example 9 with EngineCategoryDTO

use of org.phoenicis.engines.dto.EngineCategoryDTO in project POL-POM-5 by PlayOnLinux.

the class EngineSidebarSkin method createSidebarToggleGroup.

/**
 * Creates the {@link EnginesSidebarToggleGroup} which contains all known engine categories
 */
private EnginesSidebarToggleGroup createSidebarToggleGroup() {
    final FilteredList<EngineCategoryDTO> filteredEngineCategories = getControl().getItems().filtered(getControl().getFilter()::filter);
    filteredEngineCategories.predicateProperty().bind(Bindings.createObjectBinding(() -> getControl().getFilter()::filter, getControl().searchTermProperty(), getControl().showInstalledProperty(), getControl().showNotInstalledProperty()));
    final EnginesSidebarToggleGroup categoryView = new EnginesSidebarToggleGroup(tr("Engines"), filteredEngineCategories);
    getControl().selectedEngineCategoryProperty().bind(categoryView.selectedElementProperty());
    return categoryView;
}
Also used : EnginesSidebarToggleGroup(org.phoenicis.javafx.components.engine.control.EnginesSidebarToggleGroup) EngineCategoryDTO(org.phoenicis.engines.dto.EngineCategoryDTO)

Aggregations

EngineCategoryDTO (org.phoenicis.engines.dto.EngineCategoryDTO)9 IOException (java.io.IOException)4 EngineSubCategoryDTO (org.phoenicis.engines.dto.EngineSubCategoryDTO)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 List (java.util.List)3 Consumer (java.util.function.Consumer)3 InteractiveScriptSession (org.phoenicis.scripts.interpreter.InteractiveScriptSession)3 ScriptInterpreter (org.phoenicis.scripts.interpreter.ScriptInterpreter)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Map (java.util.Map)2 Safe (org.phoenicis.configuration.security.Safe)2 CategoryDTO (org.phoenicis.repository.dto.CategoryDTO)2 File (java.io.File)1 URI (java.net.URI)1 Path (java.nio.file.Path)1 ObservableList (javafx.collections.ObservableList)1