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