Skip to content

Conversation

@atul-raman
Copy link
Contributor

@atul-raman atul-raman commented Dec 19, 2025

Closes #14660

This PR fixes issue #14660 by implementing automatic identifier type detection when a user types in the identifier field of the "New Entry" dialog. The identifier type dropdown now automatically updates to reflect the detected type (arXiv, DOI, ISBN, etc.) as the user types, but only when "Automatically determine identifier type" is selected.

Steps to test

  1. Open JabRef and create/open a library
  2. Go to Entry → New Entry...
  3. Click the "Enter Identifier" tab
  4. Ensure "Automatically determine identifier type" is selected
  5. Type 2503.08641v1 in the identifier field
  6. The "Identifier type" dropdown should automatically change to "arXiv"
  7. Test with other identifiers:
    • Type 10.1234/example → should detect "DOI"
    • Type an ISBN → should detect "ISBN"
  8. Test mode switching: Switch to "Identifier type" mode, then back to "Automatically determine" → should detect identifier from current text

Mandatory checks

Changes

  • Added ChangeListener to identifier input field (idText) to detect identifier type on input
  • Automatically updates idFetcher ComboBox when valid identifier is detected
  • Only updates when "Automatically determine identifier type" is selected
  • Also detects identifier type when switching to auto-detect mode
  • Handles arXiv, DOI, ISBN, RFC, and SSRN identifier types
  • Extracted identifier validation logic into isValidIdentifier() method to avoid code duplication
  • Validates DOI and ISBN identifiers before updating fetcher

- Add ChangeListener to idText field to detect identifier type on input
- Automatically update idFetcher ComboBox when valid identifier is detected
- Only updates when 'Automatically determine identifier type' is selected
- Also detects identifier type when switching to auto-detect mode
- Handles arXiv, DOI, ISBN, RFC, and SSRN identifier types
- Validates DOI and ISBN identifiers before updating fetcher

Fixes JabRef#14660
@github-actions github-actions bot added good first issue An issue intended for project-newcomers. Varies in difficulty. status: changes-required Pull requests that are not yet complete labels Dec 19, 2025
Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

Please do not duplciate code. Try to extract functionality from org.jabref.gui.newentry.NewEntryView#extractValidIdentifierFromClipboard - I think, lines 661 to the end can be a seperate method?

Comment on lines 326 to 339
if (newValue && idText.getText() != null && !idText.getText().trim().isEmpty()) {
Optional<Identifier> identifier = Identifier.from(idText.getText().trim());
if (identifier.isPresent()) {
Identifier id = identifier.get();
boolean isValid = switch (id) {
case DOI doi -> DOI.isValid(doi.asString());
case ISBN isbn -> isbn.isValid();
default -> true;
};
if (isValid) {
fetcherForIdentifier(id).ifPresent(idFetcher::setValue);
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Try to reduce code duplication

- Extract identifier validation logic into isValidIdentifier() method
- Use the extracted method in both listeners and extractValidIdentifierFromClipboard()
- Reduces code duplication as requested in review

Addresses review feedback on PR JabRef#14662
Comment on lines 92 to 131
@Inject private StateManager stateManager;
@Inject private TaskExecutor taskExecutor;
@Inject private AiService aiService;
@Inject private FileUpdateMonitor fileUpdateMonitor;
@Inject
private StateManager stateManager;
@Inject
private TaskExecutor taskExecutor;
@Inject
private AiService aiService;
@Inject
private FileUpdateMonitor fileUpdateMonitor;

private final ControlsFxVisualizer visualizer;

@FXML private ButtonType generateButtonType;
@FXML
private ButtonType generateButtonType;
private Button generateButton;

@FXML private TabPane tabs;
@FXML private Tab tabAddEntry;
@FXML private Tab tabLookupIdentifier;
@FXML private Tab tabInterpretCitations;
@FXML private Tab tabSpecifyBibtex;

@FXML private TitledPane entryRecommendedTitle;
@FXML private TilePane entryRecommended;
@FXML private TitledPane entryOtherTitle;
@FXML private TilePane entryOther;
@FXML private TitledPane entryCustomTitle;
@FXML private TilePane entryCustom;
@FXML private TitledPane entryNonStandardTitle;
@FXML private TilePane entryNonStandard;

@FXML private TextField idText;
@FXML private Tooltip idTextTooltip;
@FXML private Hyperlink idJumpLink;
@FXML private RadioButton idLookupGuess;
@FXML private RadioButton idLookupSpecify;
@FXML private ComboBox<IdBasedFetcher> idFetcher;
@FXML private Label idErrorInvalidText;
@FXML private Label idErrorInvalidFetcher;

@FXML private TextArea interpretText;
@FXML private ComboBox<PlainCitationParserChoice> interpretParser;

@FXML private TextArea bibtexText;
@FXML
private TabPane tabs;
@FXML
private Tab tabAddEntry;
@FXML
private Tab tabLookupIdentifier;
@FXML
private Tab tabInterpretCitations;
@FXML
private Tab tabSpecifyBibtex;

@FXML
private TitledPane entryRecommendedTitle;
@FXML
private TilePane entryRecommended;
@FXML
private TitledPane entryOtherTitle;
@FXML
private TilePane entryOther;
@FXML
private TitledPane entryCustomTitle;
@FXML
private TilePane entryCustom;
@FXML
private TitledPane entryNonStandardTitle;
Copy link
Member

Choose a reason for hiding this comment

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

NO, PLEASE NOT

DO NOT REFORMAT. TELL YOUR AI!!!!!!

The previous formatting commit reformatted the entire file including unrelated code.
This reverts those changes. Only the new code we added should be formatted if needed.
@atul-raman
Copy link
Contributor Author

Hi @koppor,

I see the format check is failing, but you said not to reformat the entire file.
The code I added looks like it's correctly formatted. Could you please let me know what you'd like me to do? I want to make sure I follow the project's guidelines correctly. Thanks!

@koppor
Copy link
Member

koppor commented Dec 23, 2025

I see the format check is failing, but you said not to reformat the entire file. The code I added looks like it's correctly formatted. Could you please let me know what you'd like me to do? I want to make sure I follow the project's guidelines correctly. Thanks!

Check the output

image

Reformat that part

You can mark the lines and then press Ctrl+Shift+F

Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

Changelog?

idLookupGuess.selectedProperty().addListener((_, _, newValue) -> {
preferences.setIdLookupGuessing(newValue);
// When switching to auto-detect mode, detect identifier type from current text
if (newValue && idText.getText() != null && !idText.getText().trim().isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

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

null checks are from AI

did you check if this really happens????

You can use LOGGER for that


// Auto-detect identifier type when typing in the identifier field
// Only works when "Automatically determine identifier type" is selected
idText.textProperty().addListener((observable, oldValue, newValue) -> {
Copy link
Member

Choose a reason for hiding this comment

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

ai, ai, ai

Open in IntelliJ and see that observable is never used.

@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Dec 24, 2025
@koppor koppor added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Dec 24, 2025
@palukku
Copy link
Member

palukku commented Dec 28, 2025

image Idk if its supposed to work but when trying with the link that is written in the issue (`https://arxiv.org/html/2503.08641v1#bib.bib5`) it is not switching to the correct identifier type.

Only when typing 2503.08641v1 it works

Fixes issue where URLs with fragments (e.g., https://arxiv.org/html/2503.08641v1#bib.bib5)
were not being detected. The cleanIdentifierText() method now strips fragments
and query parameters before identifier parsing.
@github-actions github-actions bot added status: changes-required Pull requests that are not yet complete and removed status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers labels Dec 28, 2025
@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Dec 28, 2025
@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Dec 29, 2025
- Removed cleanIdentifierText() method as Identifier.from() already handles parsing
- Extracted duplicate identifier detection logic into updateFetcherFromIdentifierText() helper method
- Updated both listeners to use the shared helper method
- Updated extractValidIdentifierFromClipboard() to use Identifier.from() directly

Addresses reviewer feedback on code duplication and approach.
@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Dec 29, 2025
@atul-raman atul-raman requested a review from koppor December 29, 2025 03:23
@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Dec 29, 2025
The reviewer's refactoring left an incomplete switch statement that caused
a compilation error. Removed the broken code to restore compilation.
@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Dec 29, 2025
The JavaDoc parser doesn't recognize @returns. Changed to @return
and converted to proper JavaDoc comment format.
@koppor
Copy link
Member

koppor commented Dec 29, 2025

@atul-raman Thank you for updating. I am following the Boy Scout Rule to improve the whole dialog. Will take some more time.

Do not delete TODOs by me - even if code does not compile.

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Dec 29, 2025
@koppor koppor force-pushed the fix/identifier-type-auto-detect-14660 branch from 709b914 to e60a295 Compare December 30, 2025 19:17
@koppor
Copy link
Member

koppor commented Dec 30, 2025

@atul-raman if you fix something, please fix it and do not introduce new errors (your last commit introduced a wrong space)

I will merge as is and finish in a separte PR.

Thank you for your efforts so far.

@koppor koppor enabled auto-merge December 30, 2025 19:19
@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Dec 30, 2025
@koppor koppor added this pull request to the merge queue Dec 30, 2025
Merged via the queue into JabRef:main with commit 9256d8b Dec 30, 2025
49 checks passed
koppor added a commit that referenced this pull request Dec 30, 2025
@koppor koppor mentioned this pull request Dec 30, 2025
3 tasks
koppor added a commit that referenced this pull request Jan 12, 2026
github-merge-queue bot pushed a commit that referenced this pull request Jan 18, 2026
* Fix: Auto-detect identifier type when typing in identifier field

- Add ChangeListener to idText field to detect identifier type on input
- Automatically update idFetcher ComboBox when valid identifier is detected
- Only updates when 'Automatically determine identifier type' is selected
- Also detects identifier type when switching to auto-detect mode
- Handles arXiv, DOI, ISBN, RFC, and SSRN identifier types
- Validates DOI and ISBN identifiers before updating fetcher

Fixes #14660

* Refactor: Extract identifier validation to avoid code duplication

- Extract identifier validation logic into isValidIdentifier() method
- Use the extracted method in both listeners and extractValidIdentifierFromClipboard()
- Reduces code duplication as requested in review

Addresses review feedback on PR #14662

* Format code according to JabRef style guidelines

* Revert formatting commit - only format changed code, not entire file

The previous formatting commit reformatted the entire file including unrelated code.
This reverts those changes. Only the new code we added should be formatted if needed.

* Fix: Remove unnecessary null checks and unused parameters

- Remove unnecessary null checks (idText.getText() and newValue)
- Replace unused 'observable' parameter with '_'
- Format code according to project guidelines
- Add changelog entry

Addresses review feedback on PR #14662

* Fix syntax error in fetcherForIdentifier method

* Format isValidIdentifier switch statement to match project style

* Fix: Handle URL fragments and query parameters in identifier detection

Fixes issue where URLs with fragments (e.g., https://arxiv.org/html/2503.08641v1#bib.bib5)
were not being detected. The cleanIdentifierText() method now strips fragments
and query parameters before identifier parsing.

* Fix CHANGELOG entry format to match origin/main style

* Fix CHANGELOG entry placement and format to match Unreleased section style

* Refactor: Remove cleanIdentifierText and extract duplicate logic

- Removed cleanIdentifierText() method as Identifier.from() already handles parsing
- Extracted duplicate identifier detection logic into updateFetcherFromIdentifierText() helper method
- Updated both listeners to use the shared helper method
- Updated extractValidIdentifierFromClipboard() to use Identifier.from() directly

Addresses reviewer feedback on code duplication and approach.

* Refine JavaDoc

* Fix DOI validation and removes obsolete code

* Fix CHANGELOG.md

* More Optional syntax

* WIP

* Fix: Remove incomplete switch statement causing compilation error

The reviewer's refactoring left an incomplete switch statement that caused
a compilation error. Removed the broken code to restore compilation.

* Fix: Correct JavaDoc tag from @returns to @return

The JavaDoc parser doesn't recognize @returns. Changed to @return
and converted to proper JavaDoc comment format.

* Revert "Fix: Remove incomplete switch statement causing compilation error"

This reverts commit d4f3c71.

* Restore reviewer's TODO comment that was accidentally removed

The TODO comment from the reviewer was removed when fixing the compilation
error. Restored it as requested by the reviewer.

* Cache searchBasedFetchers

* WIP

* Add simple route

* Wire SsrnFetcher

* Streamline code in composite id fetcher

* Fix typo

* Refine variables

* Sort alphabetically

* Fix formatting

* Fix indent

* Fix unused imports

* Refine returned fetchers

* fix faliing fetcher test

* Fix composite fetcher

* Fix checkstyle location

* Add static

* Use .toList()

* More alphabet...

---------

Co-authored-by: atulrcrosslake <[email protected]>
Co-authored-by: Atul Raman <[email protected]>
Co-authored-by: Christoph <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: import-load good first issue An issue intended for project-newcomers. Varies in difficulty.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typing in identifier field should change type

5 participants