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

Custom DOI base address fix #7569

Merged
merged 5 commits into from
Apr 8, 2021
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 @@ -36,6 +36,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Fixed

- We fixed an issue where accessing DOI via Library Tab did not use custom DOI address. [#7337] (https://github.com/JabRef/jabref/issues/7337)
- We fixed an issue preventing files from being dragged & dropped into an empty library. [#6851](https://github.com/JabRef/jabref/issues/6851)
- We fixed an issue where double-click onto PDF in file list under the 'General' tab section should just open the file. [#7465](https://github.com/JabRef/jabref/issues/7465)
- We fixed an issue where the dark theme did not extend to a group's custom color picker. [#7481](https://github.com/JabRef/jabref/issues/7481)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public MainTable(MainTableDataModel model,
preferencesService,
externalFileTypes,
libraryTab.getUndoManager(),
dialogService).createColumns());
dialogService,
stateManager).createColumns());

new ViewModelTableRowFactory<BibEntryTableViewModel>()
.withOnMouseClickedEvent((entry, event) -> {
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.StateManager;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.maintable.columns.FieldColumn;
Expand Down Expand Up @@ -57,19 +58,22 @@ public class MainTableColumnFactory {
private final CellFactory cellFactory;
private final UndoManager undoManager;
private final DialogService dialogService;
private final StateManager stateManager;

public MainTableColumnFactory(BibDatabaseContext database,
PreferencesService preferencesService,
ExternalFileTypes externalFileTypes,
UndoManager undoManager,
DialogService dialogService) {
DialogService dialogService,
StateManager stateManager) {
this.database = Objects.requireNonNull(database);
this.preferencesService = Objects.requireNonNull(preferencesService);
this.columnPreferences = preferencesService.getColumnPreferences();
this.externalFileTypes = Objects.requireNonNull(externalFileTypes);
this.dialogService = dialogService;
this.cellFactory = new CellFactory(externalFileTypes, preferencesService, undoManager);
this.undoManager = undoManager;
this.stateManager = stateManager;
}

public List<TableColumn<BibEntryTableViewModel, ?>> createColumns() {
Expand Down Expand Up @@ -207,7 +211,7 @@ private Node createGroupColorRegion(BibEntryTableViewModel entry, List<AbstractG
* Creates a clickable icons column for DOIs, URLs, URIs and EPrints.
*/
private TableColumn<BibEntryTableViewModel, Map<Field, String>> createIdentifierColumn(MainTableColumnModel columnModel) {
return new LinkedIdentifierColumn(columnModel, cellFactory, database, dialogService);
return new LinkedIdentifierColumn(columnModel, cellFactory, database, dialogService, preferencesService, stateManager);
}

/**
Expand Down
26 changes: 24 additions & 2 deletions src/main/java/org/jabref/gui/maintable/OpenUrlAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@
import org.jabref.gui.actions.ActionHelper;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.desktop.JabRefDesktop;
import org.jabref.logic.importer.util.IdentifierParser;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.identifier.DOI;
import org.jabref.preferences.PreferencesService;

public class OpenUrlAction extends SimpleCommand {

private final DialogService dialogService;
private final StateManager stateManager;
private final PreferencesService preferences;

public OpenUrlAction(DialogService dialogService, StateManager stateManager) {
public OpenUrlAction(DialogService dialogService, StateManager stateManager, PreferencesService preferences) {
this.dialogService = dialogService;
this.stateManager = stateManager;
this.preferences = preferences;

BooleanExpression fieldIsSet = ActionHelper.isAnyFieldSetForSelectedEntry(
List.of(StandardField.URL, StandardField.DOI, StandardField.URI, StandardField.EPRINT),
Expand Down Expand Up @@ -62,11 +67,28 @@ public void execute() {

if (link.isPresent()) {
try {
JabRefDesktop.openExternalViewer(databaseContext, link.get(), field);
if (field.equals(StandardField.DOI) && preferences.getDOIPreferences().isUseCustom()) {
openCustomDOI(link.get());
} else {
JabRefDesktop.openExternalViewer(databaseContext, link.get(), field);
}
} catch (IOException e) {
dialogService.showErrorDialogAndWait(Localization.lang("Unable to open link."), e);
}
}
});
}

private void openCustomDOI(String link) {
Copy link
Member

Choose a reason for hiding this comment

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

I saw that this method is a duplicate of the one in the Entry Editor. To avoid code duplication, I think it could be useful to extract this method to a static method in JabRefDesktop and then call that. You would need to pass the prefs as parameter then

IdentifierParser.parse(StandardField.DOI, link)
.map(identifier -> (DOI) identifier)
.flatMap(doi -> doi.getExternalURIWithCustomBase(preferences.getDOIPreferences().getDefaultBaseURI()))
.ifPresent(uri -> {
try {
JabRefDesktop.openBrowser(uri);
} catch (IOException e) {
dialogService.showErrorDialogAndWait(Localization.lang("Unable to open link."), e);
}
});
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/maintable/RightClickMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static ContextMenu create(BibEntryTableViewModel entry,

contextMenu.getItems().add(factory.createMenuItem(StandardActions.OPEN_FOLDER, new OpenFolderAction(dialogService, stateManager, preferencesService)));
contextMenu.getItems().add(factory.createMenuItem(StandardActions.OPEN_EXTERNAL_FILE, new OpenExternalFileAction(dialogService, stateManager, preferencesService)));
contextMenu.getItems().add(factory.createMenuItem(StandardActions.OPEN_URL, new OpenUrlAction(dialogService, stateManager)));
contextMenu.getItems().add(factory.createMenuItem(StandardActions.OPEN_URL, new OpenUrlAction(dialogService, stateManager, preferencesService)));
contextMenu.getItems().add(factory.createMenuItem(StandardActions.SEARCH_SHORTSCIENCE, new SearchShortScienceAction(dialogService, stateManager)));

contextMenu.getItems().add(new SeparatorMenuItem());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@
import javafx.scene.input.MouseButton;

import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.desktop.JabRefDesktop;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.maintable.BibEntryTableViewModel;
import org.jabref.gui.maintable.CellFactory;
import org.jabref.gui.maintable.ColumnPreferences;
import org.jabref.gui.maintable.MainTableColumnFactory;
import org.jabref.gui.maintable.MainTableColumnModel;
import org.jabref.gui.maintable.OpenUrlAction;
import org.jabref.gui.util.ControlHelper;
import org.jabref.gui.util.ValueTableCellFactory;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.field.Field;
import org.jabref.preferences.PreferencesService;

/**
* A clickable icons column for DOIs, URLs, URIs and EPrints.
Expand All @@ -31,15 +34,21 @@ public class LinkedIdentifierColumn extends MainTableColumn<Map<Field, String>>
private final BibDatabaseContext database;
private final CellFactory cellFactory;
private final DialogService dialogService;
private final PreferencesService preferences;
private final StateManager stateManager;

public LinkedIdentifierColumn(MainTableColumnModel model,
CellFactory cellFactory,
BibDatabaseContext database,
DialogService dialogService) {
DialogService dialogService,
PreferencesService preferences,
StateManager stateManager) {
super(model);
this.database = database;
this.cellFactory = cellFactory;
this.dialogService = dialogService;
this.preferences = preferences;
this.stateManager = stateManager;

Node headerGraphic = IconTheme.JabRefIcons.WWW.getGraphicNode();
Tooltip.install(headerGraphic, new Tooltip(Localization.lang("Linked identifiers")));
Expand All @@ -53,15 +62,8 @@ public LinkedIdentifierColumn(MainTableColumnModel model,
.withTooltip(this::createIdentifierTooltip)
.withMenu(this::createIdentifierMenu)
.withOnMouseClickedEvent((entry, linkedFiles) -> event -> {
if ((event.getButton() == MouseButton.PRIMARY) && (linkedFiles.size() == 1)) {
// Open linked identifier directly only if 1 entry is preset
try {
for (Field field : linkedFiles.keySet()) {
JabRefDesktop.openExternalViewer(database, linkedFiles.get(field), field);
}
} catch (IOException e) {
dialogService.showErrorDialogAndWait(Localization.lang("Unable to open link."), e);
}
if ((event.getButton() == MouseButton.PRIMARY)) {
new OpenUrlAction(dialogService, stateManager, preferences).execute();
}
})
.install(this);
Expand Down