-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Fix issue #11189 part 00 refactor citation relation tab logic #11845
base: main
Are you sure you want to change the base?
Changes from all commits
3785cb1
8048da8
18db75e
0e9de3c
9a31735
b1133d0
6a8b21b
01f6da4
337780d
7c2e32d
187b5d4
b71d9fc
dda21ed
077e9ca
0bff913
ea36f1a
d7f9c2d
97b38c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,8 +37,6 @@ | |
import org.jabref.gui.collab.entrychange.PreviewWithSourceTab; | ||
import org.jabref.gui.desktop.os.NativeDesktop; | ||
import org.jabref.gui.entryeditor.EntryEditorTab; | ||
import org.jabref.gui.entryeditor.citationrelationtab.semanticscholar.CitationFetcher; | ||
import org.jabref.gui.entryeditor.citationrelationtab.semanticscholar.SemanticScholarFetcher; | ||
import org.jabref.gui.icon.IconTheme; | ||
import org.jabref.gui.mergeentries.EntriesMergeResult; | ||
import org.jabref.gui.mergeentries.MergeEntriesDialog; | ||
|
@@ -51,8 +49,10 @@ | |
import org.jabref.logic.bibtex.BibEntryWriter; | ||
import org.jabref.logic.bibtex.FieldPreferences; | ||
import org.jabref.logic.bibtex.FieldWriter; | ||
import org.jabref.logic.citation.SearchCitationsRelationsService; | ||
import org.jabref.logic.database.DuplicateCheck; | ||
import org.jabref.logic.exporter.BibWriter; | ||
import org.jabref.logic.importer.fetcher.CitationFetcher; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.logic.os.OS; | ||
import org.jabref.logic.util.BackgroundTask; | ||
|
@@ -92,7 +92,7 @@ public class CitationRelationsTab extends EntryEditorTab { | |
private final GuiPreferences preferences; | ||
private final LibraryTab libraryTab; | ||
private final TaskExecutor taskExecutor; | ||
private final BibEntryRelationsRepository bibEntryRelationsRepository; | ||
private final SearchCitationsRelationsService searchCitationsRelationsService; | ||
private final CitationsRelationsTabViewModel citationsRelationsTabViewModel; | ||
private final DuplicateCheck duplicateCheck; | ||
private final BibEntryTypesManager entryTypesManager; | ||
|
@@ -107,7 +107,8 @@ public CitationRelationsTab(DialogService dialogService, | |
GuiPreferences preferences, | ||
LibraryTab libraryTab, | ||
TaskExecutor taskExecutor, | ||
BibEntryTypesManager bibEntryTypesManager) { | ||
BibEntryTypesManager bibEntryTypesManager, | ||
SearchCitationsRelationsService searchCitationsRelationsService) { | ||
this.dialogService = dialogService; | ||
this.databaseContext = databaseContext; | ||
this.preferences = preferences; | ||
|
@@ -121,9 +122,17 @@ public CitationRelationsTab(DialogService dialogService, | |
|
||
this.entryTypesManager = bibEntryTypesManager; | ||
this.duplicateCheck = new DuplicateCheck(entryTypesManager); | ||
this.bibEntryRelationsRepository = new BibEntryRelationsRepository(new SemanticScholarFetcher(preferences.getImporterPreferences()), | ||
new BibEntryRelationsCache()); | ||
citationsRelationsTabViewModel = new CitationsRelationsTabViewModel(databaseContext, preferences, undoManager, stateManager, dialogService, fileUpdateMonitor, taskExecutor); | ||
this.searchCitationsRelationsService = searchCitationsRelationsService; | ||
|
||
citationsRelationsTabViewModel = new CitationsRelationsTabViewModel( | ||
databaseContext, | ||
preferences, | ||
undoManager, | ||
stateManager, | ||
dialogService, | ||
fileUpdateMonitor, | ||
taskExecutor | ||
); | ||
} | ||
|
||
/** | ||
|
@@ -199,22 +208,22 @@ private SplitPane getPaneAndStartSearch(BibEntry entry) { | |
|
||
refreshCitingButton.setOnMouseClicked(event -> { | ||
searchForRelations(entry, citingListView, abortCitingButton, | ||
refreshCitingButton, CitationFetcher.SearchType.CITES, importCitingButton, citingProgress, true); | ||
refreshCitingButton, CitationFetcher.SearchType.CITES, importCitingButton, citingProgress); | ||
}); | ||
|
||
refreshCitedByButton.setOnMouseClicked(event -> searchForRelations(entry, citedByListView, abortCitedButton, | ||
refreshCitedByButton, CitationFetcher.SearchType.CITED_BY, importCitedByButton, citedByProgress, true)); | ||
refreshCitedByButton, CitationFetcher.SearchType.CITED_BY, importCitedByButton, citedByProgress)); | ||
|
||
// Create SplitPane to hold all nodes above | ||
SplitPane container = new SplitPane(citingVBox, citedByVBox); | ||
styleFetchedListView(citedByListView); | ||
styleFetchedListView(citingListView); | ||
|
||
searchForRelations(entry, citingListView, abortCitingButton, refreshCitingButton, | ||
CitationFetcher.SearchType.CITES, importCitingButton, citingProgress, false); | ||
CitationFetcher.SearchType.CITES, importCitingButton, citingProgress); | ||
|
||
searchForRelations(entry, citedByListView, abortCitedButton, refreshCitedByButton, | ||
CitationFetcher.SearchType.CITED_BY, importCitedByButton, citedByProgress, false); | ||
CitationFetcher.SearchType.CITED_BY, importCitedByButton, citedByProgress); | ||
|
||
return container; | ||
} | ||
|
@@ -410,7 +419,7 @@ protected void bindToEntry(BibEntry entry) { | |
*/ | ||
private void searchForRelations(BibEntry entry, CheckListView<CitationRelationItem> listView, Button abortButton, | ||
Button refreshButton, CitationFetcher.SearchType searchType, Button importButton, | ||
ProgressIndicator progress, boolean shouldRefresh) { | ||
ProgressIndicator progress) { | ||
if (entry.getDOI().isEmpty()) { | ||
hideNodes(abortButton, progress); | ||
showNodes(refreshButton); | ||
|
@@ -424,47 +433,59 @@ private void searchForRelations(BibEntry entry, CheckListView<CitationRelationIt | |
|
||
listView.setItems(observableList); | ||
|
||
if (citingTask != null && !citingTask.isCancelled() && searchType == CitationFetcher.SearchType.CITES) { | ||
// TODO: It should not be possible to cancel a search task that is already running for same tab | ||
if (citingTask != null && !citingTask.isCancelled()) { | ||
citingTask.cancel(); | ||
} else if (citedByTask != null && !citedByTask.isCancelled() && searchType == CitationFetcher.SearchType.CITED_BY) { | ||
citedByTask.cancel(); | ||
} | ||
|
||
BackgroundTask<List<BibEntry>> task; | ||
|
||
if (searchType == CitationFetcher.SearchType.CITES) { | ||
task = BackgroundTask.wrap(() -> { | ||
if (shouldRefresh) { | ||
bibEntryRelationsRepository.forceRefreshReferences(entry); | ||
} | ||
return bibEntryRelationsRepository.getReferences(entry); | ||
}); | ||
citingTask = task; | ||
} else { | ||
task = BackgroundTask.wrap(() -> { | ||
if (shouldRefresh) { | ||
bibEntryRelationsRepository.forceRefreshCitations(entry); | ||
} | ||
return bibEntryRelationsRepository.getCitations(entry); | ||
}); | ||
citedByTask = task; | ||
} | ||
|
||
task.onRunning(() -> prepareToSearchForRelations(abortButton, refreshButton, importButton, progress, task)) | ||
.onSuccess(fetchedList -> onSearchForRelationsSucceed(entry, listView, abortButton, refreshButton, | ||
searchType, importButton, progress, fetchedList, observableList)) | ||
this.createBackGroundTask(entry, searchType) | ||
.consumeOnRunning(task -> prepareToSearchForRelations( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could probably be renamed |
||
abortButton, refreshButton, importButton, progress, task | ||
)) | ||
.onSuccess(fetchedList -> onSearchForRelationsSucceed( | ||
entry, | ||
listView, | ||
abortButton, | ||
refreshButton, | ||
searchType, | ||
importButton, | ||
progress, | ||
fetchedList, | ||
observableList | ||
)) | ||
.onFailure(exception -> { | ||
LOGGER.error("Error while fetching citing Articles", exception); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
just a typo 😃 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @InAnYan This was here before I touched this code. I am leaving this for now in this PR as this out of the scope. |
||
hideNodes(abortButton, progress, importButton); | ||
listView.setPlaceholder(new Label(Localization.lang("Error while fetching citing entries: %0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. articles or entries? 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @InAnYan This was here before I touched this code. I am leaving this for now in this PR as this out of the scope. |
||
exception.getMessage()))); | ||
|
||
refreshButton.setVisible(true); | ||
dialogService.notify(exception.getMessage()); | ||
}) | ||
.executeWith(taskExecutor); | ||
} | ||
|
||
/** | ||
* TODO: Make the method return a callable and let the calling method create the background task. | ||
*/ | ||
private BackgroundTask<List<BibEntry>> createBackGroundTask( | ||
BibEntry entry, CitationFetcher.SearchType searchType | ||
) { | ||
return switch (searchType) { | ||
case CitationFetcher.SearchType.CITES -> { | ||
citingTask = BackgroundTask.wrap( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not really appreciate this solution. The method should return a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK for me. You can add a TODO comment if you want. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO added. Will see how to enhance the task management after this PR merge. |
||
() -> this.searchCitationsRelationsService.searchReferences(entry) | ||
); | ||
yield citingTask; | ||
} | ||
case CitationFetcher.SearchType.CITED_BY -> { | ||
citedByTask = BackgroundTask.wrap( | ||
() -> this.searchCitationsRelationsService.searchCitations(entry) | ||
); | ||
yield citedByTask; | ||
} | ||
}; | ||
} | ||
|
||
private void onSearchForRelationsSucceed(BibEntry entry, CheckListView<CitationRelationItem> listView, | ||
Button abortButton, Button refreshButton, | ||
CitationFetcher.SearchType searchType, Button importButton, | ||
|
@@ -481,7 +502,7 @@ private void onSearchForRelationsSucceed(BibEntry entry, CheckListView<CitationR | |
.map(localEntry -> new CitationRelationItem(entr, localEntry, true)) | ||
.orElseGet(() -> new CitationRelationItem(entr, false))) | ||
.toList() | ||
); | ||
); | ||
|
||
if (!observableList.isEmpty()) { | ||
listView.refresh(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduces a service layer that segregates the fetching and repository logic definitions.