Search in sources :

Example 1 with InstallationCategoryDTO

use of org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationCategoryDTO in project POL-POM-5 by PhoenicisOrg.

the class InstallationsUtils method addInstallationToList.

/**
 * adds a new installation to an existing list of installations
 * @param list existing list of installations
 * @param toAdd new installation
 * @return new list of installations containing the existing and new installations
 */
public List<InstallationCategoryDTO> addInstallationToList(List<InstallationCategoryDTO> list, InstallationDTO toAdd) {
    String newInstallationCategory = toAdd.getCategory().toString();
    final InstallationCategoryDTO newCategory = new InstallationCategoryDTO.Builder().withId(newInstallationCategory).withName(tr(newInstallationCategory)).withInstallations(Collections.singletonList(toAdd)).build();
    final SortedMap<String, InstallationCategoryDTO> mergedCategories = new TreeMap<>(createSortedMap(list, InstallationCategoryDTO::getId));
    if (mergedCategories.containsKey(newCategory.getId())) {
        mergedCategories.put(newCategory.getId(), mergeCategories(mergedCategories.get(newCategory.getId()), newCategory));
    } else {
        mergedCategories.put(newCategory.getId(), newCategory);
    }
    final List<InstallationCategoryDTO> categories = new ArrayList<>(mergedCategories.values());
    categories.sort(InstallationCategoryDTO.nameComparator());
    return categories;
}
Also used : InstallationCategoryDTO(org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationCategoryDTO)

Example 2 with InstallationCategoryDTO

use of org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationCategoryDTO in project POL-POM-5 by PhoenicisOrg.

the class InstallationsUtils method mergeCategories.

private InstallationCategoryDTO mergeCategories(InstallationCategoryDTO leftCategory, InstallationCategoryDTO rightCategory) {
    final Map<String, InstallationDTO> leftInstallations = createSortedMap(leftCategory.getInstallations(), InstallationDTO::getId);
    final Map<String, InstallationDTO> rightInstallations = createSortedMap(rightCategory.getInstallations(), InstallationDTO::getId);
    final SortedMap<String, InstallationDTO> mergedInstallations = new TreeMap<>(rightInstallations);
    for (Map.Entry<String, InstallationDTO> entry : leftInstallations.entrySet()) {
        final InstallationDTO application = entry.getValue();
        if (mergedInstallations.containsKey(entry.getKey())) {
            LOGGER.error(String.format("Installation %s exists already!", entry.getKey()));
        } else {
            mergedInstallations.put(entry.getKey(), application);
        }
    }
    final List<InstallationDTO> installations = new ArrayList<>(mergedInstallations.values());
    installations.sort(InstallationDTO.nameComparator());
    return new InstallationCategoryDTO.Builder().withId(leftCategory.getId()).withName(leftCategory.getName()).withInstallations(installations).withIcon(leftCategory.getIcon()).build();
}
Also used : InstallationDTO(org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationDTO) InstallationCategoryDTO(org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationCategoryDTO)

Example 3 with InstallationCategoryDTO

use of org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationCategoryDTO in project POL-POM-5 by PlayOnLinux.

the class InstallationsUtils method removeInstallationFromList.

/**
 * Removes an {@link InstallationDTO} object from an existing list of {@link InstallationDTO} objects
 *
 * @param list The list of existing installations
 * @param toRemove The installation which shall be removed
 * @return A new list of installations containing the existing installations without the installation which shall be
 *         removed
 */
public static List<InstallationCategoryDTO> removeInstallationFromList(List<InstallationCategoryDTO> list, InstallationDTO toRemove) {
    final String newInstallationCategory = toRemove.getCategory().toString();
    final SortedMap<String, InstallationCategoryDTO> newCategories = new TreeMap<>(createSortedMap(list, InstallationCategoryDTO::getId));
    if (newCategories.containsKey(newInstallationCategory)) {
        final InstallationCategoryDTO mergedCategory = removeFromCategory(newCategories.get(newInstallationCategory), toRemove);
        if (mergedCategory.getInstallations().isEmpty()) {
            newCategories.remove(mergedCategory.getId());
        } else {
            newCategories.replace(mergedCategory.getId(), mergedCategory);
        }
    }
    return newCategories.values().stream().sorted(InstallationCategoryDTO.nameComparator()).collect(Collectors.toList());
}
Also used : InstallationCategoryDTO(org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationCategoryDTO)

Example 4 with InstallationCategoryDTO

use of org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationCategoryDTO in project POL-POM-5 by PlayOnLinux.

the class MainWindow method createInstallationsTab.

private Tab createInstallationsTab(InstallationsFeaturePanel installationsFeaturePanel) {
    final Tab installationsTab = new Tab(tr("Installations"), installationsFeaturePanel);
    installationsTab.setClosable(false);
    final ConcatenatedList<InstallationDTO> installations = ConcatenatedList.create(new MappedList<>(installationsFeaturePanel.getInstallationCategories(), InstallationCategoryDTO::getInstallations));
    // a binding containing the number of currently active installations
    final IntegerBinding openInstallations = Bindings.createIntegerBinding(installations::size, installations);
    final TabIndicator indicator = new TabIndicator();
    indicator.textProperty().bind(StringBindings.map(openInstallations, numberOfInstallations -> {
        if (numberOfInstallations.intValue() < 10) {
            return String.valueOf(numberOfInstallations);
        } else {
            return "+";
        }
    }));
    // only show the tab indicator if at least one active installation exists
    installationsTab.graphicProperty().bind(Bindings.when(Bindings.notEqual(openInstallations, 0)).then(indicator).otherwise(new SimpleObjectProperty<>()));
    return installationsTab;
}
Also used : Scene(javafx.scene.Scene) LibraryFeaturePanel(org.phoenicis.javafx.components.library.control.LibraryFeaturePanel) TabIndicator(org.phoenicis.javafx.components.common.control.TabIndicator) IntegerBinding(javafx.beans.binding.IntegerBinding) StringBindings(org.phoenicis.javafx.utils.StringBindings) MappedList(org.phoenicis.javafx.collections.MappedList) Bindings(javafx.beans.binding.Bindings) ErrorDialog(org.phoenicis.javafx.dialogs.ErrorDialog) InstallationDTO(org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationDTO) TabPane(javafx.scene.control.TabPane) JavaFXApplication(org.phoenicis.javafx.JavaFXApplication) ContainersFeaturePanel(org.phoenicis.javafx.components.container.control.ContainersFeaturePanel) InstallationsFeaturePanel(org.phoenicis.javafx.components.installation.control.InstallationsFeaturePanel) SettingsView(org.phoenicis.javafx.views.mainwindow.settings.SettingsView) ApplicationsFeaturePanel(org.phoenicis.javafx.components.application.control.ApplicationsFeaturePanel) InstallationCategoryDTO(org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationCategoryDTO) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) Platform(javafx.application.Platform) JavaFxSettingsManager(org.phoenicis.javafx.settings.JavaFxSettingsManager) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Tab(javafx.scene.control.Tab) ThemeManager(org.phoenicis.javafx.themes.ThemeManager) ConcatenatedList(org.phoenicis.javafx.collections.ConcatenatedList) PhoenicisScene(org.phoenicis.javafx.views.common.PhoenicisScene) Image(javafx.scene.image.Image) EnginesView(org.phoenicis.javafx.views.mainwindow.engines.EnginesView) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Tab(javafx.scene.control.Tab) InstallationDTO(org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationDTO) IntegerBinding(javafx.beans.binding.IntegerBinding) TabIndicator(org.phoenicis.javafx.components.common.control.TabIndicator)

Example 5 with InstallationCategoryDTO

use of org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationCategoryDTO in project POL-POM-5 by PhoenicisOrg.

the class InstallationsUtils method removeInstallationFromList.

/**
 * removes as installation from an existing list of installations
 * @param list existing list of installations
 * @param toRemove installation which shall be removed
 * @return new list of installations containing the existing installations without the installation which shall be removed
 */
public List<InstallationCategoryDTO> removeInstallationFromList(List<InstallationCategoryDTO> list, InstallationDTO toRemove) {
    String newInstallationCategory = toRemove.getCategory().toString();
    final SortedMap<String, InstallationCategoryDTO> newCategories = new TreeMap<>(createSortedMap(list, InstallationCategoryDTO::getId));
    if (newCategories.containsKey(newInstallationCategory)) {
        InstallationCategoryDTO mergedCategory = removeFromCategory(newCategories.get(newInstallationCategory), toRemove);
        if (mergedCategory.getInstallations().isEmpty()) {
            newCategories.remove(mergedCategory.getId());
        } else {
            newCategories.replace(mergedCategory.getId(), mergedCategory);
        }
    }
    final List<InstallationCategoryDTO> categories = new ArrayList<>(newCategories.values());
    categories.sort(InstallationCategoryDTO.nameComparator());
    return categories;
}
Also used : InstallationCategoryDTO(org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationCategoryDTO)

Aggregations

InstallationCategoryDTO (org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationCategoryDTO)13 InstallationDTO (org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationDTO)5 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)3 MappedList (org.phoenicis.javafx.collections.MappedList)2 JavaFxSettingsManager (org.phoenicis.javafx.settings.JavaFxSettingsManager)2 Platform (javafx.application.Platform)1 Bindings (javafx.beans.binding.Bindings)1 IntegerBinding (javafx.beans.binding.IntegerBinding)1 Scene (javafx.scene.Scene)1 Tab (javafx.scene.control.Tab)1 TabPane (javafx.scene.control.TabPane)1 Image (javafx.scene.image.Image)1 Stage (javafx.stage.Stage)1 Localisation.tr (org.phoenicis.configuration.localisation.Localisation.tr)1 JavaFXApplication (org.phoenicis.javafx.JavaFXApplication)1 ConcatenatedList (org.phoenicis.javafx.collections.ConcatenatedList)1 ApplicationsFeaturePanel (org.phoenicis.javafx.components.application.control.ApplicationsFeaturePanel)1 TabIndicator (org.phoenicis.javafx.components.common.control.TabIndicator)1 None (org.phoenicis.javafx.components.common.panelstates.None)1 CombinedListWidget (org.phoenicis.javafx.components.common.widgets.control.CombinedListWidget)1