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 15 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,6 +27,7 @@
import javafx.scene.input.MouseDragEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.VBox;

import org.jabref.architecture.AllowedToUseClassGetResource;
import org.jabref.gui.ClipBoardManager;
Expand Down Expand Up @@ -54,6 +58,8 @@
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.types.StandardEntryType;

import com.airhacks.afterburner.injection.Injector;
import org.slf4j.Logger;
Expand Down Expand Up @@ -189,6 +195,23 @@ public MainTable(MainTableDataModel model,

this.setItems(model.getEntriesFilteredAndSorted());

Button addExampleButton = new Button("Add Example Entry");
addExampleButton.setOnAction(event -> addExampleEntry());

VBox placeholderBox = new VBox(10, new Label("No entries available"), addExampleButton);
placeholderBox.setAlignment(Pos.CENTER);

// Initial check
updatePlaceholder(placeholderBox);

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

// Listener for filtering to remove the button
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.
Expand Down Expand Up @@ -523,4 +546,31 @@ private Optional<BibEntryTableViewModel> findEntry(BibEntry entry) {
public void setCitationMergeMode(boolean citationMerge) {
this.citationMergeMode = citationMerge;
}

private void updatePlaceholder(VBox placeholderBox) {
LOGGER.info("Update place holder ran ");
if (database.getDatabase().getEntries().isEmpty()) {
this.setPlaceholder(placeholderBox);
} else {
this.setPlaceholder(null);
}
}

private void 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");

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


Loading