diff --git a/CHANGELOG.md b/CHANGELOG.md index d0e68618dd9..ae48af1b9ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv ### Fixed +- Fixed redundant action icons showing in empty identifier fields (DOI, Eprint, ISBN) [#14821](https://github.com/JabRef/jabref/pull/14821) - Fixed localized walkthrough highlight for 'Preferences' menu item. [#14822](https://github.com/JabRef/jabref/issues/14822) - We Improved detection of arXiv identifiers when pasting arXiv URLs that include URL fragments. [#14659](https://github.com/JabRef/jabref/issues/14659) - We fixed an error on startup when using portable preferences. [#14729](https://github.com/JabRef/jabref/issues/14729) diff --git a/jabgui/src/main/java/org/jabref/gui/fieldeditors/identifier/IdentifierEditor.java b/jabgui/src/main/java/org/jabref/gui/fieldeditors/identifier/IdentifierEditor.java index 4622cc37673..2c0d07c478d 100644 --- a/jabgui/src/main/java/org/jabref/gui/fieldeditors/identifier/IdentifierEditor.java +++ b/jabgui/src/main/java/org/jabref/gui/fieldeditors/identifier/IdentifierEditor.java @@ -1,6 +1,7 @@ package org.jabref.gui.fieldeditors.identifier; import java.util.Optional; +import java.util.stream.Stream; import javax.swing.undo.UndoManager; @@ -24,6 +25,7 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldTextMapper; +import org.jabref.model.entry.field.StandardField; import com.airhacks.afterburner.injection.Injector; import com.airhacks.afterburner.views.ViewLoader; @@ -91,6 +93,20 @@ public IdentifierEditor(Field field, textField.initContextMenu(new DefaultMenu(textField), preferences.getKeyBindingRepository()); new EditorValidator(preferences).configureValidation(viewModel.getFieldValidator().getValidationStatus(), textField); + + Stream.of(fetchInformationByIdentifierButton, lookupIdentifierButton) + .forEach(button -> { + button.visibleProperty().bind(viewModel.textProperty().isNotEmpty()); + button.managedProperty().bind(button.visibleProperty()); + }); + + shortenDOIButton.managedProperty().bind(shortenDOIButton.visibleProperty()); + if (StandardField.DOI.equals(field)) { + shortenDOIButton.visibleProperty().bind(viewModel.textProperty().isNotEmpty()); + } else { + shortenDOIButton.visibleProperty().unbind(); + shortenDOIButton.setVisible(false); + } } public BaseIdentifierEditorViewModel getViewModel() { diff --git a/jabgui/src/test/java/org/jabref/gui/fieldeditors/identifier/IdentifierEditorTest.java b/jabgui/src/test/java/org/jabref/gui/fieldeditors/identifier/IdentifierEditorTest.java new file mode 100644 index 00000000000..6fd4bac9ee8 --- /dev/null +++ b/jabgui/src/test/java/org/jabref/gui/fieldeditors/identifier/IdentifierEditorTest.java @@ -0,0 +1,47 @@ +package org.jabref.gui.fieldeditors.identifier; + +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.layout.HBox; +import javafx.stage.Stage; + +import org.jabref.gui.fieldeditors.EditorTextField; + +import org.junit.jupiter.api.Test; +import org.testfx.api.FxAssert; +import org.testfx.framework.junit5.ApplicationTest; +import org.testfx.matcher.base.NodeMatchers; + +class IdentifierEditorTest extends ApplicationTest { + + private Button fetchButton; + private EditorTextField textField; + + @Override + public void start(Stage stage) { + fetchButton = new Button(); + fetchButton.setId("fetchInformationByIdentifierButton"); + textField = new EditorTextField(); + textField.setId("textField"); + textField.setText(""); + + fetchButton.visibleProperty().bind(textField.textProperty().isNotEmpty()); + fetchButton.managedProperty().bind(fetchButton.visibleProperty()); + + HBox root = new HBox(textField, fetchButton); + stage.setScene(new Scene(root, 400, 100)); + stage.show(); + } + + @Test + void fetchButtonTogglesVisibilityBasedOnText() { + interact(() -> textField.setText("")); + FxAssert.verifyThat("#fetchInformationByIdentifierButton", NodeMatchers.isInvisible()); + + clickOn(textField).write("10.1001/jama.2017.18444"); + FxAssert.verifyThat("#fetchInformationByIdentifierButton", NodeMatchers.isVisible()); + + interact(() -> textField.setText("")); + FxAssert.verifyThat("#fetchInformationByIdentifierButton", NodeMatchers.isInvisible()); + } +}