Skip to content

Commit 833cf30

Browse files
subhramitSiedlerchrkoppor
authored
Persist selection of databases in SLR (JabRef#11635)
* Attempt: Persist selection of databases * Use ObservableSet * ObservableList * set fetchers * Revise architecture * Revise test * Fix indent * Fix indent 2 * Add changelog entry * Fix indent * Update CHANGELOG.md * Chris' update Co-authored-by: Christoph <siedlerkiller@gmail.com> * Update src/main/java/org/jabref/preferences/WorkspacePreferences.java Co-authored-by: Christoph <siedlerkiller@gmail.com> * Update src/main/java/org/jabref/preferences/JabRefPreferences.java Co-authored-by: Christoph <siedlerkiller@gmail.com> * !Remove duplicated line * Return ObservableList * Remove unused import * Rename foreach loop variable * Rename foreach loop variable * Rename fetcher->catalog * Fix overwriting of existing study catalogs * Merge upstream/main * Fix merge issue * Persist for edits on existing studies * Save preferences only on a "new run" or "save". --------- Co-authored-by: Christoph <siedlerkiller@gmail.com> Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
1 parent 6afe688 commit 833cf30

File tree

6 files changed

+65
-9
lines changed

6 files changed

+65
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
2323
- We enabled creating a new file link manually. [#11017](https://github.com/JabRef/jabref/issues/11017)
2424
- We added a toggle button to invert the selected groups. [#9073](https://github.com/JabRef/jabref/issues/9073)
2525
- We reintroduced the floating search in the main table. [#4237](https://github.com/JabRef/jabref/issues/4237)
26+
- When starting a new SLR, the selected catalogs now persist within and across JabRef sessions. [koppor#614](https://github.com/koppor/jabref/issues/614)
2627
- We added a different background color to the search bar to indicate when the search syntax is wrong. [#11658](https://github.com/JabRef/jabref/pull/11658)
2728

2829
### Changed

src/main/java/org/jabref/gui/slr/ManageStudyDefinitionView.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public ManageStudyDefinitionView(Path pathToStudyDataDirectory) {
111111
/**
112112
* This is used to edit an existing study.
113113
*
114-
* @param study the study to edit
114+
* @param study the study to edit
115115
* @param studyDirectory the directory of the study
116116
*/
117117
public ManageStudyDefinitionView(Study study, Path studyDirectory) {
@@ -145,6 +145,7 @@ private void setupSaveSurveyButton(boolean isEdit) {
145145

146146
setResultConverter(button -> {
147147
if (button == saveSurveyButtonType) {
148+
viewModel.updateSelectedCatalogs();
148149
return viewModel.saveStudy();
149150
}
150151
// Cancel button will return null
@@ -158,14 +159,16 @@ private void initialize() {
158159
viewModel = new ManageStudyDefinitionViewModel(
159160
prefs.getImportFormatPreferences(),
160161
prefs.getImporterPreferences(),
161-
dialogService);
162+
dialogService,
163+
prefs);
162164
} else {
163165
viewModel = new ManageStudyDefinitionViewModel(
164166
study.get(),
165167
pathToStudyDataDirectory,
166168
prefs.getImportFormatPreferences(),
167169
prefs.getImporterPreferences(),
168-
dialogService);
170+
dialogService,
171+
prefs);
169172

170173
// The directory of the study cannot be changed
171174
studyDirectory.setEditable(false);
@@ -237,6 +240,10 @@ private void initCatalogsTab() {
237240
})
238241
.install(catalogTable);
239242

243+
if (study.isEmpty()) {
244+
viewModel.initializeSelectedCatalogs();
245+
}
246+
240247
catalogColumn.setReorderable(false);
241248
catalogColumn.setCellFactory(TextFieldTableCell.forTableColumn());
242249

src/main/java/org/jabref/gui/slr/ManageStudyDefinitionViewModel.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.jabref.model.study.Study;
3333
import org.jabref.model.study.StudyDatabase;
3434
import org.jabref.model.study.StudyQuery;
35+
import org.jabref.preferences.PreferencesService;
3536

3637
import org.slf4j.Logger;
3738
import org.slf4j.LoggerFactory;
@@ -60,12 +61,15 @@ public class ManageStudyDefinitionViewModel {
6061

6162
private final DialogService dialogService;
6263

64+
private final PreferencesService preferencesService;
65+
6366
/**
6467
* Constructor for a new study
6568
*/
6669
public ManageStudyDefinitionViewModel(ImportFormatPreferences importFormatPreferences,
6770
ImporterPreferences importerPreferences,
68-
DialogService dialogService) {
71+
DialogService dialogService,
72+
PreferencesService preferencesService) {
6973
databases.addAll(WebFetchers.getSearchBasedFetchers(importFormatPreferences, importerPreferences)
7074
.stream()
7175
.map(SearchBasedFetcher::getName)
@@ -78,6 +82,7 @@ public ManageStudyDefinitionViewModel(ImportFormatPreferences importFormatPrefer
7882
})
7983
.toList());
8084
this.dialogService = Objects.requireNonNull(dialogService);
85+
this.preferencesService = Objects.requireNonNull(preferencesService);
8186
}
8287

8388
/**
@@ -90,7 +95,8 @@ public ManageStudyDefinitionViewModel(Study study,
9095
Path studyDirectory,
9196
ImportFormatPreferences importFormatPreferences,
9297
ImporterPreferences importerPreferences,
93-
DialogService dialogService) {
98+
DialogService dialogService,
99+
PreferencesService preferencesService) {
94100
// copy the content of the study object into the UI fields
95101
authors.addAll(Objects.requireNonNull(study).getAuthors());
96102
title.setValue(study.getTitle());
@@ -111,6 +117,7 @@ public ManageStudyDefinitionViewModel(Study study,
111117

112118
this.directory.set(Objects.requireNonNull(studyDirectory).toString());
113119
this.dialogService = Objects.requireNonNull(dialogService);
120+
this.preferencesService = Objects.requireNonNull(preferencesService);
114121
}
115122

116123
public StringProperty getTitle() {
@@ -217,4 +224,20 @@ public void deleteQuestion(String item) {
217224
public void deleteQuery(String item) {
218225
queries.remove(item);
219226
}
227+
228+
public void initializeSelectedCatalogs() {
229+
List<String> selectedCatalogs = preferencesService.getWorkspacePreferences().getSelectedSlrCatalogs();
230+
for (StudyCatalogItem catalog : databases) {
231+
catalog.setEnabled(selectedCatalogs.contains(catalog.getName()));
232+
}
233+
}
234+
235+
public void updateSelectedCatalogs() {
236+
List<String> selectedCatalogsList = databases.stream()
237+
.filter(StudyCatalogItem::isEnabled)
238+
.map(StudyCatalogItem::getName)
239+
.collect(Collectors.toList());
240+
241+
preferencesService.getWorkspacePreferences().setSelectedSlrCatalogs(selectedCatalogsList);
242+
}
220243
}

src/main/java/org/jabref/preferences/JabRefPreferences.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,9 @@ public class JabRefPreferences implements PreferencesService, AiApiKeyProvider {
493493
private static final Logger LOGGER = LoggerFactory.getLogger(JabRefPreferences.class);
494494
private static final Preferences PREFS_NODE = Preferences.userRoot().node("/org/jabref");
495495

496+
// SLR
497+
private static final String SELECTED_SLR_CATALOGS = "selectedSlrCatalogs";
498+
496499
// The only instance of this class:
497500
private static JabRefPreferences singleton;
498501
/**
@@ -2182,7 +2185,8 @@ public WorkspacePreferences getWorkspacePreferences() {
21822185
getBoolean(OPEN_LAST_EDITED),
21832186
getBoolean(SHOW_ADVANCED_HINTS),
21842187
getBoolean(WARN_ABOUT_DUPLICATES_IN_INSPECTION),
2185-
getBoolean(CONFIRM_DELETE));
2188+
getBoolean(CONFIRM_DELETE),
2189+
getStringList(SELECTED_SLR_CATALOGS));
21862190

21872191
EasyBind.listen(workspacePreferences.languageProperty(), (obs, oldValue, newValue) -> {
21882192
put(LANGUAGE, newValue.getId());
@@ -2200,6 +2204,8 @@ public WorkspacePreferences getWorkspacePreferences() {
22002204
EasyBind.listen(workspacePreferences.showAdvancedHintsProperty(), (obs, oldValue, newValue) -> putBoolean(SHOW_ADVANCED_HINTS, newValue));
22012205
EasyBind.listen(workspacePreferences.warnAboutDuplicatesInInspectionProperty(), (obs, oldValue, newValue) -> putBoolean(WARN_ABOUT_DUPLICATES_IN_INSPECTION, newValue));
22022206
EasyBind.listen(workspacePreferences.confirmDeleteProperty(), (obs, oldValue, newValue) -> putBoolean(CONFIRM_DELETE, newValue));
2207+
workspacePreferences.getSelectedSlrCatalogs().addListener((ListChangeListener<String>) change ->
2208+
putStringList(SELECTED_SLR_CATALOGS, workspacePreferences.getSelectedSlrCatalogs()));
22032209
return workspacePreferences;
22042210
}
22052211

src/main/java/org/jabref/preferences/WorkspacePreferences.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package org.jabref.preferences;
22

3+
import java.util.List;
4+
35
import javafx.beans.property.BooleanProperty;
46
import javafx.beans.property.IntegerProperty;
57
import javafx.beans.property.ObjectProperty;
68
import javafx.beans.property.SimpleBooleanProperty;
79
import javafx.beans.property.SimpleIntegerProperty;
810
import javafx.beans.property.SimpleObjectProperty;
11+
import javafx.collections.FXCollections;
12+
import javafx.collections.ObservableList;
913

1014
import org.jabref.gui.theme.Theme;
1115
import org.jabref.logic.l10n.Language;
@@ -21,6 +25,7 @@ public class WorkspacePreferences {
2125
private final BooleanProperty showAdvancedHints;
2226
private final BooleanProperty warnAboutDuplicatesInInspection;
2327
private final BooleanProperty confirmDelete;
28+
private final ObservableList<String> selectedSlrCatalogs;
2429

2530
public WorkspacePreferences(Language language,
2631
boolean shouldOverrideDefaultFontSize,
@@ -31,7 +36,8 @@ public WorkspacePreferences(Language language,
3136
boolean shouldOpenLastEdited,
3237
boolean showAdvancedHints,
3338
boolean warnAboutDuplicatesInInspection,
34-
boolean confirmDelete) {
39+
boolean confirmDelete,
40+
List<String> selectedSlrCatalogs) {
3541
this.language = new SimpleObjectProperty<>(language);
3642
this.shouldOverrideDefaultFontSize = new SimpleBooleanProperty(shouldOverrideDefaultFontSize);
3743
this.mainFontSize = new SimpleIntegerProperty(mainFontSize);
@@ -42,6 +48,7 @@ public WorkspacePreferences(Language language,
4248
this.showAdvancedHints = new SimpleBooleanProperty(showAdvancedHints);
4349
this.warnAboutDuplicatesInInspection = new SimpleBooleanProperty(warnAboutDuplicatesInInspection);
4450
this.confirmDelete = new SimpleBooleanProperty(confirmDelete);
51+
this.selectedSlrCatalogs = FXCollections.observableArrayList(selectedSlrCatalogs);
4552
}
4653

4754
public Language getLanguage() {
@@ -155,4 +162,12 @@ public BooleanProperty confirmDeleteProperty() {
155162
public void setConfirmDelete(boolean confirmDelete) {
156163
this.confirmDelete.set(confirmDelete);
157164
}
165+
166+
public ObservableList<String> getSelectedSlrCatalogs() {
167+
return selectedSlrCatalogs;
168+
}
169+
170+
public void setSelectedSlrCatalogs(List<String> catalogs) {
171+
selectedSlrCatalogs.setAll(catalogs);
172+
}
158173
}

src/test/java/org/jabref/gui/slr/ManageStudyDefinitionViewModelTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.jabref.logic.importer.ImporterPreferences;
99
import org.jabref.model.study.Study;
1010
import org.jabref.model.study.StudyDatabase;
11+
import org.jabref.preferences.PreferencesService;
1112

1213
import org.junit.jupiter.api.BeforeEach;
1314
import org.junit.jupiter.api.Test;
@@ -21,18 +22,20 @@ class ManageStudyDefinitionViewModelTest {
2122
private ImportFormatPreferences importFormatPreferences;
2223
private ImporterPreferences importerPreferences;
2324
private DialogService dialogService;
25+
private PreferencesService preferencesService;
2426

2527
@BeforeEach
2628
void setUp() {
2729
// code taken from org.jabref.logic.importer.WebFetchersTest.setUp
2830
importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS);
2931
importerPreferences = mock(ImporterPreferences.class, Answers.RETURNS_DEEP_STUBS);
3032
dialogService = mock(DialogService.class);
33+
preferencesService = mock(PreferencesService.class);
3134
}
3235

3336
@Test
3437
void emptyStudyConstructorFillsDatabasesCorrectly() {
35-
ManageStudyDefinitionViewModel manageStudyDefinitionViewModel = new ManageStudyDefinitionViewModel(importFormatPreferences, importerPreferences, dialogService);
38+
ManageStudyDefinitionViewModel manageStudyDefinitionViewModel = new ManageStudyDefinitionViewModel(importFormatPreferences, importerPreferences, dialogService, preferencesService);
3639
assertEquals(List.of(
3740
new StudyCatalogItem("ACM Portal", true),
3841
new StudyCatalogItem("ArXiv", false),
@@ -103,6 +106,7 @@ private ManageStudyDefinitionViewModel getManageStudyDefinitionViewModel(Path te
103106
tempDir,
104107
importFormatPreferences,
105108
importerPreferences,
106-
dialogService);
109+
dialogService,
110+
preferencesService);
107111
}
108112
}

0 commit comments

Comments
 (0)