@@ -77,8 +77,8 @@ public class ImportEntriesDialog extends BaseDialog<Boolean> {
7777 private final BackgroundTask <ParserResult > task ;
7878 private final BibDatabaseContext database ;
7979 private ImportEntriesViewModel viewModel ;
80- private final SearchBasedFetcher searchBasedFetcher ;
81- private final String query ;
80+ private final Optional < SearchBasedFetcher > searchBasedFetcher ;
81+ private final Optional < String > query ;
8282
8383 @ Inject private TaskExecutor taskExecutor ;
8484 @ Inject private DialogService dialogService ;
@@ -97,7 +97,12 @@ public class ImportEntriesDialog extends BaseDialog<Boolean> {
9797 * @param task the task executed for parsing the selected files(s).
9898 */
9999 public ImportEntriesDialog (BibDatabaseContext database , BackgroundTask <ParserResult > task ) {
100- this (database , task , null , null );
100+ this .database = database ;
101+ this .task = task ;
102+ this .searchBasedFetcher = Optional .empty ();
103+ this .query = Optional .empty ();
104+
105+ initializeDialog ();
101106 }
102107
103108 /**
@@ -112,32 +117,10 @@ public ImportEntriesDialog(BibDatabaseContext database, BackgroundTask<ParserRes
112117 public ImportEntriesDialog (BibDatabaseContext database , BackgroundTask <ParserResult > task , SearchBasedFetcher fetcher , String query ) {
113118 this .database = database ;
114119 this .task = task ;
115- this .searchBasedFetcher = fetcher ;
116- this .query = query ;
117-
118- ViewLoader .view (this )
119- .load ()
120- .setAsDialogPane (this );
121-
122- boolean showPagination = (searchBasedFetcher != null ) && (query != null );
123- paginationBox .setVisible (showPagination );
124- paginationBox .setManaged (showPagination );
125-
126- BooleanBinding booleanBind = Bindings .isEmpty (entriesListView .getCheckModel ().getCheckedItems ());
127- Button btn = (Button ) this .getDialogPane ().lookupButton (importButton );
128- btn .disableProperty ().bind (booleanBind );
120+ this .searchBasedFetcher = Optional .of (fetcher );
121+ this .query = Optional .of (query );
129122
130- downloadLinkedOnlineFiles .setSelected (preferences .getFilePreferences ().shouldDownloadLinkedFiles ());
131-
132- setResultConverter (button -> {
133- if (button == importButton ) {
134- viewModel .importEntries (viewModel .getCheckedEntries ().stream ().toList (), downloadLinkedOnlineFiles .isSelected ());
135- } else {
136- dialogService .notify (Localization .lang ("Import canceled" ));
137- }
138-
139- return false ;
140- });
123+ initializeDialog ();
141124 }
142125
143126 @ FXML
@@ -231,12 +214,37 @@ private void initialize() {
231214 totalItems .textProperty ().bind (Bindings .size (viewModel .getAllEntries ()).asString ());
232215 entriesListView .setSelectionModel (new NoSelectionModel <>());
233216 initBibTeX ();
234- if (searchBasedFetcher != null ) {
217+ if (searchBasedFetcher . isPresent () ) {
235218 updatePageUI ();
236219 setupPaginationBindings ();
237220 }
238221 }
239222
223+ private void initializeDialog () {
224+ ViewLoader .view (this )
225+ .load ()
226+ .setAsDialogPane (this );
227+
228+ paginationBox .setVisible (searchBasedFetcher .isPresent ());
229+ paginationBox .setManaged (searchBasedFetcher .isPresent ());
230+
231+ BooleanBinding booleanBind = Bindings .isEmpty (entriesListView .getCheckModel ().getCheckedItems ());
232+ Button btn = (Button ) this .getDialogPane ().lookupButton (importButton );
233+ btn .disableProperty ().bind (booleanBind );
234+
235+ downloadLinkedOnlineFiles .setSelected (preferences .getFilePreferences ().shouldDownloadLinkedFiles ());
236+
237+ setResultConverter (button -> {
238+ if (button == importButton ) {
239+ viewModel .importEntries (viewModel .getCheckedEntries ().stream ().toList (), downloadLinkedOnlineFiles .isSelected ());
240+ } else {
241+ dialogService .notify (Localization .lang ("Import canceled" ));
242+ }
243+
244+ return false ;
245+ });
246+ }
247+
240248 private void setupPaginationBindings () {
241249 BooleanProperty loading = viewModel .loadingProperty ();
242250 BooleanProperty initialLoadComplete = viewModel .initialLoadCompleteProperty ();
@@ -248,7 +256,7 @@ private void setupPaginationBindings() {
248256 }, viewModel .currentPageProperty (), viewModel .totalPagesProperty ());
249257
250258 BooleanBinding isPagedFetcher = Bindings .createBooleanBinding (() ->
251- searchBasedFetcher instanceof PagedSearchBasedFetcher
259+ searchBasedFetcher . isPresent () && searchBasedFetcher . get () instanceof PagedSearchBasedFetcher
252260 );
253261
254262 // Disable: during loading OR when on the last page for non-paged fetchers
@@ -306,7 +314,7 @@ private void setupPaginationBindings() {
306314 )
307315 );
308316
309- loading .addListener ((obs , oldVal , newVal ) -> {
317+ loading .addListener ((_ , _ , newVal ) -> {
310318 getDialogPane ().getScene ().setCursor (newVal ? Cursor .WAIT : Cursor .DEFAULT );
311319 });
312320
@@ -382,7 +390,7 @@ public void selectAllEntries() {
382390 }
383391
384392 private boolean isOnLastPageAndPagedFetcher () {
385- if (!(searchBasedFetcher instanceof PagedSearchBasedFetcher )) {
393+ if (searchBasedFetcher . isEmpty () || !(searchBasedFetcher . get () instanceof PagedSearchBasedFetcher )) {
386394 return false ;
387395 }
388396
@@ -400,7 +408,7 @@ private void onPrevPage() {
400408 @ FXML
401409 private void onNextPage () {
402410 if (isOnLastPageAndPagedFetcher ()) {
403- viewModel .fetchMoreEntriesFromLastPage ();
411+ viewModel .fetchMoreEntries ();
404412 } else {
405413 viewModel .goToNextPage ();
406414 }
0 commit comments