Skip to content

Add 'Open example library' button to Welcome Tab#13068

Merged
koppor merged 15 commits into
JabRef:mainfrom
khushp3:fix-for-issue-13014
May 15, 2025
Merged

Add 'Open example library' button to Welcome Tab#13068
koppor merged 15 commits into
JabRef:mainfrom
khushp3:fix-for-issue-13014

Conversation

@khushp3

@khushp3 khushp3 commented May 6, 2025

Copy link
Copy Markdown
Contributor

Closes #13014

  • Moved Chocolate.bib to jabgui/src/main/resources
  • Added an "Open example library" button
  • Loads Chocolate.bib from resources
  • Saves it as a temp file
  • Opens it as a new library
  • Deletes it when the VM terminates

PR image

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • [/] Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (if change is visible to the user)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

- Moved Chocolate.bib to jabgui/src/main/resources
- Added an "Open example library" button
- Loads Chocolate.bib from resources
- Saves it as a temp file
- Opens it as a new library
- Deletes it when the VM terminates
taskExecutor).openFiles(List.of(tmpFile));
tmpFile.toFile().deleteOnExit();
} catch (IOException ex) {
throw new RuntimeException(ex);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using exceptions for control flow is not recommended. Exceptions should be used for exceptional states, not for normal control flow.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just add a logger statement here or show an errror dialog
dialogService.showEror...

@khushp3 khushp3 changed the title Changes: Changes: #13014 May 6, 2025
@khushp3 khushp3 changed the title Changes: #13014 Changes: May 6, 2025
@khushp3 khushp3 changed the title Changes: Added 'Open example library' button to Welcome Tab May 6, 2025
}
}
} catch (IOException ex) {
throw new RuntimeException(ex);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same here

@koppor koppor changed the title Added 'Open example library' button to Welcome Tab Add 'Open example library' button to Welcome Tab May 8, 2025

@koppor koppor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

tmp file is not the right approach.

if (in != null) {
Path tmpFile = Files.createTempFile("example-library", ".bib");
try {
Files.copy(in, tmpFile, StandardCopyOption.REPLACE_EXISTING);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wrong approach.

  1. Create a new library
  2. Fill it with contents of Chocolate.bib. For that, you need to use org.jabref.logic.importer.fileformat.BibtexParser#BibtexParser(org.jabref.logic.importer.ImportFormatPreferences). Then you can call org.jabref.model.database.BibDatabase#insertEntries(java.util.List<org.jabref.model.entry.BibEntry>) - similar to addExampleButton.setOnAction(...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please try to keep the file in jablib. Report back if you cannot load it.

khushp3 added 3 commits May 11, 2025 12:29
- Passes each entry in "Chocolate.bib"
- Creates an empty database object
- Inserts the entries into the database
- Wraps the database in BibDatabaseContext
- Creates a new library tab with the data loaded from "Chocolate.bib"
@khushp3 khushp3 requested a review from koppor May 12, 2025 14:42
@koppor

koppor commented May 12, 2025

Copy link
Copy Markdown
Member

@khushp3 please do not request a review before you have addressed the issues risen by the tests

Comment on lines +146 to +152
BibtexParser bibtexParser = new BibtexParser(preferences.getImportFormatPreferences(), fileUpdateMonitor);
List<BibEntry> entries = bibtexParser.parseEntries(in);

BibDatabase database = new BibDatabase();
database.insertEntries(entries);

BibDatabaseContext databaseContext = new BibDatabaseContext(database);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seeing this, there is a more simpler way:

Suggested change
BibtexParser bibtexParser = new BibtexParser(preferences.getImportFormatPreferences(), fileUpdateMonitor);
List<BibEntry> entries = bibtexParser.parseEntries(in);
BibDatabase database = new BibDatabase();
database.insertEntries(entries);
BibDatabaseContext databaseContext = new BibDatabaseContext(database);
reader = Importer.getReader(inputStream);
BibtexParser bibtexParser = new BibtexParser(preferences.getImportFormatPreferences(), fileUpdateMonitor);
ParserResult result = bibtexParser.parse(reader);
BibDatabaseContext databaseContext = result.getDatabaseContext();

I found simlar code in org.jabref.logic.importer.fileformat.BibtexParser

Comment on lines +137 to +171
fileHistoryMenu.getItems().addListener((ListChangeListener<MenuItem>) _ -> updateWelcomeRecentLibraries());
fileHistoryMenu.getItems().addListener((ListChangeListener<MenuItem>) e -> updateWelcomeRecentLibraries());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this change AI generated? Please keep _

Comment thread jabgui/src/main/java/org/jabref/gui/WelcomeTab.java
@koppor koppor mentioned this pull request May 15, 2025
1 task
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.util.FileUpdateMonitor;

import static org.jabref.gui.edit.automaticfiededitor.AbstractAutomaticFieldEditorTabViewModel.LOGGER;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy and paste issue - see https://devdocs.jabref.org/code-howtos/logging.html how to initialize the logger

Comment on lines +145 to +146
Reader reader;
reader = Importer.getReader(in);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Merge in one line; you can even move it up into the try braces

taskExecutor).execute());

return createVBoxContainer(startLabel, newLibraryLink, openLibraryLink);
Hyperlink openExampleLibraryLink = new Hyperlink(Localization.lang("Open example library"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. The string should be New example library
  2. Rename "New library" to "New empty library"
  3. position it one above, so that the order is
  • New empty library
  • New example library
  • Open library

Comment thread jabgui/src/main/java/org/jabref/gui/WelcomeTab.java
…d JabRef_en.properties

- Correctly imported LOGGER
Comment thread jabgui/src/main/java/org/jabref/gui/WelcomeTab.java
Comment thread jabgui/src/main/java/org/jabref/gui/WelcomeTab.java
RELEVANCE(Localization.lang("Relevance"), IconTheme.JabRefIcons.RELEVANCE),
RELEVANT(Localization.lang("Toggle relevance"), IconTheme.JabRefIcons.RELEVANCE),
NEW_LIBRARY(Localization.lang("New library"), IconTheme.JabRefIcons.NEW),
NEW_LIBRARY(Localization.lang("New empty library"), IconTheme.JabRefIcons.NEW),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The change from 'New library' to 'New empty library' should be consistent with other strings and grouped semantically. Ensure that similar actions use consistent terminology.

Comment thread jablib/src/main/resources/l10n/JabRef_en.properties Outdated
@koppor koppor marked this pull request as ready for review May 15, 2025 15:01
@koppor koppor enabled auto-merge May 15, 2025 15:01
@koppor

koppor commented May 15, 2025

Copy link
Copy Markdown
Member

I fixed the small test issues (wrong variable order and translation strings)

Now, it is good to go.

Thank you for the efforts!

@trag-bot

trag-bot Bot commented May 15, 2025

Copy link
Copy Markdown

@trag-bot didn't find any issues in the code! ✅✨

1 similar comment
@trag-bot

trag-bot Bot commented May 15, 2025

Copy link
Copy Markdown

@trag-bot didn't find any issues in the code! ✅✨

@koppor koppor added this pull request to the merge queue May 15, 2025
Merged via the queue into JabRef:main with commit dca5cd5 May 15, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Welcome Tab: "Open example library"

3 participants