Search in sources :

Example 16 with CategoryDTO

use of org.phoenicis.repository.dto.CategoryDTO in project phoenicis by PhoenicisOrg.

the class EnginesController method setDefaultEngineIcons.

private void setDefaultEngineIcons(List<CategoryDTO> categoryDTOS) {
    try {
        StringBuilder cssBuilder = new StringBuilder();
        for (CategoryDTO category : categoryDTOS) {
            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 : CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) Path(java.nio.file.Path) IOException(java.io.IOException) URI(java.net.URI) File(java.io.File)

Example 17 with CategoryDTO

use of org.phoenicis.repository.dto.CategoryDTO 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 18 with CategoryDTO

use of org.phoenicis.repository.dto.CategoryDTO in project phoenicis by PhoenicisOrg.

the class EngineToolsManager method fetchAvailableEngineTools.

/**
 * fetches the available engine tools
 * @param repositoryDTO
 * @param callback
 */
public void fetchAvailableEngineTools(RepositoryDTO repositoryDTO, Consumer<Map<String, ApplicationDTO>> callback) {
    Map<String, ApplicationDTO> tools = new HashMap<>();
    // get engine CategoryDTOs
    List<CategoryDTO> categoryDTOS = new ArrayList<>();
    for (TypeDTO typeDTO : repositoryDTO.getTypes()) {
        if (typeDTO.getId().equals("Engines")) {
            categoryDTOS = typeDTO.getCategories();
        }
    }
    for (CategoryDTO engine : categoryDTOS) {
        for (ApplicationDTO applicationDTO : engine.getApplications()) {
            if (applicationDTO.getId().equals("Tools")) {
                tools.put(engine.getId(), applicationDTO);
            }
        }
    }
    callback.accept(tools);
}
Also used : CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) ApplicationDTO(org.phoenicis.repository.dto.ApplicationDTO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TypeDTO(org.phoenicis.repository.dto.TypeDTO)

Example 19 with CategoryDTO

use of org.phoenicis.repository.dto.CategoryDTO in project POL-POM-5 by PlayOnLinux.

the class AppsController method setDefaultCategoryIcons.

/**
 * sets the default category icons from the repository for the sidebar buttons
 *
 * @param categories categories in repository
 */
private void setDefaultCategoryIcons(List<CategoryDTO> categories) {
    Platform.runLater(() -> {
        try {
            StringBuilder cssBuilder = new StringBuilder();
            for (CategoryDTO category : categories) {
                cssBuilder.append("#" + ApplicationSidebarToggleGroupSkin.getToggleButtonId(category.getId()) + "{\n");
                final String categoryIconPath = Optional.ofNullable(category.getIcon()).map(categoryIcon -> categoryIcon.toString()).orElse("/org/phoenicis/javafx/views/common/phoenicis.png");
                cssBuilder.append(String.format("-fx-background-image: url('%s');\n", categoryIconPath));
                cssBuilder.append("}\n");
            }
            String css = cssBuilder.toString();
            Path temp = Files.createTempFile("defaultCategoryIcons", ".css").toAbsolutePath();
            File tempFile = temp.toFile();
            tempFile.deleteOnExit();
            Files.write(temp, css.getBytes());
            String defaultCategoryIconsCss = temp.toUri().toString();
            this.themeManager.setDefaultCategoryIconsCss(defaultCategoryIconsCss);
        } catch (IOException e) {
            LOGGER.warn("Could not set default category icons.", e);
        }
    });
}
Also used : CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) RepositoryDTO(org.phoenicis.repository.dto.RepositoryDTO) Logger(org.slf4j.Logger) Files(java.nio.file.Files) ApplicationSidebarToggleGroupSkin(org.phoenicis.javafx.components.application.skin.ApplicationSidebarToggleGroupSkin) RepositoryManager(org.phoenicis.repository.RepositoryManager) ApplicationsFeaturePanel(org.phoenicis.javafx.components.application.control.ApplicationsFeaturePanel) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) File(java.io.File) ErrorDialog(org.phoenicis.javafx.dialogs.ErrorDialog) Platform(javafx.application.Platform) List(java.util.List) ThemeManager(org.phoenicis.javafx.themes.ThemeManager) Optional(java.util.Optional) URI(java.net.URI) Path(java.nio.file.Path) Path(java.nio.file.Path) IOException(java.io.IOException) File(java.io.File)

Example 20 with CategoryDTO

use of org.phoenicis.repository.dto.CategoryDTO in project POL-POM-5 by PlayOnLinux.

the class EnginesController method setDefaultEngineIcons.

/**
 * Generates css for the button design associated with the given categories
 *
 * @param categoryDTOS The categories
 */
private void setDefaultEngineIcons(List<CategoryDTO> categoryDTOS) {
    try {
        StringBuilder cssBuilder = new StringBuilder();
        for (CategoryDTO category : categoryDTOS) {
            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 : CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) EngineCategoryDTO(org.phoenicis.engines.dto.EngineCategoryDTO) EngineSubCategoryDTO(org.phoenicis.engines.dto.EngineSubCategoryDTO) Path(java.nio.file.Path) IOException(java.io.IOException) URI(java.net.URI) File(java.io.File)

Aggregations

CategoryDTO (org.phoenicis.repository.dto.CategoryDTO)27 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 ApplicationDTO (org.phoenicis.repository.dto.ApplicationDTO)10 File (java.io.File)7 URI (java.net.URI)7 Path (java.nio.file.Path)6 List (java.util.List)6 TypeDTO (org.phoenicis.repository.dto.TypeDTO)6 HashMap (java.util.HashMap)5 Optional (java.util.Optional)5 EngineCategoryDTO (org.phoenicis.engines.dto.EngineCategoryDTO)4 EngineSubCategoryDTO (org.phoenicis.engines.dto.EngineSubCategoryDTO)4 ApplicationsFeaturePanel (org.phoenicis.javafx.components.application.control.ApplicationsFeaturePanel)4 Collections (java.util.Collections)3 Consumer (java.util.function.Consumer)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2