Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -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 <kbd>ctrl</kbd> + <kbd>,</kbd> 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javafx.scene.text.Text;

import org.jabref.gui.DialogService;
import org.jabref.gui.JabRefGUI;
import org.jabref.gui.StateManager;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.icon.JabRefIcon;
Expand Down Expand Up @@ -60,6 +61,7 @@ public class MainTableColumnFactory {
private final DialogService dialogService;
private final TaskExecutor taskExecutor;
private final StateManager stateManager;
private final MainTableTooltip tooltip;

public MainTableColumnFactory(BibDatabaseContext database,
PreferencesService preferencesService,
Expand All @@ -76,6 +78,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,
JabRefGUI.getThemeManager(), taskExecutor);
Copy link
Member

Choose a reason for hiding this comment

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

Pleas pass the ThemeManager via constructor (Dependency Inversion Principle)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Siedlerchr This entails adding ThemeManager as a constructor parameter for dozen other classes. Should I still do it?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I know this sounds crazy but we don't have really any good dependency injection.
But most of the calling classes should already have the theme manager, so I hope it's only a handful of classes that need ajustment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Siedlerchr I think it's 17 files
commit

Copy link
Member

Choose a reason for hiding this comment

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

ThemeManager themeManager = Injector.instantiateModelOrService(ThemeManager.class);

is a temporary solution until we have a proper di solution.

}

public TableColumn<BibEntryTableViewModel, ?> createColumn(MainTableColumnModel column) {
Expand Down Expand Up @@ -111,14 +115,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;
}
Expand Down Expand Up @@ -263,8 +267,8 @@ private Node createGroupIconRegion(BibEntryTableViewModel entry, List<AbstractGr
/**
* Creates a text column to display any standard field.
*/
private TableColumn<BibEntryTableViewModel, ?> createFieldColumn(MainTableColumnModel columnModel) {
return new FieldColumn(columnModel);
private TableColumn<BibEntryTableViewModel, ?> createFieldColumn(MainTableColumnModel columnModel, MainTableTooltip tooltip) {
return new FieldColumn(columnModel, tooltip);
}

/**
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/org/jabref/gui/maintable/MainTableTooltip.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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 + "\n ");

if (preferences.getPreviewPreferences().shouldShowPreviewEntryTableTooltip()) {
VBox vBox = new VBox();
vBox.getChildren().add(label);
vBox.getChildren().add(preview);
this.setGraphic(vBox);
} else {
this.setGraphic(label);
}
return this;
}
}
11 changes: 10 additions & 1 deletion src/main/java/org/jabref/gui/maintable/columns/FieldColumn.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,16 +21,19 @@
public class FieldColumn extends MainTableColumn<String> {

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<BibEntryTableViewModel, String>()
.withText(text -> text)
.graphicTooltip(this::createTooltip)
.install(this);

if (fields.hasExactlyOne()) {
Expand Down Expand Up @@ -60,4 +65,8 @@ private ObservableValue<String> getFieldValue(BibEntryTableViewModel entry) {
return entry.getFields(fields);
}
}

private Tooltip createTooltip(BibEntryTableViewModel entry, String fieldValue) {
return tooltip.createTooltip(entry.getEntry(), fieldValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
fx:controller="org.jabref.gui.preferences.preview.PreviewTab">
<Label text="%Current Preview" styleClass="titleHeader"/>
<CheckBox fx:id="showAsTabCheckBox" text="%Show preview as a tab in entry editor"/>
<CheckBox fx:id="showPreviewTooltipCheckBox" text="Show preview in entry table tooltip"/>
<HBox spacing="4.0">
<VBox spacing="4.0" HBox.hgrow="ALWAYS">
<Label text="%Available" styleClass="sectionHeader"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
public class PreviewTab extends AbstractPreferenceTabView<PreviewTabViewModel> implements PreferencesTab {

@FXML private CheckBox showAsTabCheckBox;
@FXML private CheckBox showPreviewTooltipCheckBox;
@FXML private ListView<PreviewLayout> availableListView;
@FXML private ListView<PreviewLayout> chosenListView;
@FXML private Button toRightButton;
Expand Down Expand Up @@ -108,6 +109,7 @@ public void initialize() {
lastKeyPressTime = System.currentTimeMillis();

showAsTabCheckBox.selectedProperty().bindBidirectional(viewModel.showAsExtraTabProperty());
showPreviewTooltipCheckBox.selectedProperty().bindBidirectional(viewModel.showPreviewInEntryTableTooltip());

searchBox.setPromptText(Localization.lang("Search") + "...");
searchBox.setLeft(IconTheme.JabRefIcons.SEARCH.getGraphicNode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class PreviewTabViewModel implements PreferenceTabViewModel {
private static final Logger LOGGER = LoggerFactory.getLogger(PreviewTabViewModel.class);

private final BooleanProperty showAsExtraTabProperty = new SimpleBooleanProperty(false);
private final BooleanProperty showPreviewInEntryTableTooltip = new SimpleBooleanProperty(false);

private final ListProperty<PreviewLayout> availableListProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
private final ObjectProperty<MultipleSelectionModel<PreviewLayout>> availableSelectionModelProperty = new SimpleObjectProperty<>(new NoSelectionModel<>());
Expand Down Expand Up @@ -113,6 +114,7 @@ public PreviewTabViewModel(DialogService dialogService,
@Override
public void setValues() {
showAsExtraTabProperty.set(previewPreferences.shouldShowPreviewAsExtraTab());
showPreviewInEntryTableTooltip.set(previewPreferences.shouldShowPreviewEntryTableTooltip());
chosenListProperty().getValue().clear();
chosenListProperty.getValue().addAll(previewPreferences.getLayoutCycle());

Expand Down Expand Up @@ -190,6 +192,7 @@ public void storeSettings() {
previewPreferences.getLayoutCycle().clear();
previewPreferences.getLayoutCycle().addAll(chosenListProperty);
previewPreferences.setShowPreviewAsExtraTab(showAsExtraTabProperty.getValue());
previewPreferences.setShowPreviewEntryTableTooltip(showPreviewInEntryTableTooltip.getValue());
previewPreferences.setCustomPreviewLayout((TextBasedPreviewLayout) customLayout);

if (!chosenSelectionModelProperty.getValue().getSelectedItems().isEmpty()) {
Expand Down Expand Up @@ -439,6 +442,10 @@ public BooleanProperty showAsExtraTabProperty() {
return showAsExtraTabProperty;
}

public BooleanProperty showPreviewInEntryTableTooltip() {
return showPreviewInEntryTableTooltip;
}

public ListProperty<PreviewLayout> availableListProperty() {
return availableListProperty;
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/jabref/gui/util/ValueTableCellFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ public class ValueTableCellFactory<S, T> implements Callback<TableColumn<S, T>,
private Function<T, String> toText;
private BiFunction<S, T, Node> toGraphic;
private BiFunction<S, T, EventHandler<? super MouseEvent>> toOnMouseClickedEvent;
private BiFunction<S, T, EventHandler<? super MouseEvent>> toOnMouseEnterEvent;
private Function<T, BooleanExpression> toDisableExpression;
private Function<T, BooleanExpression> toVisibleExpression;
private BiFunction<S, T, String> toTooltip;
private BiFunction<S, T, Tooltip> tooltip;
private Function<T, ContextMenu> contextMenuFactory;
private BiFunction<S, T, ContextMenu> menuFactory;

Expand All @@ -54,6 +56,11 @@ public ValueTableCellFactory<S, T> withTooltip(BiFunction<S, T, String> toToolti
return this;
}

public ValueTableCellFactory<S, T> graphicTooltip(BiFunction<S, T, Tooltip> tooltip) {
this.tooltip = tooltip;
return this;
}

public ValueTableCellFactory<S, T> withTooltip(Function<T, String> toTooltip) {
this.toTooltip = (rowItem, value) -> toTooltip.apply(value);
return this;
Expand Down Expand Up @@ -133,6 +140,12 @@ protected void updateItem(T item, boolean empty) {
});
}

setOnMouseEntered(event -> {
if (tooltip != null) {
setTooltip(tooltip.apply(rowItem, item));
}
});

setOnMouseClicked(event -> {
if (toOnMouseClickedEvent != null) {
toOnMouseClickedEvent.apply(rowItem, item).handle(event);
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ public class JabRefPreferences implements PreferencesService {
public static final String CYCLE_PREVIEW_POS = "cyclePreviewPos";
public static final String CYCLE_PREVIEW = "cyclePreview";
public static final String PREVIEW_AS_TAB = "previewAsTab";
public static final String PREVIEW_IN_ENTRY_TABLE_TOOLTIP = "previewInEntryTableTooltip";

// UI
private static final String FONT_FAMILY = "fontFamily";
Expand Down Expand Up @@ -800,6 +801,7 @@ private JabRefPreferences() {
defaults.put(CYCLE_PREVIEW, "Preview;" + CitationStyle.DEFAULT);
defaults.put(CYCLE_PREVIEW_POS, 0);
defaults.put(PREVIEW_AS_TAB, Boolean.FALSE);
defaults.put(PREVIEW_IN_ENTRY_TABLE_TOOLTIP, Boolean.FALSE);
defaults.put(PREVIEW_STYLE,
"<font face=\"sans-serif\">" +
"<b>\\bibtextype</b><a name=\"\\citationkey\">\\begin{citationkey} (\\citationkey)</a>\\end{citationkey}__NEWLINE__" +
Expand Down Expand Up @@ -2420,12 +2422,14 @@ public PreviewPreferences getPreviewPreferences() {
getPreviewCyclePosition(layouts),
new TextBasedPreviewLayout(style, getLayoutFormatterPreferences(), Globals.journalAbbreviationRepository),
(String) defaults.get(PREVIEW_STYLE),
getBoolean(PREVIEW_AS_TAB));
getBoolean(PREVIEW_AS_TAB),
getBoolean(PREVIEW_IN_ENTRY_TABLE_TOOLTIP));

previewPreferences.getLayoutCycle().addListener((InvalidationListener) c -> storePreviewLayouts(previewPreferences.getLayoutCycle()));
EasyBind.listen(previewPreferences.layoutCyclePositionProperty(), (obs, oldValue, newValue) -> putInt(CYCLE_PREVIEW_POS, newValue));
EasyBind.listen(previewPreferences.customPreviewLayoutProperty(), (obs, oldValue, newValue) -> put(PREVIEW_STYLE, newValue.getText()));
EasyBind.listen(previewPreferences.showPreviewAsExtraTabProperty(), (obs, oldValue, newValue) -> putBoolean(PREVIEW_AS_TAB, newValue));
EasyBind.listen(previewPreferences.showPreviewEntryTableTooltip(), (obs, oldValue, newValue) -> putBoolean(PREVIEW_IN_ENTRY_TABLE_TOOLTIP, newValue));

return this.previewPreferences;
}
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/org/jabref/preferences/PreviewPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@ public class PreviewPreferences {
private final ObjectProperty<TextBasedPreviewLayout> customPreviewLayout;
private final StringProperty defaultCustomPreviewLayout;
private final BooleanProperty showPreviewAsExtraTab;
private final BooleanProperty showPreviewEntryTableTooltip;

public PreviewPreferences(List<PreviewLayout> layoutCycle,
int layoutCyclePosition,
TextBasedPreviewLayout customPreviewLayout,
String defaultCustomPreviewLayout,
boolean showPreviewAsExtraTab) {
boolean showPreviewAsExtraTab,
boolean showPreviewEntryTableTooltip) {
this.layoutCycle = FXCollections.observableArrayList(layoutCycle);
this.layoutCyclePosition = new SimpleIntegerProperty(layoutCyclePosition);
this.customPreviewLayout = new SimpleObjectProperty<>(customPreviewLayout);
this.defaultCustomPreviewLayout = new SimpleStringProperty(defaultCustomPreviewLayout);
this.showPreviewAsExtraTab = new SimpleBooleanProperty(showPreviewAsExtraTab);
this.showPreviewEntryTableTooltip = new SimpleBooleanProperty(showPreviewEntryTableTooltip);
}

public ObservableList<PreviewLayout> getLayoutCycle() {
Expand Down Expand Up @@ -90,11 +93,23 @@ public boolean shouldShowPreviewAsExtraTab() {
return showPreviewAsExtraTab.getValue();
}

public void setShowPreviewAsExtraTab(boolean showPreviewAsExtraTab) {
this.showPreviewAsExtraTab.set(showPreviewAsExtraTab);
}

public BooleanProperty showPreviewAsExtraTabProperty() {
return showPreviewAsExtraTab;
}

public void setShowPreviewAsExtraTab(boolean showPreviewAsExtraTab) {
this.showPreviewAsExtraTab.set(showPreviewAsExtraTab);
public boolean shouldShowPreviewEntryTableTooltip() {
return showPreviewEntryTableTooltip.getValue();
}

public void setShowPreviewEntryTableTooltip(boolean showPreviewEntryTableTooltip) {
this.showPreviewEntryTableTooltip.set(showPreviewEntryTableTooltip);
}

public BooleanProperty showPreviewEntryTableTooltip() {
return showPreviewEntryTableTooltip;
}
}