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;
}
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();
}
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());
}
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;
}
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;
}
Aggregations