From e4f3ea3dc9c6391ff73f09e4d0ed7bb9380898c0 Mon Sep 17 00:00:00 2001 From: ricantech Date: Sun, 17 Feb 2019 19:39:16 +0100 Subject: [PATCH] Convert ObservableList into ListProperty - review changes --- .../contentselector/ContentSelectorDialogView.java | 6 +++--- .../ContentSelectorDialogViewModel.java | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialogView.java b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialogView.java index 8f530e512d34..bb62a712d7dd 100644 --- a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialogView.java +++ b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialogView.java @@ -3,8 +3,8 @@ import java.util.Optional; import java.util.function.Supplier; +import javafx.beans.property.ListProperty; import javafx.beans.value.ChangeListener; -import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.ButtonType; @@ -93,8 +93,8 @@ private void removeKeyword() { } } - private void initListView(ListView listViewToInit, Supplier> backingList, ChangeListener onSelectedListener) { - listViewToInit.setItems(backingList.get()); + private void initListView(ListView listViewToInit, Supplier> backingList, ChangeListener onSelectedListener) { + listViewToInit.itemsProperty().bind(backingList.get()); listViewToInit.getSelectionModel().selectedItemProperty().addListener(onSelectedListener); listViewToInit.getSelectionModel().select(FIRST_ELEMENT); } diff --git a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialogViewModel.java b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialogViewModel.java index 62d2aff1c111..9d16f531a19c 100644 --- a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialogViewModel.java +++ b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialogViewModel.java @@ -9,9 +9,11 @@ import java.util.Set; import java.util.stream.Collectors; +import javafx.beans.property.ListProperty; +import javafx.beans.property.SimpleListProperty; import javafx.collections.FXCollections; -import javafx.collections.ObservableList; +import org.jabref.gui.AbstractViewModel; import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; import org.jabref.logic.l10n.Localization; @@ -21,7 +23,7 @@ import static com.google.common.collect.ImmutableList.of; -class ContentSelectorDialogViewModel { +class ContentSelectorDialogViewModel extends AbstractViewModel { private static final List DEFAULT_FIELD_NAMES = of(FieldName.AUTHOR, FieldName.JOURNAL, FieldName.KEYWORDS, FieldName.PUBLISHER); @@ -30,8 +32,8 @@ class ContentSelectorDialogViewModel { private final BasePanel basePanel; private final Map> fieldNameKeywordsMap = new HashMap<>(); - private ObservableList fieldNames = FXCollections.observableArrayList(); - private ObservableList keywords = FXCollections.observableArrayList(); + private ListProperty fieldNames = new SimpleListProperty<>(FXCollections.observableArrayList()); + private ListProperty keywords = new SimpleListProperty<>(FXCollections.observableArrayList()); ContentSelectorDialogViewModel(MetaData metaData, BasePanel basePanel, DialogService dialogService) { this.metaData = metaData; @@ -57,11 +59,11 @@ private void populateFieldNameKeywordsMapWithExistingValues() { ); } - ObservableList getFieldNamesBackingList() { + ListProperty getFieldNamesBackingList() { return fieldNames; } - ObservableList getKeywordsBackingList() { + ListProperty getKeywordsBackingList() { return keywords; }