Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix highlight issues for lists #5454

Merged
merged 1 commit into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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