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

Added "Add example entry" and "Import existing PDFs" when a library is empty #12741

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Added

- 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)
- We added a new Welcome tab which shows a welcome screen if no database is open. [#12272](https://github.com/JabRef/jabref/issues/12272)
- 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)
- We added a feature to rename the subgroup, with the keybinding (<kbd>F2</kbd>) for quick access. [#11896](https://github.com/JabRef/jabref/issues/11896)
7 changes: 7 additions & 0 deletions src/main/java/org/jabref/gui/Base.css
Original file line number Diff line number Diff line change
@@ -2496,3 +2496,10 @@ journalInfo .grid-cell-b {
.refresh {
-fx-background-color: transparent;
}

.text-button-blue{
-fx-background-color: transparent;
-fx-text-fill: -jr-theme;
-fx-font-size: 1.25em;
-fx-border-color: transparent;
}
86 changes: 86 additions & 0 deletions src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
@@ -12,6 +12,9 @@

import javafx.collections.ListChangeListener;
import javafx.css.PseudoClass;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow;
@@ -24,6 +27,8 @@
import javafx.scene.input.MouseDragEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

import org.jabref.architecture.AllowedToUseClassGetResource;
import org.jabref.gui.ClipBoardManager;
@@ -35,10 +40,12 @@
import org.jabref.gui.actions.StandardActions;
import org.jabref.gui.edit.EditAction;
import org.jabref.gui.externalfiles.ExternalFilesEntryLinker;
import org.jabref.gui.externalfiles.FindUnlinkedFilesAction;
import org.jabref.gui.externalfiles.ImportHandler;
import org.jabref.gui.importer.fetcher.LookupIdentifierAction;
import org.jabref.gui.keyboard.KeyBinding;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.libraryproperties.LibraryPropertiesAction;
import org.jabref.gui.maintable.columns.LibraryColumn;
import org.jabref.gui.maintable.columns.MainTableColumn;
import org.jabref.gui.mergeentries.MergeWithFetchedEntryAction;
@@ -53,11 +60,14 @@
import org.jabref.logic.citationstyle.CitationStyleOutputFormat;
import org.jabref.logic.importer.WebFetchers;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.identifier.DOI;
import org.jabref.model.entry.types.StandardEntryType;

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

this.setItems(model.getEntriesFilteredAndSorted());

Button addExampleButton = new Button(Localization.lang("Add example entry"));
addExampleButton.getStyleClass().add("text-button-blue");
addExampleButton.setOnAction(event -> {
BibEntry entry = addExampleEntry();
libraryTab.showAndEdit(entry);
});

Button importPdfsButton = new Button(Localization.lang("Import existing PDFs"));
importPdfsButton.getStyleClass().add("text-button-blue");
importPdfsButton.setOnAction(event -> {
importPdfsButton();
});

Label noContentLabel = new Label(Localization.lang("No content in table"));

// Create horizontal box for buttons
Copy link
Member

Choose a reason for hiding this comment

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

No need for that comment --> either a more "WHY"ish approach or remove

HBox buttonBox = new HBox(20, addExampleButton, importPdfsButton);
buttonBox.setAlignment(Pos.CENTER);

// Create a VBox with the label and horizontal button box
Copy link
Member

Choose a reason for hiding this comment

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

No need for that comment --> either a more "WHY"ish approach or remove

VBox placeholderBox = new VBox(15, noContentLabel, buttonBox);
placeholderBox.setAlignment(Pos.CENTER);

// Initial placeholder based on database content
Copy link
Member

Choose a reason for hiding this comment

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

No need for that comment --> either a more "WHY"ish approach or remove

updatePlaceholder(placeholderBox);

// Listen for database changes
Copy link
Member

Choose a reason for hiding this comment

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

No need for that comment --> either a more "WHY"ish approach or remove

database.getDatabase().getEntries().addListener((ListChangeListener<BibEntry>) change -> updatePlaceholder(placeholderBox));

// Listen for filter changes
Copy link
Member

Choose a reason for hiding this comment

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

No need for that comment --> either a more "WHY"ish approach or remove

this.getItems().addListener((ListChangeListener<BibEntryTableViewModel>) change -> updatePlaceholder(placeholderBox));

// Enable sorting
// Workaround for a JavaFX bug: https://bugs.openjdk.org/browse/JDK-8301761 (The sorting of the SortedList can become invalid)
// The default comparator of the SortedList does not consider the insertion index of entries that are equal according to the comparator.
@@ -538,4 +580,48 @@ private Optional<BibEntryTableViewModel> findEntry(BibEntry entry) {
public void setCitationMergeMode(boolean citationMerge) {
this.citationMergeMode = citationMerge;
}

private void updatePlaceholder(VBox placeholderBox) {
if (database.getDatabase().getEntries().isEmpty()) {
this.setPlaceholder(placeholderBox);
} else {
this.setPlaceholder(null);
}
}

private BibEntry addExampleEntry() {
BibEntry exampleEntry = new BibEntry(StandardEntryType.Article);
exampleEntry.setField(StandardField.AUTHOR, "Oliver Kopp and Carl Christian Snethlage and Christoph Schwentker");
exampleEntry.setField(StandardField.TITLE, "JabRef: BibTeX-based literature management software");
exampleEntry.setField(StandardField.JOURNAL, "TUGboat");
exampleEntry.setField(StandardField.VOLUME, "44");
exampleEntry.setField(StandardField.NUMBER, "3");
exampleEntry.setField(StandardField.PAGES, "441--447");
exampleEntry.setField(StandardField.DOI, "10.47397/tb/44-3/tb138kopp-jabref");
exampleEntry.setField(StandardField.ISSN, "0896-3207");
exampleEntry.setField(StandardField.ISSUE, "138");
exampleEntry.setField(StandardField.YEAR, "2023");
Comment on lines +593 to +603
Copy link
Member

Choose a reason for hiding this comment

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

Dind't I comment that withField should be used? Please do


database.getDatabase().insertEntry(exampleEntry);
return exampleEntry;
}

private void importPdfsButton() {
List<Path> fileDirectories = database.getFileDirectories(filePreferences);

// check if file directories is not empty
Copy link
Member

Choose a reason for hiding this comment

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

No need for that comment --> either a more "WHY"ish approach or remove

if (fileDirectories.isEmpty()) {
dialogService.showWarningDialogAndWait(
Localization.lang("File directory is not set or does not exist!"),
Comment on lines +614 to +615
Copy link

Choose a reason for hiding this comment

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

The warning message ends with an exclamation mark, which should be avoided in UI messages as per guidelines. Should end with a period instead.

Copy link
Author

Choose a reason for hiding this comment

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

Used Key which was already defined in properties , Should i update ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, please. Do it in a separate PR so that we can integrate this fast.

If you feel uncomfortable to create a new branch based on main, you can use git town hack.

Copy link
Author

Choose a reason for hiding this comment

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

I noticed that this message was originally used in an Error Dialog, while the review comment specifically refers to a Warning message. Should I still proceed with making this a global change and remove the exclamation mark?

Copy link
Author

Choose a reason for hiding this comment

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

Also , After reviewing the properties file, I found that many messages contain exclamation marks. Should I update all of them for consistency ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but please think whether it could be critical error, then leave the !.

Localization.lang("Please configure a file directory"));

LibraryPropertiesAction libraryPropertiesAction = new LibraryPropertiesAction(stateManager);
libraryPropertiesAction.execute();
} else {
FindUnlinkedFilesAction findUnlinkedFilesAction = new FindUnlinkedFilesAction(dialogService, stateManager);
findUnlinkedFilesAction.execute();
}
}
}


6 changes: 6 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
@@ -2875,6 +2875,12 @@ Editor\ related=Editor related
Title\ related=Title related
Entry\ fields=Entry fields
Please\ configure\ a\ file\ directory=Please configure a file directory
Add\ example\ entry=Add example entry
No\ content\ in\ table=No content in table
Copy link
Member

Choose a reason for hiding this comment

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

I don't get why this is here - I also see it in current JabREf

image

Import\ existing\ PDFs=Import existing PDFs
No\ recent\ libraries=No recent libraries
Recent=Recent
Start=Start