|
12 | 12 |
|
13 | 13 | import javafx.collections.ListChangeListener;
|
14 | 14 | import javafx.css.PseudoClass;
|
| 15 | +import javafx.geometry.Pos; |
| 16 | +import javafx.scene.control.Button; |
| 17 | +import javafx.scene.control.Label; |
15 | 18 | import javafx.scene.control.SelectionMode;
|
16 | 19 | import javafx.scene.control.TableColumn;
|
17 | 20 | import javafx.scene.control.TableRow;
|
|
24 | 27 | import javafx.scene.input.MouseDragEvent;
|
25 | 28 | import javafx.scene.input.MouseEvent;
|
26 | 29 | import javafx.scene.input.TransferMode;
|
| 30 | +import javafx.scene.layout.HBox; |
| 31 | +import javafx.scene.layout.VBox; |
27 | 32 |
|
28 | 33 | import org.jabref.architecture.AllowedToUseClassGetResource;
|
29 | 34 | import org.jabref.gui.ClipBoardManager;
|
|
35 | 40 | import org.jabref.gui.actions.StandardActions;
|
36 | 41 | import org.jabref.gui.edit.EditAction;
|
37 | 42 | import org.jabref.gui.externalfiles.ExternalFilesEntryLinker;
|
| 43 | +import org.jabref.gui.externalfiles.FindUnlinkedFilesAction; |
38 | 44 | import org.jabref.gui.externalfiles.ImportHandler;
|
39 | 45 | import org.jabref.gui.importer.fetcher.LookupIdentifierAction;
|
40 | 46 | import org.jabref.gui.keyboard.KeyBinding;
|
41 | 47 | import org.jabref.gui.keyboard.KeyBindingRepository;
|
| 48 | +import org.jabref.gui.libraryproperties.LibraryPropertiesAction; |
42 | 49 | import org.jabref.gui.maintable.columns.LibraryColumn;
|
43 | 50 | import org.jabref.gui.maintable.columns.MainTableColumn;
|
44 | 51 | import org.jabref.gui.mergeentries.MergeWithFetchedEntryAction;
|
|
53 | 60 | import org.jabref.logic.citationstyle.CitationStyleOutputFormat;
|
54 | 61 | import org.jabref.logic.importer.WebFetchers;
|
55 | 62 | import org.jabref.logic.journals.JournalAbbreviationRepository;
|
| 63 | +import org.jabref.logic.l10n.Localization; |
56 | 64 | import org.jabref.logic.util.TaskExecutor;
|
57 | 65 | import org.jabref.model.database.BibDatabaseContext;
|
58 | 66 | import org.jabref.model.entry.BibEntry;
|
59 | 67 | import org.jabref.model.entry.BibEntryTypesManager;
|
| 68 | +import org.jabref.model.entry.field.StandardField; |
60 | 69 | import org.jabref.model.entry.identifier.DOI;
|
| 70 | +import org.jabref.model.entry.types.StandardEntryType; |
61 | 71 |
|
62 | 72 | import com.airhacks.afterburner.injection.Injector;
|
63 | 73 | import org.slf4j.Logger;
|
@@ -193,6 +203,32 @@ public MainTable(MainTableDataModel model,
|
193 | 203 |
|
194 | 204 | this.setItems(model.getEntriesFilteredAndSorted());
|
195 | 205 |
|
| 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 | + |
196 | 232 | // Enable sorting
|
197 | 233 | // Workaround for a JavaFX bug: https://bugs.openjdk.org/browse/JDK-8301761 (The sorting of the SortedList can become invalid)
|
198 | 234 | // 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) {
|
538 | 574 | public void setCitationMergeMode(boolean citationMerge) {
|
539 | 575 | this.citationMergeMode = citationMerge;
|
540 | 576 | }
|
| 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 | + } |
541 | 617 | }
|
0 commit comments