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

Reimplement tooltips for file and identifier columns #4011

Merged
merged 2 commits into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
34 changes: 28 additions & 6 deletions src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public MainTableColumnFactory(BibDatabaseContext database, ColumnPreferences pre

// Add column for eprints
if (preferences.showEprintColumn()) {
columns.add(createIconColumn(IconTheme.JabRefIcons.WWW, FieldName.EPRINT));
columns.add(createEprintColumn(IconTheme.JabRefIcons.WWW, FieldName.EPRINT));
}

// Add columns for other file types
Expand Down Expand Up @@ -245,6 +245,7 @@ private TableColumn<BibEntryTableViewModel, List<LinkedFile>> createFileColumn()
column.setCellValueFactory(cellData -> cellData.getValue().getLinkedFiles());
new ValueTableCellFactory<BibEntryTableViewModel, List<LinkedFile>>()
.withGraphic(this::createFileIcon)
.withTooltip(this::createFileTooltip)
.withMenu(this::createFileMenu)
.withOnMouseClickedEvent((entry, linkedFiles) -> event -> {
if ((event.getButton() == MouseButton.PRIMARY) && (linkedFiles.size() == 1)) {
Expand All @@ -257,6 +258,13 @@ private TableColumn<BibEntryTableViewModel, List<LinkedFile>> createFileColumn()
return column;
}

private String createFileTooltip(List<LinkedFile> linkedFiles) {
if (linkedFiles.size() > 0) {
return Localization.lang("Open file %0", linkedFiles.get(0).getLink());
}
return null;
}

private ContextMenu createFileMenu(BibEntryTableViewModel entry, List<LinkedFile> linkedFiles) {
if (linkedFiles.size() <= 1) {
return null;
Expand Down Expand Up @@ -285,9 +293,10 @@ private TableColumn<BibEntryTableViewModel, String> createUrlOrDoiColumn(JabRefI
column.getStyleClass().add(ICON_COLUMN);
setExactWidth(column, GUIGlobals.WIDTH_ICON_COL);
// icon is chosen based on field name in cell, so map fields to its names
column.setCellValueFactory(cellData -> EasyBind.map(cellData.getValue().getField(firstField), x -> firstField).orElse(EasyBind.map(cellData.getValue().getField(secondField), x -> secondField)));
column.setCellValueFactory(cellData -> EasyBind.monadic(cellData.getValue().getField(firstField)).map(x -> firstField).orElse(EasyBind.monadic(cellData.getValue().getField(secondField)).map(x -> secondField)));
new ValueTableCellFactory<BibEntryTableViewModel, String>()
.withGraphic(cellFactory::getTableIcon)
.withTooltip(this::createIdentifierTooltip)
.withOnMouseClickedEvent((BibEntryTableViewModel entry, String content) -> (MouseEvent event) -> openUrlOrDoi(event, entry, content))
.install(column);
return column;
Expand All @@ -313,16 +322,29 @@ private void openUrlOrDoi(MouseEvent event, BibEntryTableViewModel entry, String
event.consume();
}

private TableColumn<BibEntryTableViewModel, String> createIconColumn(JabRefIcon icon, String field) {
private String createIdentifierTooltip(BibEntryTableViewModel entry, String content) {
Optional<String> field = entry.getEntry().getField(content);
if (field.isPresent()) {
if (FieldName.DOI.equals(content)) {
return Localization.lang("Open DOI web link (%0)", field.get());
Copy link
Member

Choose a reason for hiding this comment

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

As DOI, Arxiv are not really translateable, I would just add them as parameter, e.g Open %0 Url %1 (at least for arxiv)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

} else if (FieldName.URL.equals(content)) {
return Localization.lang("Open URL (%0)", field.get());
} else if (FieldName.EPRINT.equals(content)) {
return Localization.lang("Open ArXiv URL (%0)", field.get());
}
}
return null;
}

private TableColumn<BibEntryTableViewModel, String> createEprintColumn(JabRefIcon icon, String field) {
TableColumn<BibEntryTableViewModel, String> column = new TableColumn<>();
column.setGraphic(icon.getGraphicNode());
column.getStyleClass().add(ICON_COLUMN);
setExactWidth(column, GUIGlobals.WIDTH_ICON_COL);
column.setCellValueFactory(cellData -> {
return EasyBind.map(cellData.getValue().getField(field), x -> field);
});
column.setCellValueFactory(cellData -> EasyBind.monadic(cellData.getValue().getField(field)).map(x -> field));
new ValueTableCellFactory<BibEntryTableViewModel, String>()
.withGraphic(cellFactory::getTableIcon)
.withTooltip(this::createIdentifierTooltip)
.withOnMouseClickedEvent((BibEntryTableViewModel entry, String content) -> (MouseEvent event) -> openUrlOrDoi(event, entry, field))
.install(column);
return column;
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/jabref/gui/util/ValueTableCellFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ 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 Function<T, String> toTooltip;
private BiFunction<S, T, String> toTooltip;
private Function<T, ContextMenu> contextMenuFactory;
private BiFunction<S, T, ContextMenu> menuFactory;

Expand All @@ -46,11 +46,16 @@ public ValueTableCellFactory<S, T> withGraphic(BiFunction<S, T, Node> toGraphic)
return this;
}

public ValueTableCellFactory<S, T> withTooltip(Function<T, String> toTooltip) {
public ValueTableCellFactory<S, T> withTooltip(BiFunction<S, T, String> toTooltip) {
this.toTooltip = toTooltip;
return this;
}

public ValueTableCellFactory<S, T> withTooltip(Function<T, String> toTooltip) {
this.toTooltip = (rowItem, value) -> toTooltip.apply(value);
return this;
}

public ValueTableCellFactory<S, T> withOnMouseClickedEvent(BiFunction<S, T, EventHandler<? super MouseEvent>> toOnMouseClickedEvent) {
this.toOnMouseClickedEvent = toOnMouseClickedEvent;
return this;
Expand Down Expand Up @@ -95,7 +100,7 @@ protected void updateItem(T item, boolean empty) {
setGraphic(toGraphic.apply(rowItem, item));
}
if (toTooltip != null) {
String tooltipText = toTooltip.apply(item);
String tooltipText = toTooltip.apply(rowItem, item);
if (StringUtil.isNotBlank(tooltipText)) {
setTooltip(new Tooltip(tooltipText));
}
Expand Down