Skip to content

Commit 5c03936

Browse files
Added "Add example entry" and "Import existing PDFs" when a library is empty (#12741)
* Add placeholder with "Add Example Entry" for empty library -Ensures button is hidden when entries exist but are filtered -Add listeners to track database and table entry changes * Updated code based on draft review ( Import pdf pending) -used localization -added styles for button * Added function for Import existing PDFs -checks if directory exists -triggers search for unlinked files ( if directory exists ) -Shows notification and open library properties ( if directory doesn't exist) * updated CHANGELOG.md * Fixed localization issues and checkstyle * Fixed localization issues * submodules changes * roll back .gitmodules * Added comment at the right place * Resolved Review Comments - Removed Unnecessary comments - Used withField for BibEntry instead of setField * Removed Exclamation mark , should be avoided in UI messages. -updating with period * -Refactored function name to importPdfs -Added focus for library-specific file directory * -Refactored importPDFs to follow fail fast principles -Removed Unused Localization keys -Updated to lambda for better readability * -rewriteRun changes * -Resolved Review Changes . -Label Style Changes --------- Co-authored-by: Christoph <[email protected]>
1 parent c39222d commit 5c03936

File tree

6 files changed

+94
-2
lines changed

6 files changed

+94
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
1111

1212
### Added
1313

14+
- We added buttons "Add example entry" and "Import existing PDFs" when a library is empty, making it easier for new users to get started. [#12662](https://github.com/JabRef/jabref/issues/12662)
1415
- In the Open/LibreOffice integration, we added the provision to modify the bibliography title and its format for CSL styles, in the "Select style" dialog. [#12663](https://github.com/JabRef/jabref/issues/12663)
1516
- We added a new Welcome tab which shows a welcome screen if no database is open. [#12272](https://github.com/JabRef/jabref/issues/12272)
1617
- We added <kbd>F5</kbd> as a shortcut key for fetching data and <kbd>Alt+F</kbd> as a shortcut for looking up data using DOI. [#11802](https://github.com/JabRef/jabref/issues/11802)

src/main/java/org/jabref/gui/Base.css

+7
Original file line numberDiff line numberDiff line change
@@ -2496,3 +2496,10 @@ journalInfo .grid-cell-b {
24962496
.refresh {
24972497
-fx-background-color: transparent;
24982498
}
2499+
2500+
.text-button-blue{
2501+
-fx-background-color: transparent;
2502+
-fx-text-fill: -jr-theme;
2503+
-fx-font-size: 1.25em;
2504+
-fx-border-color: transparent;
2505+
}

src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public void moveToDefaultDirectory() {
294294
// Get target folder
295295
Optional<Path> fileDir = databaseContext.getFirstExistingFileDir(preferences.getFilePreferences());
296296
if (fileDir.isEmpty()) {
297-
dialogService.showErrorDialogAndWait(Localization.lang("Move file"), Localization.lang("File directory is not set or does not exist!"));
297+
dialogService.showErrorDialogAndWait(Localization.lang("Move file"), Localization.lang("File directory is not set or does not exist."));
298298
return;
299299
}
300300

src/main/java/org/jabref/gui/libraryproperties/general/GeneralPropertiesView.java

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.nio.charset.Charset;
44

5+
import javafx.application.Platform;
56
import javafx.fxml.FXML;
67
import javafx.scene.control.ComboBox;
78
import javafx.scene.control.TextField;
@@ -57,6 +58,8 @@ public void initialize() {
5758
librarySpecificFileDirectory.textProperty().bindBidirectional(viewModel.librarySpecificDirectoryPropertyProperty());
5859
userSpecificFileDirectory.textProperty().bindBidirectional(viewModel.userSpecificFileDirectoryProperty());
5960
laTexFileDirectory.textProperty().bindBidirectional(viewModel.laTexFileDirectoryProperty());
61+
62+
Platform.runLater(()-> librarySpecificFileDirectory.requestFocus());
6063
}
6164

6265
@FXML

src/main/java/org/jabref/gui/maintable/MainTable.java

+76
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
import javafx.collections.ListChangeListener;
1414
import javafx.css.PseudoClass;
15+
import javafx.geometry.Pos;
16+
import javafx.scene.control.Button;
17+
import javafx.scene.control.Label;
1518
import javafx.scene.control.SelectionMode;
1619
import javafx.scene.control.TableColumn;
1720
import javafx.scene.control.TableRow;
@@ -24,6 +27,8 @@
2427
import javafx.scene.input.MouseDragEvent;
2528
import javafx.scene.input.MouseEvent;
2629
import javafx.scene.input.TransferMode;
30+
import javafx.scene.layout.HBox;
31+
import javafx.scene.layout.VBox;
2732

2833
import org.jabref.architecture.AllowedToUseClassGetResource;
2934
import org.jabref.gui.ClipBoardManager;
@@ -35,10 +40,12 @@
3540
import org.jabref.gui.actions.StandardActions;
3641
import org.jabref.gui.edit.EditAction;
3742
import org.jabref.gui.externalfiles.ExternalFilesEntryLinker;
43+
import org.jabref.gui.externalfiles.FindUnlinkedFilesAction;
3844
import org.jabref.gui.externalfiles.ImportHandler;
3945
import org.jabref.gui.importer.fetcher.LookupIdentifierAction;
4046
import org.jabref.gui.keyboard.KeyBinding;
4147
import org.jabref.gui.keyboard.KeyBindingRepository;
48+
import org.jabref.gui.libraryproperties.LibraryPropertiesAction;
4249
import org.jabref.gui.maintable.columns.LibraryColumn;
4350
import org.jabref.gui.maintable.columns.MainTableColumn;
4451
import org.jabref.gui.mergeentries.MergeWithFetchedEntryAction;
@@ -53,11 +60,14 @@
5360
import org.jabref.logic.citationstyle.CitationStyleOutputFormat;
5461
import org.jabref.logic.importer.WebFetchers;
5562
import org.jabref.logic.journals.JournalAbbreviationRepository;
63+
import org.jabref.logic.l10n.Localization;
5664
import org.jabref.logic.util.TaskExecutor;
5765
import org.jabref.model.database.BibDatabaseContext;
5866
import org.jabref.model.entry.BibEntry;
5967
import org.jabref.model.entry.BibEntryTypesManager;
68+
import org.jabref.model.entry.field.StandardField;
6069
import org.jabref.model.entry.identifier.DOI;
70+
import org.jabref.model.entry.types.StandardEntryType;
6171

6272
import com.airhacks.afterburner.injection.Injector;
6373
import org.slf4j.Logger;
@@ -193,6 +203,32 @@ public MainTable(MainTableDataModel model,
193203

194204
this.setItems(model.getEntriesFilteredAndSorted());
195205

206+
Button addExampleButton = new Button(Localization.lang("Add example entry"));
207+
addExampleButton.getStyleClass().add("text-button-blue");
208+
addExampleButton.setOnAction(event -> {
209+
BibEntry entry = addExampleEntry();
210+
libraryTab.showAndEdit(entry);
211+
});
212+
213+
Button importPdfsButton = new Button(Localization.lang("Import existing PDFs"));
214+
importPdfsButton.getStyleClass().add("text-button-blue");
215+
importPdfsButton.setOnAction(event -> importPdfs());
216+
217+
Label noContentLabel = new Label(Localization.lang("No content in table"));
218+
noContentLabel.getStyleClass().add("welcome-header-label");
219+
220+
HBox buttonBox = new HBox(20, addExampleButton, importPdfsButton);
221+
buttonBox.setAlignment(Pos.CENTER);
222+
223+
VBox placeholderBox = new VBox(15, noContentLabel, buttonBox);
224+
placeholderBox.setAlignment(Pos.CENTER);
225+
226+
updatePlaceholder(placeholderBox);
227+
228+
database.getDatabase().getEntries().addListener((ListChangeListener<BibEntry>) change -> updatePlaceholder(placeholderBox));
229+
230+
this.getItems().addListener((ListChangeListener<BibEntryTableViewModel>) change -> updatePlaceholder(placeholderBox));
231+
196232
// Enable sorting
197233
// Workaround for a JavaFX bug: https://bugs.openjdk.org/browse/JDK-8301761 (The sorting of the SortedList can become invalid)
198234
// The default comparator of the SortedList does not consider the insertion index of entries that are equal according to the comparator.
@@ -538,4 +574,44 @@ private Optional<BibEntryTableViewModel> findEntry(BibEntry entry) {
538574
public void setCitationMergeMode(boolean citationMerge) {
539575
this.citationMergeMode = citationMerge;
540576
}
577+
578+
private void updatePlaceholder(VBox placeholderBox) {
579+
if (database.getDatabase().getEntries().isEmpty()) {
580+
this.setPlaceholder(placeholderBox);
581+
} else {
582+
this.setPlaceholder(null);
583+
}
584+
}
585+
586+
private BibEntry addExampleEntry() {
587+
BibEntry exampleEntry = new BibEntry(StandardEntryType.Article)
588+
.withField(StandardField.AUTHOR, "Oliver Kopp and Carl Christian Snethlage and Christoph Schwentker").withField(StandardField.TITLE, "JabRef: BibTeX-based literature management software")
589+
.withField(StandardField.JOURNAL, "TUGboat")
590+
.withField(StandardField.VOLUME, "44")
591+
.withField(StandardField.NUMBER, "3")
592+
.withField(StandardField.PAGES, "441--447")
593+
.withField(StandardField.DOI, "10.47397/tb/44-3/tb138kopp-jabref")
594+
.withField(StandardField.ISSN, "0896-3207")
595+
.withField(StandardField.ISSUE, "138")
596+
.withField(StandardField.YEAR, "2023");
597+
598+
database.getDatabase().insertEntry(exampleEntry);
599+
return exampleEntry;
600+
}
601+
602+
private void importPdfs() {
603+
List<Path> fileDirectories = database.getFileDirectories(filePreferences);
604+
605+
if (fileDirectories.isEmpty()) {
606+
dialogService.notify(
607+
Localization.lang("File directory is not set or does not exist.")
608+
);
609+
LibraryPropertiesAction libraryPropertiesAction = new LibraryPropertiesAction(stateManager);
610+
libraryPropertiesAction.execute();
611+
return;
612+
}
613+
614+
FindUnlinkedFilesAction findUnlinkedFilesAction = new FindUnlinkedFilesAction(dialogService, stateManager);
615+
findUnlinkedFilesAction.execute();
616+
}
541617
}

src/main/resources/l10n/JabRef_en.properties

+6-1
Original file line numberDiff line numberDiff line change
@@ -2748,7 +2748,7 @@ Clear\ history=Clear history
27482748
27492749
File=File
27502750
file=file
2751-
File\ directory\ is\ not\ set\ or\ does\ not\ exist\!=File directory is not set or does not exist!
2751+
File\ directory\ is\ not\ set\ or\ does\ not\ exist.=File directory is not set or does not exist.
27522752
File\ exists=File exists
27532753
File\ not\ found=File not found
27542754
@@ -2879,6 +2879,11 @@ Editor\ related=Editor related
28792879
Title\ related=Title related
28802880
Entry\ fields=Entry fields
28812881
2882+
Add\ example\ entry=Add example entry
2883+
No\ content\ in\ table=No content in table
2884+
Import\ existing\ PDFs=Import existing PDFs
2885+
2886+
28822887
No\ recent\ libraries=No recent libraries
28832888
Recent=Recent
28842889
Start=Start

0 commit comments

Comments
 (0)