Skip to content

Commit

Permalink
Fix #2946: external changes are now correctly shown in the entry editor
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasdiez committed Jul 12, 2017
1 parent ce5b4ee commit 03861a3
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Collection;

import javafx.beans.binding.ObjectBinding;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

Expand All @@ -17,6 +18,7 @@ public class AbstractEditorViewModel extends AbstractViewModel {
protected StringProperty text = new SimpleStringProperty("");
protected BibEntry entry;
private final AutoCompleteSuggestionProvider<?> suggestionProvider;
private ObjectBinding<String> fieldBinding;

public AbstractEditorViewModel(String fieldName, AutoCompleteSuggestionProvider<?> suggestionProvider) {
this.fieldName = fieldName;
Expand All @@ -29,9 +31,13 @@ public StringProperty textProperty() {

public void bindToEntry(BibEntry entry) {
this.entry = entry;

// We need to keep a reference to the binding since it otherwise gets discarded
fieldBinding = entry.getFieldBinding(fieldName);

BindingsHelper.bindBidirectional(
this.textProperty(),
entry.getFieldBinding(fieldName),
fieldBinding,
newValue -> {
if (newValue != null) {
entry.setField(fieldName, newValue);
Expand Down

0 comments on commit 03861a3

Please sign in to comment.