use of javafx.beans.Observable in project POL-POM-5 by PlayOnLinux.
the class LibraryFeaturePanelSkin method createCombinedListWidget.
private CombinedListWidget<ShortcutDTO> createCombinedListWidget() {
final FilteredList<ShortcutDTO> filteredShortcuts = ConcatenatedList.create(new MappedList<>(getControl().getCategories().sorted(Comparator.comparing(ShortcutCategoryDTO::getName)), ShortcutCategoryDTO::getShortcuts)).filtered(getControl().getFilter()::filter);
filteredShortcuts.predicateProperty().bind(Bindings.createObjectBinding(() -> getControl().getFilter()::filter, getControl().getFilter().searchTermProperty(), getControl().getFilter().selectedShortcutCategoryProperty()));
final SortedList<ShortcutDTO> sortedShortcuts = filteredShortcuts.sorted(Comparator.comparing(shortcut -> shortcut.getInfo().getName()));
final ObservableList<ListWidgetElement<ShortcutDTO>> listWidgetEntries = new MappedList<>(sortedShortcuts, ListWidgetElement::create);
final CombinedListWidget<ShortcutDTO> combinedListWidget = new CombinedListWidget<>(listWidgetEntries, this.selectedListWidget);
// bind direction: controller property -> skin property
getControl().selectedShortcutProperty().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 ShortcutDTO selectedItem = newValue.getItem();
final MouseEvent event = newValue.getEvent();
getControl().setSelectedShortcut(selectedItem);
getControl().setOpenedDetailsPanel(new ShortcutInformation(selectedItem));
if (event.getClickCount() == 2) {
getControl().runShortcut(selectedItem);
}
} else {
getControl().setSelectedShortcut(null);
getControl().setOpenedDetailsPanel(new None());
}
});
return combinedListWidget;
}
use of javafx.beans.Observable in project POL-POM-5 by PlayOnLinux.
the class CollectionBindings method mapToMap.
/**
* Maps an {@link ObservableValue<I>} object to an {@link ObservableMap} by applying the given converter function
* and adding the result to the {@link ObservableMap}.
* In case the input value is empty, i.e. contains <code>null</code>, the returned {@link ObservableMap} is also
* empty
*
* @param property The input value
* @param converter The converter function
* @param <I> The type of the input value
* @param <O1> The input type of the result map
* @param <O2> The output type of the result map
* @return A {@link ObservableMap} containing the converted map
*/
public static <I, O1, O2> ObservableMap<O1, O2> mapToMap(ObservableValue<I> property, Function<I, Map<O1, O2>> converter) {
final ObservableMap<O1, O2> result = FXCollections.observableHashMap();
final InvalidationListener listener = (Observable invalidation) -> {
final I input = property.getValue();
result.clear();
if (input != null) {
result.putAll(converter.apply(input));
}
};
// add the listener to the property
property.addListener(listener);
// ensure that the result map is initialised correctly
listener.invalidated(property);
return result;
}
use of javafx.beans.Observable in project POL-POM-5 by PlayOnLinux.
the class CollectionBindings method mapToList.
/**
* Maps an {@link ObservableValue<I>} object to an {@link ObservableList} by applying the given converter function
* and adding the result to the {@link ObservableList}.
* In case the input value is empty, i.e. contains <code>null</code>, the returned {@link ObservableList} is also
* empty
*
* @param property The input value
* @param converter The converter function
* @param <I> The type of the input value
* @param <O> The type of the output value
* @return A {@link ObservableList} containing the converted list
*/
public static <I, O> ObservableList<O> mapToList(ObservableValue<I> property, Function<I, ? extends Collection<O>> converter) {
final ObservableList<O> result = FXCollections.observableArrayList();
final InvalidationListener listener = (Observable invalidation) -> {
final I input = property.getValue();
if (input != null) {
result.setAll(converter.apply(input));
} else {
result.clear();
}
};
// add the listener to the property
property.addListener(listener);
// ensure that the result list is initialised correctly
listener.invalidated(property);
return result;
}
use of javafx.beans.Observable in project POL-POM-5 by PlayOnLinux.
the class ShortcutInformationPanelSkin method createKeyAttributeList.
private KeyAttributeList createKeyAttributeList() {
final KeyAttributeList keyAttributeList = new KeyAttributeList();
this.environmentAttributes.addListener((Observable invalidated) -> keyAttributeList.setAttributeMap(this.environmentAttributes));
keyAttributeList.setAttributeMap(this.environmentAttributes);
return keyAttributeList;
}
use of javafx.beans.Observable in project POL-POM-5 by PlayOnLinux.
the class ShortcutInformationPanelSkin method createPropertiesGrid.
/**
* Creates a new {@link GridPane} containing the properties of the selected shortcut
*
* @return a new {@link GridPane} containing the properties of the selected shortcut
*/
private GridPane createPropertiesGrid() {
final GridPane propertiesGrid = new GridPane();
propertiesGrid.getStyleClass().add("grid");
ColumnConstraints titleColumn = new ColumnConstraintsWithPercentage(30);
ColumnConstraints valueColumn = new ColumnConstraintsWithPercentage(70);
propertiesGrid.getColumnConstraints().addAll(titleColumn, valueColumn);
// ensure that changes to the shortcutProperties map result in updates to the GridPane
shortcutProperties.addListener((Observable invalidation) -> updateProperties(propertiesGrid));
// initialize the properties grid correctly
updateProperties(propertiesGrid);
return propertiesGrid;
}
Aggregations