Skip to content
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed the BibTeX source dialog background in the Citation Relations tab for dark themes. [#13599](https://github.com/JabRef/jabref/issues/13599)
- We fixed an issue where "Regenerate (custom)" in the AI summary ignored the chosen summarization algorithm. [#17216](https://github.com/JabRef/jabref/issues/17216)
- We fixed AI summary regeneration restoring an outdated summary after a new generation started. [#17236](https://github.com/JabRef/jabref/pull/17236)
- We fixed the linked file tooltip showing the old file name after renaming or moving the file. [#9277](https://github.com/JabRef/jabref/issues/9277)

## [6.0-beta.1] - 2026-09-21

Expand Down
5 changes: 5 additions & 0 deletions docs/code-howtos/javafx.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ DialogService dialogService = Injector.instantiateModelOrService(DialogService.c
JabRef makes heavy use of Properties and Bindings. These are wrappers around Observables. A good explanation on the concept can be found here:
[JavaFX Bindings and Properties](https://web.archive.org/web/20240921154452/https://edencoding.com/javafx-properties-and-binding-a-complete-guide/)

For observable list-cell tooltip text, use `ViewModelListCellFactory.withTooltipText` with a property or lazy observable.
Each cell creates one tooltip and binds its text once through the cell's item property using `flatMap`.
The binding follows the current item and detaches its listeners from the previous item or when the cell becomes empty.
Use `withStringTooltip` for static text and `withTooltip` for custom tooltips whose resources are managed by the caller.

## Features missing in JavaFX

* bidirectional binding in FXML, see [official feature request](https://bugs.openjdk.java.net/browse/JDK-8090665)
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ private void initialize() {
);

new ViewModelListCellFactory<LinkedFileViewModel>()
.withStringTooltip(LinkedFileViewModel::getDescriptionAndLink)
.withTooltipText(linkedFile -> linkedFile.linkProperty().flatMap(_ ->
linkedFile.descriptionProperty().map(_ -> linkedFile.getDescriptionAndLink())))
Comment on lines +166 to +167

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. The linked-file fix lacks a requirement 📘 Rule violation ⚙ Maintainability

LinkedFilesEditor now binds tooltip text to linked-file properties so renames and moves change the
displayed name. Because this user-visible bug fix adds no corresponding entry under
docs/requirements/, its intended behavior is not captured in the requirements set for future
verification.
Agent Prompt
## Issue description
The linked-file tooltip behavior changed so the displayed file name updates after a rename or move, but the PR does not add a corresponding documented requirement.

## Fix Focus Areas
- docs/requirements/ux.md[1-194]
- jabgui/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java[166-167]

## Recommended Fix
Add a requirement to the appropriate requirements document describing that linked-file tooltips display the current file name and update when the linked file is renamed or moved. Include the required requirement identifier immediately after its heading and preserve the file's required markdownlint footer.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

.withPseudoClass(PseudoClass.getPseudoClass("auto-found"), LinkedFileViewModel::isAutomaticallyFoundProperty)
.withGraphic(this::createFileDisplay)
.withOnMouseClickedEvent(this::handleItemMouseClick)
Expand Down
104 changes: 64 additions & 40 deletions jabgui/src/main/java/org/jabref/gui/util/ViewModelListCellFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,43 @@

import com.tobiasdiez.easybind.Subscription;
import de.saxsys.mvvmfx.utils.validation.ValidationStatus;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

/// Constructs a [ListCell] based on the view model of the row and a bunch of specified converter methods.
///
/// @param <T> cell value
@NullMarked
public class ViewModelListCellFactory<T> implements Callback<ListView<T>, ListCell<T>> {

private static final PseudoClass INVALID_PSEUDO_CLASS = PseudoClass.getPseudoClass("invalid");

private Callback<T, String> toText;
private Callback<T, Node> toGraphic;
private Callback<T, Tooltip> toTooltip;
private BiConsumer<T, ? super MouseEvent> toOnMouseClickedEvent;
private Supplier<List<String>> styleClassSupplier;
private Callback<T, ContextMenu> toContextMenu;
private BiConsumer<T, ? super MouseEvent> toOnDragDetected;
private BiConsumer<T, ? super DragEvent> toOnDragDropped;
private BiConsumer<T, ? super DragEvent> toOnDragEntered;
private BiConsumer<T, ? super DragEvent> toOnDragExited;
private BiConsumer<T, ? super DragEvent> toOnDragOver;
private BiConsumer<T, ? super DragEvent> toOnDragDone;
private @Nullable Callback<T, String> toText;
private @Nullable Callback<T, @Nullable Node> toGraphic;
private Callback<ListCell<T>, Callback<T, @Nullable Tooltip>> tooltipFactory = _ -> _ -> null;
private @Nullable BiConsumer<T, ? super MouseEvent> toOnMouseClickedEvent;
private @Nullable Supplier<List<String>> styleClassSupplier;
private @Nullable Callback<T, @Nullable ContextMenu> toContextMenu;
private @Nullable BiConsumer<T, ? super MouseEvent> toOnDragDetected;
private @Nullable BiConsumer<T, ? super DragEvent> toOnDragDropped;
private @Nullable BiConsumer<T, ? super DragEvent> toOnDragEntered;
private @Nullable BiConsumer<T, ? super DragEvent> toOnDragExited;
private @Nullable BiConsumer<T, ? super DragEvent> toOnDragOver;
private @Nullable BiConsumer<T, ? super DragEvent> toOnDragDone;
private final Map<PseudoClass, Callback<T, ObservableValue<Boolean>>> pseudoClasses = new HashMap<>();
private Callback<T, ValidationStatus> validationStatusProperty;
private @Nullable Callback<T, ValidationStatus> validationStatusProperty;

public ViewModelListCellFactory<T> withText(Callback<T, String> toText) {
this.toText = toText;
return this;
}

public ViewModelListCellFactory<T> withGraphic(Callback<T, Node> toGraphic) {
public ViewModelListCellFactory<T> withGraphic(Callback<T, @Nullable Node> toGraphic) {
this.toGraphic = toGraphic;
return this;
}

public ViewModelListCellFactory<T> withIcon(Callback<T, JabRefIcon> toIcon) {
public ViewModelListCellFactory<T> withIcon(Callback<T, @Nullable JabRefIcon> toIcon) {
this.toGraphic = viewModel -> {
JabRefIcon icon = toIcon.call(viewModel);
if (icon != null) {
Expand All @@ -75,23 +78,38 @@ public ViewModelListCellFactory<T> withIcon(Callback<T, JabRefIcon> toIcon, Call
return this;
}

public ViewModelListCellFactory<T> withStringTooltip(Callback<T, String> toStringTooltip) {
this.toTooltip = viewModel -> {
public ViewModelListCellFactory<T> withStringTooltip(Callback<T, @Nullable String> toStringTooltip) {
return withTooltip(viewModel -> {
String tooltipText = toStringTooltip.call(viewModel);
if (StringUtil.isNotBlank(tooltipText)) {
return new Tooltip(tooltipText);
}
return null;
};
});
}

public ViewModelListCellFactory<T> withTooltip(Callback<T, @Nullable Tooltip> toTooltip) {
this.tooltipFactory = _ -> toTooltip;
return this;
}

public ViewModelListCellFactory<T> withTooltip(Callback<T, Tooltip> toTooltip) {
this.toTooltip = toTooltip;
/// Creates one tooltip per cell and binds its text to the current item's observable value.
///
/// The callback is called when the cell receives an item. It must return a property or a lazy
/// observable that releases its listeners when the cell changes items or becomes empty.
///
/// @param toTooltipText provides observable tooltip text for an item
/// @return this factory
public ViewModelListCellFactory<T> withTooltipText(Callback<T, ObservableValue<String>> toTooltipText) {
this.tooltipFactory = cell -> {
Tooltip tooltip = new Tooltip();
tooltip.textProperty().bind(cell.itemProperty().flatMap(toTooltipText::call).when(cell.emptyProperty().not()));
return _ -> tooltip;
Comment on lines +105 to +107

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Informational

2. Blank file links can show empty tooltips 🐞 Bug ≡ Correctness

withTooltipText always attaches a Tooltip, even when its bound text is blank, unlike
withStringTooltip, which leaves the cell without one. A linked file can have an empty link and
description, so a cell without an overriding validation warning receives an empty tooltip rather
than no tooltip.
Agent Prompt
## Issue description
`withTooltipText` attaches a tooltip even when its observable text is blank, whereas static string tooltips are omitted for blank text.

## Fix Focus Areas
- jabgui/src/main/java/org/jabref/gui/util/ViewModelListCellFactory.java[103-108]
- jabgui/src/test/java/org/jabref/gui/util/ViewModelListCellFactoryTest.java[70-97]

## Recommended Fix
Make the reactive tooltip absent when the current text is blank, while retaining the per-cell tooltip and listener cleanup when text becomes nonblank again. Add a test for both transitions.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

};
return this;
}

public ViewModelListCellFactory<T> withContextMenu(Callback<T, ContextMenu> toContextMenu) {
public ViewModelListCellFactory<T> withContextMenu(Callback<T, @Nullable ContextMenu> toContextMenu) {
this.toContextMenu = toContextMenu;
return this;
}
Expand Down Expand Up @@ -160,12 +178,13 @@ public void install(ListView<T> listView) {
}

@Override
public ListCell<T> call(ListView<T> param) {
public ListCell<T> call(@Nullable ListView<T> param) {
ListCell<T> listCell = new ListCell<>() {
final List<Subscription> subscriptions = new ArrayList<>();
private final Callback<T, @Nullable Tooltip> toTooltip = tooltipFactory.call(this);

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

// Remove previous subscriptions
Expand All @@ -186,22 +205,23 @@ protected void updateItem(T item, boolean empty) {
if (toGraphic != null) {
setGraphic(toGraphic.call(viewModel));
}
if (toOnMouseClickedEvent != null) {
setOnMouseClicked(event -> toOnMouseClickedEvent.accept(viewModel, event));
}
if (toTooltip != null) {
setTooltip(toTooltip.call(viewModel));
BiConsumer<T, ? super MouseEvent> onMouseClickedEvent = toOnMouseClickedEvent;
if (onMouseClickedEvent != null) {
setOnMouseClicked(event -> onMouseClickedEvent.accept(viewModel, event));
}
setTooltip(toTooltip.call(viewModel));
if (toContextMenu != null) {
setContextMenu(toContextMenu.call(viewModel));
}
if (toOnDragDetected != null) {
setOnDragDetected(event -> toOnDragDetected.accept(viewModel, event));
BiConsumer<T, ? super MouseEvent> onDragDetected = toOnDragDetected;
if (onDragDetected != null) {
setOnDragDetected(event -> onDragDetected.accept(viewModel, event));
}
if (toOnDragDropped != null) {
BiConsumer<T, ? super DragEvent> onDragDropped = toOnDragDropped;
if (onDragDropped != null) {
setOnDragDropped(event -> {
// For reordering we need to accept the event so that the local handlers get it
toOnDragDropped.accept(viewModel, event);
onDragDropped.accept(viewModel, event);
Node parent = getParent();
if (parent != null) {
// The parent is the box for dropping from external files; that should be used as target (and not this cell)
Expand All @@ -212,16 +232,19 @@ protected void updateItem(T item, boolean empty) {
event.consume();
});
}
if (toOnDragEntered != null) {
setOnDragEntered(event -> toOnDragEntered.accept(viewModel, event));
BiConsumer<T, ? super DragEvent> onDragEntered = toOnDragEntered;
if (onDragEntered != null) {
setOnDragEntered(event -> onDragEntered.accept(viewModel, event));
}
if (toOnDragExited != null) {
setOnDragExited(event -> toOnDragExited.accept(viewModel, event));
BiConsumer<T, ? super DragEvent> onDragExited = toOnDragExited;
if (onDragExited != null) {
setOnDragExited(event -> onDragExited.accept(viewModel, event));
}
if (toOnDragOver != null) {
BiConsumer<T, ? super DragEvent> onDragOver = toOnDragOver;
if (onDragOver != null) {
setOnDragOver(event -> {
// For reordering we need to accept the event so that the local handlers get it
toOnDragOver.accept(viewModel, event);
onDragOver.accept(viewModel, event);
Node parent = getParent();
if (parent != null) {
DragEvent forwarded = event.copyFor(parent, parent);
Expand All @@ -230,8 +253,9 @@ protected void updateItem(T item, boolean empty) {
event.consume();
});
}
if (toOnDragDone != null) {
setOnDragDone(event -> toOnDragDone.accept(viewModel, event));
BiConsumer<T, ? super DragEvent> onDragDone = toOnDragDone;
if (onDragDone != null) {
setOnDragDone(event -> onDragDone.accept(viewModel, event));
}
for (Map.Entry<PseudoClass, Callback<T, ObservableValue<Boolean>>> pseudoClassWithCondition : pseudoClasses.entrySet()) {
ObservableValue<Boolean> condition = pseudoClassWithCondition.getValue().call(viewModel);
Expand Down
Loading
Loading