Skip to content

Commit

Permalink
Fix highlight issues for lists
Browse files Browse the repository at this point in the history
Fixes #5277 and fixes #5035. The problem was in both cases that the list view reuses nodes when scrolling (instead of creating new ones).
  • Loading branch information
tobiasdiez committed Oct 16, 2019
1 parent e36daae commit 6fef097
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where empty keywords lead to a strange display of automatic keyword groups. [#5333](https://github.com/JabRef/jabref/issues/5333)
- We fixed an error where the default color of a new group was white instead of dark gray. [#4868](https://github.com/JabRef/jabref/issues/4868)
- We fixed an issue where the first field in the entry editor got the focus while performing a different action (like searching). [#5084](https://github.com/JabRef/jabref/issues/5084)
- We fixed an issue where multiple entries were highlighted in the web search result after scrolling. [#5035](https://github.com/JabRef/jabref/issues/5035)
- We fixed an issue where the hover indication in the web search pane was not working. [#5277](https://github.com/JabRef/jabref/issues/5277)
- We fixed an error mentioning "javafx.controls/com.sun.javafx.scene.control" that was thrown when interacting with the toolbar.
- We fixed an error where a cleared search was restored after switching libraries. [#4846](https://github.com/JabRef/jabref/issues/4846)
- We fixed an exception which occurred when trying to open a non-existing file from the "Recent files"-menu [#5334](https://github.com/JabRef/jabref/issues/5334)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.BindingsHelper;
import org.jabref.gui.util.NoSelectionModel;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.gui.util.TextFlowLimited;
Expand Down Expand Up @@ -110,7 +109,6 @@ private void initialize() {
HBox.setHgrow(entryNode, Priority.ALWAYS);
HBox container = new HBox(entryNode, separator, addToggle);
container.getStyleClass().add("entry-container");
BindingsHelper.includePseudoClassWhen(container, entrySelected, addToggle.selectedProperty());

BackgroundTask.wrap(() -> viewModel.hasDuplicate(entry)).onSuccess(duplicateFound -> {
if (duplicateFound) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void search() {
BackgroundTask<List<BibEntry>> task = BackgroundTask.wrap(() -> activeFetcher.performSearch(getQuery().trim()))
.withInitialMessage(Localization.lang("Processing %0", getQuery()));

task.onFailure(ex -> dialogService.showErrorDialogAndWait(ex));
task.onFailure(dialogService::showErrorDialogAndWait);

ImportEntriesDialog dialog = new ImportEntriesDialog(frame.getCurrentBasePanel().getBibDatabaseContext(), task);
dialog.setTitle(activeFetcher.getName());
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/jabref/gui/util/BindingsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.PreboundBinding;
import org.fxmisc.easybind.Subscription;

/**
* Helper methods for javafx binding.
Expand All @@ -43,12 +44,13 @@ public static <T> BooleanBinding all(ObservableList<T> source, Predicate<T> pred
return Bindings.createBooleanBinding(() -> !source.isEmpty() && source.stream().allMatch(predicate), source);
}

public static void includePseudoClassWhen(Node node, PseudoClass pseudoClass, ObservableValue<? extends Boolean> condition) {
public static Subscription includePseudoClassWhen(Node node, PseudoClass pseudoClass, ObservableValue<? extends Boolean> condition) {
Consumer<Boolean> changePseudoClass = value -> node.pseudoClassStateChanged(pseudoClass, value);
EasyBind.subscribe(condition, changePseudoClass);
Subscription subscription = EasyBind.subscribe(condition, changePseudoClass);

// Put the pseudo class there depending on the current value
changePseudoClass.accept(condition.getValue());
return subscription;
}

/**
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/jabref/gui/util/ViewModelListCellFactory.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.jabref.gui.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;

Expand All @@ -20,6 +22,8 @@
import org.jabref.gui.icon.JabRefIcon;
import org.jabref.model.strings.StringUtil;

import org.fxmisc.easybind.Subscription;

/**
* Constructs a {@link ListCell} based on the view model of the row and a bunch of specified converter methods.
*
Expand Down Expand Up @@ -144,10 +148,16 @@ public ListCell<T> call(ListView<T> param) {

return new ListCell<T>() {

List<Subscription> subscriptions = new ArrayList<>();

@Override
protected void updateItem(T item, boolean empty) {
super.updateItem(item, empty);

// Remove previous subscriptions
subscriptions.forEach(Subscription::unsubscribe);
subscriptions.clear();

T viewModel = getItem();
if (empty || (viewModel == null)) {
setText(null);
Expand Down Expand Up @@ -190,10 +200,10 @@ protected void updateItem(T item, boolean empty) {
}
for (Map.Entry<PseudoClass, Callback<T, ObservableValue<Boolean>>> pseudoClassWithCondition : pseudoClasses.entrySet()) {
ObservableValue<Boolean> condition = pseudoClassWithCondition.getValue().call(viewModel);
BindingsHelper.includePseudoClassWhen(this, pseudoClassWithCondition.getKey(), condition);
Subscription subscription = BindingsHelper.includePseudoClassWhen(this, pseudoClassWithCondition.getKey(), condition);
subscriptions.add(subscription);
}
}
getListView().refresh();
}
};
}
Expand Down

0 comments on commit 6fef097

Please sign in to comment.