Search in sources :

Example 6 with InstallationCategoryDTO

use of org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationCategoryDTO in project phoenicis 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)

Example 7 with InstallationCategoryDTO

use of org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationCategoryDTO in project phoenicis 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 8 with InstallationCategoryDTO

use of org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationCategoryDTO in project phoenicis 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 9 with InstallationCategoryDTO

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

the class InstallationsFeaturePanelSkin method createContent.

/**
 * {@inheritDoc}
 */
@Override
public ObjectExpression<Node> createContent() {
    final FilteredList<InstallationDTO> filteredInstallations = ConcatenatedList.create(new MappedList<>(getControl().getInstallationCategories().sorted(Comparator.comparing(InstallationCategoryDTO::getName)), InstallationCategoryDTO::getInstallations)).filtered(getControl().getFilter()::filter);
    filteredInstallations.predicateProperty().bind(Bindings.createObjectBinding(() -> getControl().getFilter()::filter, getControl().getFilter().searchTermProperty(), getControl().getFilter().selectedInstallationCategoryProperty()));
    final SortedList<InstallationDTO> sortedInstallations = filteredInstallations.sorted(Comparator.comparing(InstallationDTO::getName));
    final ObservableList<ListWidgetElement<InstallationDTO>> listWidgetEntries = new MappedList<>(sortedInstallations, ListWidgetElement::create);
    final CombinedListWidget<InstallationDTO> combinedListWidget = new CombinedListWidget<>(listWidgetEntries, this.selectedListWidget);
    // bind direction: controller property -> skin property
    getControl().selectedInstallationProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            combinedListWidget.select(newValue);
        } else {
            combinedListWidget.deselect();
        }
    });
    // bind direction: skin property -> controller properties
    combinedListWidget.selectedElementProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            final InstallationDTO selectedItem = newValue.getItem();
            getControl().setSelectedInstallation(selectedItem);
            getControl().setOpenedDetailsPanel(new Installation(selectedItem));
        } else {
            getControl().setSelectedInstallation(null);
            getControl().setOpenedDetailsPanel(new None());
        }
    });
    return new SimpleObjectProperty<>(combinedListWidget);
}
Also used : MappedList(org.phoenicis.javafx.collections.MappedList) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) CombinedListWidget(org.phoenicis.javafx.components.common.widgets.control.CombinedListWidget) Installation(org.phoenicis.javafx.components.installation.panelstates.Installation) ListWidgetElement(org.phoenicis.javafx.components.common.widgets.utils.ListWidgetElement) InstallationDTO(org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationDTO) InstallationCategoryDTO(org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationCategoryDTO) None(org.phoenicis.javafx.components.common.panelstates.None)

Example 10 with InstallationCategoryDTO

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

the class InstallationsFeaturePanelSkin method createSidebar.

/**
 * {@inheritDoc}
 */
@Override
public ObjectExpression<SidebarBase<?, ?, ?>> createSidebar() {
    final SortedList<InstallationCategoryDTO> sortedCategories = getControl().getInstallationCategories().sorted(Comparator.comparing(InstallationCategoryDTO::getName));
    final InstallationSidebar sidebar = new InstallationSidebar(getControl().getFilter(), sortedCategories, this.selectedListWidget);
    // set the default selection
    sidebar.setSelectedListWidget(Optional.ofNullable(getControl().getJavaFxSettingsManager()).map(JavaFxSettingsManager::getInstallationsListType).orElse(ListWidgetType.ICONS_LIST));
    // save changes to the list widget selection to the hard drive
    sidebar.selectedListWidgetProperty().addListener((observable, oldValue, newValue) -> {
        final JavaFxSettingsManager javaFxSettingsManager = getControl().getJavaFxSettingsManager();
        if (newValue != null) {
            javaFxSettingsManager.setInstallationsListType(newValue);
            javaFxSettingsManager.save();
        }
    });
    return new SimpleObjectProperty<>(sidebar);
}
Also used : SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) InstallationSidebar(org.phoenicis.javafx.components.installation.control.InstallationSidebar) JavaFxSettingsManager(org.phoenicis.javafx.settings.JavaFxSettingsManager) 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