Skip to content

Keyword Tooltip/Cleanup for MSC codes added to Keyword Editor #12914

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

Open
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

JustinHennis1
Copy link

@JustinHennis1 JustinHennis1 commented Apr 9, 2025

Closes #12944

Created a JSON file to hold key-value pairs of MSC codes to their respective descriptions/classifications by parsing msc_2020.pdf (which was provided in link to zbmath).

Created MscCodeUtils.java class that implements a method to load a JSON file and converts said file into a Map object.

Created ConvertMSCCodesCleanupTest.java, added to panel, and when user selects preference to convert and saves, the codes are converted to descriptions. Alternatively, when unselected, descriptions are reverted back to code.

In KeywordsEditor.java I added a private variable, mscmap, that calls the above method. Using this map object, I added a condition in the create tag method to check if the label text matches any of the keys. If it does, then we initialize a Tooltip and call install onMouseEnter and uninstall onMouseExited.

ToolTip

Screenshot (18)
Screenshot (19)

Cleanup

Before:

jabref_cleanup

After:

jabrefcleanup2

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.

@@ -50,6 +55,8 @@ public class KeywordsEditor extends HBox implements FieldEditorFX {
private static final Logger LOGGER = LoggerFactory.getLogger(KeywordsEditor.class);
private static final PseudoClass FOCUSED = PseudoClass.getPseudoClass("focused");

private Map<String, String> mscmap = MscCodeUtils.loadMscCodesFromJson("../../resources/main/org/jabref/gui/fieldeditors/msccodes/msc_codes.json");
Copy link
Member

Choose a reason for hiding this comment

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

This won't work inside a jar, you need to use class.getResource

@JustinHennis1 JustinHennis1 reopened this Apr 10, 2025
@Siedlerchr
Copy link
Member

Please fix the failing tests before. This reduces the burden of us maintainers to review incomplete PRs

…iptions, bug: error when trying to cleanup when editor is open
@JustinHennis1 JustinHennis1 reopened this Apr 14, 2025
@@ -114,7 +114,8 @@ private boolean doCleanup(BibDatabaseContext databaseContext, CleanupPreferences
CleanupWorker cleaner = new CleanupWorker(
databaseContext,
preferences.getFilePreferences(),
preferences.getTimestampPreferences()
preferences.getTimestampPreferences(),
preferences.getBibEntryPreferences()
Copy link

Choose a reason for hiding this comment

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

The addition of preferences.getBibEntryPreferences() to the CleanupWorker constructor requires updating the JavaDoc for doCleanup method to reflect this change in parameters.

@jabref-machine
Copy link
Collaborator

Your pull request needs to link an issue.

To ease organizational workflows, please link this pull-request to the issue with syntax as described in https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue:

Linking a pull request to an issue using a keyword

You can link a pull request to an issue by using a supported keyword in the pull request's description or in a commit message. The pull request must be on the default branch.

  • close
  • closes
  • closed
  • fix
  • fixes
  • fixed
  • resolve
  • resolves
  • resolved

If you use a keyword to reference a pull request comment in another pull request, the pull requests will be linked. Merging the referencing pull request also closes the referenced pull request.

The syntax for closing keywords depends on whether the issue is in the same repository as the pull request.

Examples

  • Fixes #xyz links pull-request to issue. Merging the PR will close the issue.
  • Fixes https://github.com/JabRef/jabref/issues/xyz links pull-request to issue. Merging the PR will close the issue.
  • Fixes https://github.com/Koppor/jabref/issues/xyz links pull-request to issue. Merging the PR will close the issue.
  • Fixes [#xyz](https://github.com/JabRef/jabref/issues/xyz) links pull-request to issue. Merging the PR will NOT close the issue.

@JustinHennis1 JustinHennis1 changed the title Keyword Tooltip for MSC codes added to Keyword Editor Keyword Tooltip/Cleanup for MSC codes added to Keyword Editor Apr 16, 2025
@JustinHennis1 JustinHennis1 marked this pull request as draft April 16, 2025 00:24
@JustinHennis1 JustinHennis1 marked this pull request as ready for review April 16, 2025 23:49
URL resourceUrl = ConvertMSCCodesCleanup.class.getClassLoader().getResource("msc_codes.json");

if (resourceUrl == null) {
logger.error("Resource not found: msc_codes.json");
Copy link

Choose a reason for hiding this comment

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

User-facing text should be localized using Localization.lang method to support multilingual capabilities.

conversionPossible = false;
}
} catch (MscCodeLoadingException e) {
logger.error("Error loading MSC codes:", e);
Copy link

Choose a reason for hiding this comment

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

User-facing text should be localized using Localization.lang method to support multilingual capabilities.

@Override
public List<FieldChange> cleanup(BibEntry entry) {
if (!conversionPossible) {
logger.error("MSC code conversion was attempted but is not possible because the codes file could not be loaded");
Copy link

Choose a reason for hiding this comment

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

User-facing text should be localized using Localization.lang method to support multilingual capabilities.


return Optional.of(result);
} catch (JsonParseException | JsonMappingException e) {
LOGGER.error("Error parsing MSC codes from JSON", e);
Copy link

Choose a reason for hiding this comment

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

The logging of exceptions is done correctly using the exception logging capabilities. Ensure this pattern is consistently applied across the codebase.

Copy link

trag-bot bot commented Apr 18, 2025

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

private final boolean convertToDescriptions;

static {
Map<String, String> tempMap = new HashMap<>();
Copy link
Member

Choose a reason for hiding this comment

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

You could make use of Guavas BiMap that does the "reverse" mapping then for you

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.

Add Mathematics Subject Classification as tooltip to keywords
3 participants