Search in sources :

Example 1 with EngineCategoryDTO

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

the class EnginesController method setDefaultEngineIcons.

private void setDefaultEngineIcons(List<EngineCategoryDTO> engineCategoryDTOS) {
    try {
        StringBuilder cssBuilder = new StringBuilder();
        for (EngineCategoryDTO category : engineCategoryDTOS) {
            cssBuilder.append("#" + category.getName().toLowerCase() + "Button{\n");
            URI categoryIcon = category.getIcon();
            if (categoryIcon == null) {
                cssBuilder.append("-fx-background-image: url('/org/phoenicis/javafx/views/common/phoenicis.png');\n");
            } else {
                cssBuilder.append("-fx-background-image: url('" + categoryIcon + "');\n");
            }
            cssBuilder.append("}\n");
        }
        String css = cssBuilder.toString();
        Path temp = Files.createTempFile("defaultEngineIcons", ".css").toAbsolutePath();
        File tempFile = temp.toFile();
        tempFile.deleteOnExit();
        Files.write(temp, css.getBytes());
        String defaultEngineIconsCss = temp.toUri().toString();
        themeManager.setDefaultEngineIconsCss(defaultEngineIconsCss);
    } catch (IOException e) {
        LOGGER.warn("Could not set default engine icons.", e);
    }
}
Also used : Path(java.nio.file.Path) EngineCategoryDTO(org.phoenicis.engines.dto.EngineCategoryDTO) IOException(java.io.IOException) URI(java.net.URI) File(java.io.File)

Example 2 with EngineCategoryDTO

use of org.phoenicis.engines.dto.EngineCategoryDTO in project POL-POM-5 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 3 with EngineCategoryDTO

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

the class EngineSubCategoryPanelSkin method createFilteredEngineVersions.

/**
 * Creates a {@link FilteredList} object of the engine versions by applying the {@link EnginesFilter} known to the
 * control
 *
 * @return A filtered list of the engine versions
 */
private ObservableList<EngineVersionDTO> createFilteredEngineVersions() {
    final EnginesFilter filter = getControl().getFilter();
    final EngineCategoryDTO engineCategory = getControl().getEngineCategory();
    final EngineSubCategoryDTO engineSubCategory = getControl().getEngineSubCategory();
    final FilteredList<EngineVersionDTO> filteredEngineVersions = FXCollections.observableArrayList(engineSubCategory.getPackages()).sorted(EngineSubCategoryDTO.comparator().reversed()).filtered(filter.createFilter(engineCategory, engineSubCategory));
    filteredEngineVersions.predicateProperty().bind(Bindings.createObjectBinding(() -> filter.createFilter(engineCategory, engineSubCategory), filter.searchTermProperty(), filter.selectedEngineCategoryProperty(), filter.showInstalledProperty(), filter.showNotInstalledProperty()));
    return filteredEngineVersions;
}
Also used : EngineCategoryDTO(org.phoenicis.engines.dto.EngineCategoryDTO) EngineVersionDTO(org.phoenicis.engines.dto.EngineVersionDTO) EnginesFilter(org.phoenicis.javafx.views.mainwindow.engines.EnginesFilter) EngineSubCategoryDTO(org.phoenicis.engines.dto.EngineSubCategoryDTO)

Example 4 with EngineCategoryDTO

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

the class EnginesView method updateVersions.

/**
 * 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);
    });
}
Also used : EngineCategoryDTO(org.phoenicis.engines.dto.EngineCategoryDTO)

Example 5 with EngineCategoryDTO

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

the class EnginesView method createEngineSubCategoryTabs.

private ObservableList<Tab> createEngineSubCategoryTabs(EngineSidebar sidebar) {
    // initialize the engines sub category panels
    final MappedList<List<EngineSubCategoryPanel>, EngineCategoryDTO> engineSubCategoryPanelGroups = new MappedList<>(this.engineCategories, engineCategory -> engineCategory.getSubCategories().stream().map(engineSubCategory -> {
        final EngineSubCategoryPanel engineSubCategoryPanel = new EngineSubCategoryPanel();
        engineSubCategoryPanel.setEngineCategory(engineCategory);
        engineSubCategoryPanel.setEngineSubCategory(engineSubCategory);
        engineSubCategoryPanel.setEnginesPath(this.enginesPath);
        engineSubCategoryPanel.setFilter(this.filter);
        engineSubCategoryPanel.setEngine(this.engines.get(engineCategory.getName().toLowerCase()));
        engineSubCategoryPanel.selectedListWidgetProperty().bind(sidebar.selectedListWidgetProperty());
        engineSubCategoryPanel.setOnEngineSelect(this::showEngineDetails);
        return engineSubCategoryPanel;
    }).collect(Collectors.toList()));
    final ConcatenatedList<EngineSubCategoryPanel> engineSubCategoryPanels = ConcatenatedList.create(engineSubCategoryPanelGroups);
    final FilteredList<EngineSubCategoryPanel> filteredEngineSubCategoryPanels = engineSubCategoryPanels.sorted(Comparator.comparing(engineSubCategoryPanel -> engineSubCategoryPanel.getEngineSubCategory().getName())).filtered(this.filter::filter);
    filteredEngineSubCategoryPanels.predicateProperty().bind(Bindings.createObjectBinding(() -> this.filter::filter, this.filter.searchTermProperty(), this.filter.showInstalledProperty(), this.filter.showNotInstalledProperty()));
    // map the panels to tabs
    return new MappedList<>(filteredEngineSubCategoryPanels, engineSubCategoryPanel -> new Tab(engineSubCategoryPanel.getEngineSubCategory().getDescription(), engineSubCategoryPanel));
}
Also used : MappedList(org.phoenicis.javafx.collections.MappedList) Tab(javafx.scene.control.Tab) EngineCategoryDTO(org.phoenicis.engines.dto.EngineCategoryDTO) MappedList(org.phoenicis.javafx.collections.MappedList) FilteredList(javafx.collections.transformation.FilteredList) ObservableList(javafx.collections.ObservableList) ConcatenatedList(org.phoenicis.javafx.collections.ConcatenatedList) EngineSubCategoryPanel(org.phoenicis.javafx.components.engine.control.EngineSubCategoryPanel)

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