Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.gui.fieldeditors.identifier;

import java.util.Optional;
import java.util.stream.Stream;

import javax.swing.undo.UndoManager;

Expand All @@ -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;
Expand Down Expand Up @@ -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());
Copy link
Member

Choose a reason for hiding this comment

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

Did someone understand what "lookup" means?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I misunderstood the behavior and took the word “hide” literally.
I also understand that “lookup” should work even when there is no DOI, by searching online.

I can change the code to disable instead of hide. Is this what you mean?

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for the offer. Your past PR needed more than 10 comments of two different maintainers. Still the code did not work. Your code is just hacky - and did not build on existing (!) JavaFX code. Thus, we should save the time of both you and the team. -- In future, please first read around at the code base. The IdentifierEditor is a very nice example to learn about JavaFX bindings and general UI principles in JavaFX. You missed this opportunity.

I already fixed it at #14931.

button.managedProperty().bind(button.visibleProperty());
});

shortenDOIButton.managedProperty().bind(shortenDOIButton.visibleProperty());
Copy link
Member

Choose a reason for hiding this comment

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

The code totally overlooked org.jabref.gui.fieldeditors.identifier.BaseIdentifierEditorViewModel#canShortenIdentifier

if (StandardField.DOI.equals(field)) {
shortenDOIButton.visibleProperty().bind(viewModel.textProperty().isNotEmpty());
} else {
shortenDOIButton.visibleProperty().unbind();
shortenDOIButton.setVisible(false);
}
}

public BaseIdentifierEditorViewModel<?> getViewModel() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}