-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
base: main
Are you sure you want to change the base?
Changes from all commits
0ad6aa5
91a755c
1316e10
fd92723
0ebccda
c3e6ba5
a58fe3d
82a6ff4
bee4510
8c72d94
3b4cacb
612e994
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
HBox buttonBox = new HBox(20, addExampleButton, importPdfsButton); | ||
buttonBox.setAlignment(Pos.CENTER); | ||
|
||
// Create a VBox with the label and horizontal button box | ||
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. 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 | ||
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. No need for that comment --> either a more "WHY"ish approach or remove |
||
updatePlaceholder(placeholderBox); | ||
|
||
// Listen for database changes | ||
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. 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 | ||
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. 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
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. Dind't I comment that |
||
|
||
database.getDatabase().insertEntry(exampleEntry); | ||
return exampleEntry; | ||
} | ||
|
||
private void importPdfsButton() { | ||
List<Path> fileDirectories = database.getFileDirectories(filePreferences); | ||
|
||
// check if file directories is not empty | ||
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. 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
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. The warning message ends with an exclamation mark, which should be avoided in UI messages as per guidelines. Should end with a period instead. 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. Used Key which was already defined in properties , Should i update ? 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. 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 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 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? 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. Also , After reviewing the properties file, I found that many messages contain exclamation marks. Should I update all of them for consistency ? 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. 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(); | ||
} | ||
} | ||
} | ||
|
||
|
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 | ||
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. |
||
Import\ existing\ PDFs=Import existing PDFs | ||
No\ recent\ libraries=No recent libraries | ||
Recent=Recent | ||
Start=Start | ||
|
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.
No need for that comment --> either a more "WHY"ish approach or remove