diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e34874359a..e1d1e813a02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We added support for offline extracting refereferences from PDFs following the IEEE format. [#11156](https://github.com/JabRef/jabref/pull/11156) - We added a new keyboard shortcut ctrl + , to open the preferences. [#11154](https://github.com/JabRef/jabref/pull/11154) - We added value selection (such as for month) for content selectors in custom entry types. [#11109](https://github.com/JabRef/jabref/issues/11109) +- We added tooltip on main table cells that shows cell content or cell content and entry preview if set in preferences. [10925](https://github.com/JabRef/jabref/issues/10925) ### Changed diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java index 6d45b0882a5..e0781bace97 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java @@ -32,6 +32,7 @@ import org.jabref.gui.maintable.columns.MainTableColumn; import org.jabref.gui.maintable.columns.SpecialFieldColumn; import org.jabref.gui.specialfields.SpecialFieldValueViewModel; +import org.jabref.gui.theme.ThemeManager; import org.jabref.gui.util.TaskExecutor; import org.jabref.gui.util.ValueTableCellFactory; import org.jabref.logic.l10n.Localization; @@ -43,6 +44,7 @@ import org.jabref.model.groups.AbstractGroup; import org.jabref.preferences.PreferencesService; +import com.airhacks.afterburner.injection.Injector; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,7 +61,9 @@ public class MainTableColumnFactory { private final UndoManager undoManager; private final DialogService dialogService; private final TaskExecutor taskExecutor; + private final ThemeManager themeManager = Injector.instantiateModelOrService(ThemeManager.class); private final StateManager stateManager; + private final MainTableTooltip tooltip; public MainTableColumnFactory(BibDatabaseContext database, PreferencesService preferencesService, @@ -76,6 +80,8 @@ public MainTableColumnFactory(BibDatabaseContext database, this.cellFactory = new CellFactory(preferencesService, undoManager); this.undoManager = undoManager; this.stateManager = stateManager; + this.tooltip = new MainTableTooltip(database, dialogService, preferencesService, stateManager, + themeManager, taskExecutor); } public TableColumn createColumn(MainTableColumnModel column) { @@ -111,14 +117,14 @@ public MainTableColumnFactory(BibDatabaseContext database, returnColumn = createSpecialFieldColumn(column); } else { LOGGER.warn("Special field type '{}' is unknown. Using normal column type.", column.getQualifier()); - returnColumn = createFieldColumn(column); + returnColumn = createFieldColumn(column, tooltip); } } break; default: case NORMALFIELD: if (!column.getQualifier().isBlank()) { - returnColumn = createFieldColumn(column); + returnColumn = createFieldColumn(column, tooltip); } break; } @@ -263,8 +269,8 @@ private Node createGroupIconRegion(BibEntryTableViewModel entry, List createFieldColumn(MainTableColumnModel columnModel) { - return new FieldColumn(columnModel); + private TableColumn createFieldColumn(MainTableColumnModel columnModel, MainTableTooltip tooltip) { + return new FieldColumn(columnModel, tooltip); } /** diff --git a/src/main/java/org/jabref/gui/maintable/MainTableTooltip.java b/src/main/java/org/jabref/gui/maintable/MainTableTooltip.java new file mode 100644 index 00000000000..0dee796ca40 --- /dev/null +++ b/src/main/java/org/jabref/gui/maintable/MainTableTooltip.java @@ -0,0 +1,46 @@ +package org.jabref.gui.maintable; + +import javafx.scene.control.Label; +import javafx.scene.control.Tooltip; +import javafx.scene.layout.VBox; +import javafx.util.Duration; + +import org.jabref.gui.DialogService; +import org.jabref.gui.StateManager; +import org.jabref.gui.preview.PreviewViewer; +import org.jabref.gui.theme.ThemeManager; +import org.jabref.gui.util.TaskExecutor; +import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.entry.BibEntry; +import org.jabref.preferences.PreferencesService; + +public class MainTableTooltip extends Tooltip { + + private final PreviewViewer preview; + private final PreferencesService preferences; + + public MainTableTooltip(BibDatabaseContext databaseContext, DialogService dialogService, PreferencesService preferences, + StateManager stateManager, ThemeManager themeManager, TaskExecutor taskExecutor) { + + this.preferences = preferences; + this.preview = new PreviewViewer(databaseContext, dialogService, preferences, stateManager, themeManager, taskExecutor); + } + + public Tooltip createTooltip(BibEntry entry, String fieldValue) { + preview.setLayout(preferences.getPreviewPreferences().getSelectedPreviewLayout()); + preview.setEntry(entry); + this.setShowDelay(Duration.seconds(1)); + Label label = new Label(fieldValue); + + if (preferences.getPreviewPreferences().shouldShowPreviewEntryTableTooltip()) { + VBox vBox = new VBox(); + label.setText(label.getText() + "\n "); + vBox.getChildren().add(label); + vBox.getChildren().add(preview); + this.setGraphic(vBox); + } else { + this.setGraphic(label); + } + return this; + } +} diff --git a/src/main/java/org/jabref/gui/maintable/columns/FieldColumn.java b/src/main/java/org/jabref/gui/maintable/columns/FieldColumn.java index 698e8e16895..e272467f409 100644 --- a/src/main/java/org/jabref/gui/maintable/columns/FieldColumn.java +++ b/src/main/java/org/jabref/gui/maintable/columns/FieldColumn.java @@ -1,9 +1,11 @@ package org.jabref.gui.maintable.columns; import javafx.beans.value.ObservableValue; +import javafx.scene.control.Tooltip; import org.jabref.gui.maintable.BibEntryTableViewModel; import org.jabref.gui.maintable.MainTableColumnModel; +import org.jabref.gui.maintable.MainTableTooltip; import org.jabref.gui.util.ValueTableCellFactory; import org.jabref.gui.util.comparator.NumericFieldComparator; import org.jabref.model.entry.field.Field; @@ -19,16 +21,19 @@ public class FieldColumn extends MainTableColumn { private final OrFields fields; + private final MainTableTooltip tooltip; - public FieldColumn(MainTableColumnModel model) { + public FieldColumn(MainTableColumnModel model, MainTableTooltip tooltip) { super(model); this.fields = FieldFactory.parseOrFields(model.getQualifier()); + this.tooltip = tooltip; setText(getDisplayName()); setCellValueFactory(param -> getFieldValue(param.getValue())); new ValueTableCellFactory() .withText(text -> text) + .graphicTooltip(this::createTooltip) .install(this); if (fields.hasExactlyOne()) { @@ -60,4 +65,8 @@ private ObservableValue getFieldValue(BibEntryTableViewModel entry) { return entry.getFields(fields); } } + + private Tooltip createTooltip(BibEntryTableViewModel entry, String fieldValue) { + return tooltip.createTooltip(entry.getEntry(), fieldValue); + } } diff --git a/src/main/java/org/jabref/gui/preferences/preview/PreviewTab.fxml b/src/main/java/org/jabref/gui/preferences/preview/PreviewTab.fxml index 7bd8582ffa3..0b31d99de58 100644 --- a/src/main/java/org/jabref/gui/preferences/preview/PreviewTab.fxml +++ b/src/main/java/org/jabref/gui/preferences/preview/PreviewTab.fxml @@ -20,6 +20,7 @@ fx:controller="org.jabref.gui.preferences.preview.PreviewTab">