From 2a4d378f4a3d87a1b45b774c00550d47020c0597 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Mon, 25 Sep 2023 00:46:20 +0100 Subject: [PATCH 01/41] change name to extension comparison in fromString and toStringList --- .../jabref/gui/externalfiletype/ExternalFileTypes.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java index c3a7ebf3d46..25e2bfaa088 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java @@ -148,10 +148,10 @@ public static String toStringList(Collection fileTypes) { for (ExternalFileType type : fileTypes) { results.add(type); - // See if we can find a type with matching name in the default type list: + // See if we can find a type with matching extension in the default type list: ExternalFileType found = null; for (ExternalFileType defType : defTypes) { - if (defType.getName().equals(type.getName())) { + if (defType.getExtension().equals(type.getExtension())) { found = defType; break; } @@ -221,11 +221,11 @@ public static Set fromString(String storedFileTypes) { } else { // A new or modified entry type. Construct it from the string array: ExternalFileType type = CustomExternalFileType.buildFromArgs(val); - // Check if there is a default type with the same name. If so, this is a + // Check if there is a default type with the same extension. If so, this is a // modification of that type, so remove the default one: ExternalFileType toRemove = null; for (ExternalFileType defType : types) { - if (type.getName().equals(defType.getName())) { + if (type.getExtension().equals(defType.getExtension())) { toRemove = defType; break; } From 7187b699659dcf464d5b88e626e8c45f8eb20b30 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Sun, 8 Oct 2023 19:30:07 +0100 Subject: [PATCH 02/41] fix problem of abort button still add external file type entry in EditExternalFileTypeEntryDialog class --- .../externalfiletypes/EditExternalFileTypeEntryDialog.java | 6 ++++++ .../externalfiletypes/ExternalFileTypesTabViewModel.java | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java index e5aa3e55c03..5799a73cd1b 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java @@ -36,9 +36,12 @@ public class EditExternalFileTypeEntryDialog extends BaseDialog { private final ExternalFileTypeItemViewModel item; + private final boolean isNewItem; private EditExternalFileTypeViewModel viewModel; public EditExternalFileTypeEntryDialog(ExternalFileTypeItemViewModel item, String dialogTitle) { + this.isNewItem = (item.extensionProperty().get().equals("")) ? true : false; + this.item = item; this.setTitle(dialogTitle); @@ -50,6 +53,8 @@ public EditExternalFileTypeEntryDialog(ExternalFileTypeItemViewModel item, Strin this.setResultConverter(button -> { if (button == ButtonType.OK) { viewModel.storeSettings(); + } else { + name.setText(""); } return null; }); @@ -67,6 +72,7 @@ public void initialize() { btnBrowse.disableProperty().bind(viewModel.defaultApplicationSelectedProperty()); extension.textProperty().bindBidirectional(viewModel.extensionProperty()); + extension.setEditable(isNewItem); name.textProperty().bindBidirectional(viewModel.nameProperty()); mimeType.textProperty().bindBidirectional(viewModel.mimeTypeProperty()); selectedApplication.textProperty().bindBidirectional(viewModel.selectedApplicationProperty()); diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java index b61818105f0..817e930b382 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java @@ -56,8 +56,10 @@ public void resetToDefaults() { public void addNewType() { ExternalFileTypeItemViewModel item = new ExternalFileTypeItemViewModel(); - fileTypes.add(item); showEditDialog(item, Localization.lang("Add new file type")); + if (item.getName() != "") { + fileTypes.add(item); + } } public ObservableList getFileTypes() { From 341c52c66ee3125da260e0b9135d166183d0ae6f Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Sun, 15 Oct 2023 11:37:06 +0100 Subject: [PATCH 03/41] Block the Close action of EditExternalFileTypeEntryDialog when value empty --- .../EditExternalFileTypeEntryDialog.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java index 5799a73cd1b..5841a143965 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java @@ -50,6 +50,13 @@ public EditExternalFileTypeEntryDialog(ExternalFileTypeItemViewModel item, Strin .load() .setAsDialogPane(this); + final Button btOk = (Button) this.getDialogPane().lookupButton(ButtonType.OK); + btOk.addEventFilter(ActionEvent.ACTION, event -> { + if (!isValidExternalFileTypeEntry()) { + event.consume(); + } + }); + this.setResultConverter(button -> { if (button == ButtonType.OK) { viewModel.storeSettings(); @@ -60,6 +67,16 @@ public EditExternalFileTypeEntryDialog(ExternalFileTypeItemViewModel item, Strin }); } + public boolean isValidExternalFileTypeEntry() { + if (name.getText().trim().equalsIgnoreCase("") + || extension.getText().trim().equalsIgnoreCase("") + || mimeType.getText().trim().equalsIgnoreCase("") + ) { + return false; + } + return true; + } + @FXML public void initialize() { viewModel = new EditExternalFileTypeViewModel(item); From f7cc511e22006fc995acc46c945e161931a4f320 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Sun, 15 Oct 2023 13:12:39 +0100 Subject: [PATCH 04/41] ExternalFileTypesTab only scroll to bottom when new fileType added successfully --- .../externalfiletypes/ExternalFileTypesTab.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTab.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTab.java index b131484ddc3..cd358279445 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTab.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTab.java @@ -88,9 +88,12 @@ public void initialize() { @FXML private void addNewType() { + int fileTypeCount = fileTypesTable.getItems().size(); viewModel.addNewType(); - fileTypesTable.getSelectionModel().selectLast(); - fileTypesTable.scrollTo(viewModel.getFileTypes().size() - 1); + if (fileTypeCount < fileTypesTable.getItems().size()) { + fileTypesTable.getSelectionModel().selectLast(); + fileTypesTable.scrollTo(viewModel.getFileTypes().size() - 1); + } } @FXML From f6166c02043e122c13fadc2c4881175cc4767e7f Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Sun, 15 Oct 2023 15:47:32 +0100 Subject: [PATCH 05/41] check if external file type exists then cannot add a new one --- .../ExternalFileTypesTabViewModel.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java index 817e930b382..d21fd494300 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java @@ -57,9 +57,19 @@ public void resetToDefaults() { public void addNewType() { ExternalFileTypeItemViewModel item = new ExternalFileTypeItemViewModel(); showEditDialog(item, Localization.lang("Add new file type")); - if (item.getName() != "") { - fileTypes.add(item); + + if (item.getName() == "") { + return; + } + + String newExt = item.extensionProperty().get(); + for (ExternalFileTypeItemViewModel fileTypeItem : fileTypes) { + if (newExt.equalsIgnoreCase(fileTypeItem.extensionProperty().get())) { + return; + } } + + fileTypes.add(item); } public ObservableList getFileTypes() { From 5fe6df9844b43c3c8ed52f1171dad48859fbdf3c Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Thu, 19 Oct 2023 01:41:34 +0100 Subject: [PATCH 06/41] update changelog.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d77a4fdd04..0e15d9e269c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where exporting "Embedded BibTeX pdf" without selecting an existing document would produce an exception. [#10101](https://github.com/JabRef/jabref/issues/10101) - We fixed an issue where it was not possible to connect to a shared database once a group with entries was added or other metadata modified [#10336](https://github.com/JabRef/jabref/issues/10336) - We fixed an issue where middle-button paste in X not always worked [#7905](https://github.com/JabRef/jabref/issues/7905) +- We fixed issues where in 1) preferences: external file type duplicates when change languages. [#10271] (https://github.com/JabRef/jabref/issues/10271) 2) Cancel button only close EditExternalFileTypeEntryDialog without further action 3) Missed value in EditExternalFileTypeEntryDialog cannot close dialog even OK button clicked 4) Cannot save new External File Type if it extension exists already ### Removed From f0b21d02bc32352d924f96c37ac5d56997ea8a33 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Sat, 21 Oct 2023 00:41:54 +0100 Subject: [PATCH 07/41] reformat the new entry in CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e0d07244e0..49d454e0017 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,7 +56,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where there was a failure to access the url link for "eprint" for the ArXiv entry.[#10474](https://github.com/JabRef/jabref/issues/10474) - We fixed an issue where it was not possible to connect to a shared database once a group with entries was added or other metadata modified [#10336](https://github.com/JabRef/jabref/issues/10336) - We fixed an issue where middle-button paste in X not always worked [#7905](https://github.com/JabRef/jabref/issues/7905) -- We fixed issues where in 1) preferences: external file type duplicates when change languages. [#10271] (https://github.com/JabRef/jabref/issues/10271) 2) Cancel button only close EditExternalFileTypeEntryDialog without further action 3) Missed value in EditExternalFileTypeEntryDialog cannot close dialog even OK button clicked 4) Cannot save new External File Type if it extension exists already +- We fixed issues where in 1) preferences: external file type duplicates when change languages. [#10271](https://github.com/JabRef/jabref/issues/10271) 2) Cancel button only close EditExternalFileTypeEntryDialog without further action 3) Missed value in EditExternalFileTypeEntryDialog cannot close dialog even OK button clicked 4) Cannot save new External File Type if it extension exists already ### Removed From a84d4da72b3064553ee568a852fc3446fd603baa Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Sun, 22 Oct 2023 17:21:56 +0100 Subject: [PATCH 08/41] added ExternalFileTypesTabViewModelTest and run rewriteRun --- .../EditExternalFileTypeEntryDialog.java | 10 +-- .../ExternalFileTypesTabViewModel.java | 2 +- .../ExternalFileTypesTabViewModelTest.java | 67 +++++++++++++++++++ 3 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java index 5841a143965..f205bf09825 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java @@ -40,7 +40,7 @@ public class EditExternalFileTypeEntryDialog extends BaseDialog { private EditExternalFileTypeViewModel viewModel; public EditExternalFileTypeEntryDialog(ExternalFileTypeItemViewModel item, String dialogTitle) { - this.isNewItem = (item.extensionProperty().get().equals("")) ? true : false; + this.isNewItem = item.extensionProperty().get().equals(""); this.item = item; @@ -68,13 +68,9 @@ public EditExternalFileTypeEntryDialog(ExternalFileTypeItemViewModel item, Strin } public boolean isValidExternalFileTypeEntry() { - if (name.getText().trim().equalsIgnoreCase("") + return !(name.getText().trim().equalsIgnoreCase("") || extension.getText().trim().equalsIgnoreCase("") - || mimeType.getText().trim().equalsIgnoreCase("") - ) { - return false; - } - return true; + || mimeType.getText().trim().equalsIgnoreCase("")); } @FXML diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java index d21fd494300..2dbd2c24edb 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java @@ -58,7 +58,7 @@ public void addNewType() { ExternalFileTypeItemViewModel item = new ExternalFileTypeItemViewModel(); showEditDialog(item, Localization.lang("Add new file type")); - if (item.getName() == "") { + if ("".equals(item.getName())) { return; } diff --git a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java new file mode 100644 index 00000000000..77a66fb26bb --- /dev/null +++ b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java @@ -0,0 +1,67 @@ +package org.jabref.gui.preferences.externalfiletypes; + +import java.util.Set; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + +import org.jabref.gui.externalfiletype.ExternalFileType; +import org.jabref.gui.externalfiletype.StandardExternalFileType; +import org.jabref.preferences.FilePreferences; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ExternalFileTypesTabViewModelTest { + private static final Set TEST_LIST = Set.of( + StandardExternalFileType.MARKDOWN, + StandardExternalFileType.PDF, + StandardExternalFileType.URL, + StandardExternalFileType.JPG, + StandardExternalFileType.TXT); + + private ExternalFileTypesTabViewModel externalFileTypesTabViewModel = mock(ExternalFileTypesTabViewModel.class); + private FilePreferences filePreferences = mock(FilePreferences.class); + private ObservableList fileTypes = FXCollections.observableArrayList(); + + @BeforeEach + void setUp() { + // Arrange + when(filePreferences.getExternalFileTypes()).thenReturn(FXCollections.observableSet(TEST_LIST)); + fileTypes.addAll(filePreferences.getExternalFileTypes().stream().map(ExternalFileTypeItemViewModel::new).toList()); + } + + @Test + public void addNewTypeSuccess() { + // Arrange + doAnswer(invocation -> { + ExternalFileTypeItemViewModel item = new ExternalFileTypeItemViewModel(); + fileTypes.add(item); + return null; + }).when(externalFileTypesTabViewModel).addNewType(); + + //Action + externalFileTypesTabViewModel.addNewType(); + + //Assert + assertEquals(fileTypes.size(), 6); + } + + @Test + public void addNewTypeFailed() { + // Arrange + doNothing().when(externalFileTypesTabViewModel).addNewType(); + + //Action + externalFileTypesTabViewModel.addNewType(); + + //Assert + assertEquals(fileTypes.size(), 5); + } +} From b5c1d1698d768274826b26279018b6563a30d1cb Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Sun, 22 Oct 2023 17:29:01 +0100 Subject: [PATCH 09/41] updated the comment format --- .../ExternalFileTypesTabViewModelTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java index 77a66fb26bb..e10a03703fc 100644 --- a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java +++ b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java @@ -46,10 +46,10 @@ public void addNewTypeSuccess() { return null; }).when(externalFileTypesTabViewModel).addNewType(); - //Action + // Action externalFileTypesTabViewModel.addNewType(); - //Assert + // Assert assertEquals(fileTypes.size(), 6); } @@ -58,10 +58,10 @@ public void addNewTypeFailed() { // Arrange doNothing().when(externalFileTypesTabViewModel).addNewType(); - //Action + // Action externalFileTypesTabViewModel.addNewType(); - //Assert + // Assert assertEquals(fileTypes.size(), 5); } } From ac06f61e51f2049ba1a04da7d718fee3db0b696a Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Mon, 23 Oct 2023 01:31:09 +0100 Subject: [PATCH 10/41] rephase entry in CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e14e2ee85b..12fb3808048 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,7 +68,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where there was a failure to access the url link for "eprint" for the ArXiv entry.[#10474](https://github.com/JabRef/jabref/issues/10474) - We fixed an issue where it was not possible to connect to a shared database once a group with entries was added or other metadata modified [#10336](https://github.com/JabRef/jabref/issues/10336) - We fixed an issue where middle-button paste in X not always worked [#7905](https://github.com/JabRef/jabref/issues/7905) -- We fixed issues where in 1) preferences: external file type duplicates when change languages. [#10271](https://github.com/JabRef/jabref/issues/10271) 2) Cancel button only close EditExternalFileTypeEntryDialog without further action 3) Missed value in EditExternalFileTypeEntryDialog cannot close dialog even OK button clicked 4) Cannot save new External File Type if it extension exists already +- We fixed issues in the external file type dialog, e.g., duplicate entries in the case of a language switch. [#10271](https://github.com/JabRef/jabref/issues/10271) ## [5.10] – 2023-09-02 From c604ecbb8287b9f1c07ca6a573baf20c55920c21 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Fri, 27 Oct 2023 22:51:47 +0100 Subject: [PATCH 11/41] change viewModel.addNewType to return boolean --- .../externalfiletypes/ExternalFileTypesTab.java | 3 +-- .../externalfiletypes/ExternalFileTypesTabViewModel.java | 7 ++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTab.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTab.java index cd358279445..36409314e90 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTab.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTab.java @@ -89,8 +89,7 @@ public void initialize() { @FXML private void addNewType() { int fileTypeCount = fileTypesTable.getItems().size(); - viewModel.addNewType(); - if (fileTypeCount < fileTypesTable.getItems().size()) { + if (viewModel.addNewType()) { fileTypesTable.getSelectionModel().selectLast(); fileTypesTable.scrollTo(viewModel.getFileTypes().size() - 1); } diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java index 2dbd2c24edb..42cd631909f 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java @@ -54,22 +54,23 @@ public void resetToDefaults() { fileTypes.sort(Comparator.comparing(ExternalFileTypeItemViewModel::getName)); } - public void addNewType() { + public boolean addNewType() { ExternalFileTypeItemViewModel item = new ExternalFileTypeItemViewModel(); showEditDialog(item, Localization.lang("Add new file type")); if ("".equals(item.getName())) { - return; + return false; } String newExt = item.extensionProperty().get(); for (ExternalFileTypeItemViewModel fileTypeItem : fileTypes) { if (newExt.equalsIgnoreCase(fileTypeItem.extensionProperty().get())) { - return; + return false; } } fileTypes.add(item); + return true; } public ObservableList getFileTypes() { From 5bf568847f1ff961346e035517a92f0b26a3ca04 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Mon, 30 Oct 2023 00:56:44 +0000 Subject: [PATCH 12/41] replace .trim.getEqual() with isblank() --- .../externalfiletypes/EditExternalFileTypeEntryDialog.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java index f205bf09825..8e087ec8023 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java @@ -68,9 +68,9 @@ public EditExternalFileTypeEntryDialog(ExternalFileTypeItemViewModel item, Strin } public boolean isValidExternalFileTypeEntry() { - return !(name.getText().trim().equalsIgnoreCase("") - || extension.getText().trim().equalsIgnoreCase("") - || mimeType.getText().trim().equalsIgnoreCase("")); + return !(name.getText().isBlank() + || extension.getText().isBlank() + || mimeType.getText().isBlank()); } @FXML From ca3ed25a20f5ffc308704589521bbead026ba33c Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Sun, 5 Nov 2023 16:35:26 +0000 Subject: [PATCH 13/41] refactor logic of externalFileType add and edit --- .../EditExternalFileTypeEntryDialog.java | 21 +-------- .../ExternalFileTypesTab.java | 11 ++++- .../ExternalFileTypesTabViewModel.java | 44 ++++++++++++++----- 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java index 8e087ec8023..0b9df2b1fe7 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java @@ -33,15 +33,10 @@ public class EditExternalFileTypeEntryDialog extends BaseDialog { private final NativeDesktop nativeDesktop = OS.getNativeDesktop(); private final FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().withInitialDirectory(nativeDesktop.getApplicationDirectory()).build(); - private final ExternalFileTypeItemViewModel item; - - private final boolean isNewItem; private EditExternalFileTypeViewModel viewModel; public EditExternalFileTypeEntryDialog(ExternalFileTypeItemViewModel item, String dialogTitle) { - this.isNewItem = item.extensionProperty().get().equals(""); - this.item = item; this.setTitle(dialogTitle); @@ -51,28 +46,15 @@ public EditExternalFileTypeEntryDialog(ExternalFileTypeItemViewModel item, Strin .setAsDialogPane(this); final Button btOk = (Button) this.getDialogPane().lookupButton(ButtonType.OK); - btOk.addEventFilter(ActionEvent.ACTION, event -> { - if (!isValidExternalFileTypeEntry()) { - event.consume(); - } - }); this.setResultConverter(button -> { if (button == ButtonType.OK) { viewModel.storeSettings(); - } else { - name.setText(""); } return null; }); } - public boolean isValidExternalFileTypeEntry() { - return !(name.getText().isBlank() - || extension.getText().isBlank() - || mimeType.getText().isBlank()); - } - @FXML public void initialize() { viewModel = new EditExternalFileTypeViewModel(item); @@ -83,14 +65,13 @@ public void initialize() { customApplication.selectedProperty().bindBidirectional(viewModel.customApplicationSelectedProperty()); selectedApplication.disableProperty().bind(viewModel.defaultApplicationSelectedProperty()); btnBrowse.disableProperty().bind(viewModel.defaultApplicationSelectedProperty()); - extension.textProperty().bindBidirectional(viewModel.extensionProperty()); - extension.setEditable(isNewItem); name.textProperty().bindBidirectional(viewModel.nameProperty()); mimeType.textProperty().bindBidirectional(viewModel.mimeTypeProperty()); selectedApplication.textProperty().bindBidirectional(viewModel.selectedApplicationProperty()); } + @FXML private void openFileChooser(ActionEvent event) { dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(path -> viewModel.selectedApplicationProperty().setValue(path.toAbsolutePath().toString())); diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTab.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTab.java index 36409314e90..5a9ba1a6018 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTab.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTab.java @@ -78,7 +78,7 @@ public void initialize() { .install(fileTypesTableIconColumn); new ValueTableCellFactory() .withGraphic(none -> IconTheme.JabRefIcons.EDIT.getGraphicNode()) - .withOnMouseClickedEvent((type, none) -> event -> viewModel.edit(type)) + .withOnMouseClickedEvent((type, none) -> event -> editType(type)) .install(fileTypesTableEditColumn); new ValueTableCellFactory() .withGraphic(none -> IconTheme.JabRefIcons.DELETE_ENTRY.getGraphicNode()) @@ -86,15 +86,22 @@ public void initialize() { .install(fileTypesTableDeleteColumn); } + private void editType(ExternalFileTypeItemViewModel type){ + if(viewModel.edit(type)){ + fileTypesTable.getSelectionModel().selectLast(); + fileTypesTable.scrollTo(viewModel.getFileTypes().size() - 1); + } + } + @FXML private void addNewType() { - int fileTypeCount = fileTypesTable.getItems().size(); if (viewModel.addNewType()) { fileTypesTable.getSelectionModel().selectLast(); fileTypesTable.scrollTo(viewModel.getFileTypes().size() - 1); } } + @FXML private void resetToDefault() { viewModel.resetToDefaults(); diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java index 42cd631909f..ea95bc04c10 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java @@ -8,14 +8,19 @@ import javafx.collections.ObservableList; import org.jabref.gui.DialogService; +import org.jabref.gui.exporter.CreateModifyExporterDialogViewModel; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.preferences.PreferenceTabViewModel; import org.jabref.logic.l10n.Localization; import org.jabref.preferences.FilePreferences; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class ExternalFileTypesTabViewModel implements PreferenceTabViewModel { + private static final Logger LOGGER = LoggerFactory.getLogger(CreateModifyExporterDialogViewModel.class); private final ObservableList fileTypes = FXCollections.observableArrayList(); private final FilePreferences filePreferences; @@ -58,16 +63,8 @@ public boolean addNewType() { ExternalFileTypeItemViewModel item = new ExternalFileTypeItemViewModel(); showEditDialog(item, Localization.lang("Add new file type")); - if ("".equals(item.getName())) { + if (!isValidExternalFileType(item)) return false; - } - - String newExt = item.extensionProperty().get(); - for (ExternalFileTypeItemViewModel fileTypeItem : fileTypes) { - if (newExt.equalsIgnoreCase(fileTypeItem.extensionProperty().get())) { - return false; - } - } fileTypes.add(item); return true; @@ -81,11 +78,36 @@ private void showEditDialog(ExternalFileTypeItemViewModel item, String dialogTit dialogService.showCustomDialogAndWait(new EditExternalFileTypeEntryDialog(item, dialogTitle)); } - public void edit(ExternalFileTypeItemViewModel type) { - showEditDialog(type, Localization.lang("Edit file type")); + public boolean edit(ExternalFileTypeItemViewModel type) { + ExternalFileTypeItemViewModel typeToModify = new ExternalFileTypeItemViewModel(type.toExternalFileType()); + showEditDialog(typeToModify, Localization.lang("Edit file type")); + + if (!isValidExternalFileType(typeToModify)) + return false; + + fileTypes.remove(type); + fileTypes.add(typeToModify); + return true; } public void remove(ExternalFileTypeItemViewModel type) { fileTypes.remove(type); } + public boolean isValidExternalFileType(ExternalFileTypeItemViewModel item){ + // Check that there are no empty strings. + if (item.getName().isEmpty() || item.extensionProperty().get().isEmpty() || item.mimetypeProperty().get().isEmpty()) { + LOGGER.info("One of the fields is empty or invalid!"); + return false; + } + + //check extension need to be unique + String newExt = item.extensionProperty().get(); + for (ExternalFileTypeItemViewModel fileTypeItem : fileTypes) + if (newExt.equalsIgnoreCase(fileTypeItem.extensionProperty().get())) { + LOGGER.info("File Extension exists already!"); + return false; + } + + return true; + } } From d797e032cdde1946c457c0040b370ae7c8776eb7 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Tue, 7 Nov 2023 02:04:45 +0000 Subject: [PATCH 14/41] add test for preference externalFileType addNewType() and isValidExternalFileType() --- .../ExternalFileTypesTabViewModel.java | 2 +- .../ExternalFileTypeItemViewModelDTO.java | 36 +++++++ .../ExternalFileTypesTabViewModelTest.java | 101 +++++++++++------- 3 files changed, 98 insertions(+), 41 deletions(-) create mode 100644 src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelDTO.java diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java index ea95bc04c10..3d20a86ddb3 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java @@ -74,7 +74,7 @@ public ObservableList getFileTypes() { return fileTypes; } - private void showEditDialog(ExternalFileTypeItemViewModel item, String dialogTitle) { + protected void showEditDialog(ExternalFileTypeItemViewModel item, String dialogTitle) { dialogService.showCustomDialogAndWait(new EditExternalFileTypeEntryDialog(item, dialogTitle)); } diff --git a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelDTO.java b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelDTO.java new file mode 100644 index 00000000000..5b055cf8189 --- /dev/null +++ b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelDTO.java @@ -0,0 +1,36 @@ +package org.jabref.gui.preferences.externalfiletypes; + +public class ExternalFileTypeItemViewModelDTO { + private ExternalFileTypeItemViewModel externalFileTypeItemViewModel = new ExternalFileTypeItemViewModel(); + + public void setup(){ + externalFileTypeItemViewModel.nameProperty().set("Excel 2007"); + externalFileTypeItemViewModel.extensionProperty().set("xlsx"); + externalFileTypeItemViewModel.mimetypeProperty().set("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + externalFileTypeItemViewModel.applicationProperty().set("oocalc"); + } + public void setupWithoutName(){ + externalFileTypeItemViewModel.nameProperty().set(""); + } + public ExternalFileTypeItemViewModel get(){ + return externalFileTypeItemViewModel; + }; + + public void clone(ExternalFileTypeItemViewModel updatedModel){ + updatedModel.nameProperty().set(externalFileTypeItemViewModel.getName()); + updatedModel.extensionProperty().set(externalFileTypeItemViewModel.extensionProperty().get()); + updatedModel.mimetypeProperty().set(externalFileTypeItemViewModel.mimetypeProperty().get()); + updatedModel.applicationProperty().set(externalFileTypeItemViewModel.applicationProperty().get()); + } + + public boolean isSameValue(ExternalFileTypeItemViewModel item) { + if (!item.getName().equals(externalFileTypeItemViewModel.getName()) + || !item.extensionProperty().get().equals(externalFileTypeItemViewModel.extensionProperty().get()) + || !item.mimetypeProperty().get().equals(externalFileTypeItemViewModel.mimetypeProperty().get()) + || !item.applicationProperty().get().equals(externalFileTypeItemViewModel.applicationProperty().get()) + ) + return false; + else + return true; + } +} diff --git a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java index e10a03703fc..c4001df295d 100644 --- a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java +++ b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java @@ -1,67 +1,88 @@ package org.jabref.gui.preferences.externalfiletypes; -import java.util.Set; - -import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import org.jabref.gui.externalfiletype.ExternalFileType; -import org.jabref.gui.externalfiletype.StandardExternalFileType; +import org.jabref.gui.DialogService; import org.jabref.preferences.FilePreferences; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Spy; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.spy; public class ExternalFileTypesTabViewModelTest { - private static final Set TEST_LIST = Set.of( - StandardExternalFileType.MARKDOWN, - StandardExternalFileType.PDF, - StandardExternalFileType.URL, - StandardExternalFileType.JPG, - StandardExternalFileType.TXT); - - private ExternalFileTypesTabViewModel externalFileTypesTabViewModel = mock(ExternalFileTypesTabViewModel.class); + private FilePreferences filePreferences = mock(FilePreferences.class); - private ObservableList fileTypes = FXCollections.observableArrayList(); + private DialogService dialogService = mock(DialogService.class); + @Spy + private ExternalFileTypesTabViewModel externalFileTypesTabViewModel = spy(new ExternalFileTypesTabViewModel(filePreferences, dialogService)); + private ExternalFileTypeItemViewModelDTO externalFileTypeItemViewModel = new ExternalFileTypeItemViewModelDTO(); + @BeforeEach + void setUp() { + //arrange + externalFileTypeItemViewModel.setup(); + } - @BeforeEach - void setUp() { - // Arrange - when(filePreferences.getExternalFileTypes()).thenReturn(FXCollections.observableSet(TEST_LIST)); - fileTypes.addAll(filePreferences.getExternalFileTypes().stream().map(ExternalFileTypeItemViewModel::new).toList()); + @Test + public void whenExternalFileTypeItemViewModelWithNonEmptyStringValueThenisValidExternalFileTypeReturnTrue(){ + //action, assert + assertTrue(externalFileTypesTabViewModel.isValidExternalFileType(externalFileTypeItemViewModel.get())); } - @Test - public void addNewTypeSuccess() { - // Arrange - doAnswer(invocation -> { - ExternalFileTypeItemViewModel item = new ExternalFileTypeItemViewModel(); - fileTypes.add(item); - return null; - }).when(externalFileTypesTabViewModel).addNewType(); + @Test + public void whenExternalFileTypeItemViewModelWithEmptyNameThenisValidExternalFileTypeReturnFalse(){ - // Action - externalFileTypesTabViewModel.addNewType(); + //arrange + externalFileTypeItemViewModel.setupWithoutName(); + //action, assert + assertFalse(externalFileTypesTabViewModel.isValidExternalFileType(externalFileTypeItemViewModel.get())); + } - // Assert - assertEquals(fileTypes.size(), 6); - } + @Test + public void WhenExternalFileTypeItemViewModelIsValidThenAddNewTypeIsSuccessful(){ + + //arrange + ArgumentCaptor worldCaptor = ArgumentCaptor.forClass(ExternalFileTypeItemViewModel.class); + doAnswer(mocked -> { + ExternalFileTypeItemViewModel capturedWorld = worldCaptor.getValue(); + externalFileTypeItemViewModel.clone(capturedWorld); + return null; + }).when(externalFileTypesTabViewModel).showEditDialog(worldCaptor.capture(),any()); + + //action + externalFileTypesTabViewModel.addNewType(); + + //assert + ObservableList actualFileTypes = externalFileTypesTabViewModel.getFileTypes(); + assertEquals(actualFileTypes.size(),1); + assertTrue(externalFileTypeItemViewModel.isSameValue(actualFileTypes.getFirst())); + } @Test - public void addNewTypeFailed() { - // Arrange - doNothing().when(externalFileTypesTabViewModel).addNewType(); + public void WhenExternalFileTypeItemViewModelMissNameThenAddNewTypeIsFailed(){ + + //arrange + externalFileTypeItemViewModel.setupWithoutName(); + ArgumentCaptor worldCaptor = ArgumentCaptor.forClass(ExternalFileTypeItemViewModel.class); + doAnswer(mocked -> { + ExternalFileTypeItemViewModel capturedWorld = worldCaptor.getValue(); + externalFileTypeItemViewModel.clone(capturedWorld); + return null; + }).when(externalFileTypesTabViewModel).showEditDialog(worldCaptor.capture(),any()); - // Action + //action externalFileTypesTabViewModel.addNewType(); - // Assert - assertEquals(fileTypes.size(), 5); + //assert + ObservableList emptyFileTypes = externalFileTypesTabViewModel.getFileTypes(); + assertEquals(emptyFileTypes.size(),0); } } From 2c5de27b196a4cef4c44d8e7a3196efec4671d78 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Tue, 7 Nov 2023 02:11:51 +0000 Subject: [PATCH 15/41] updated changelog.md --- CHANGELOG.md | 2 +- .../ExternalFileTypesTabViewModel.java | 14 +++-- .../ExternalFileTypeItemViewModelDTO.java | 17 ++++--- .../ExternalFileTypesTabViewModelTest.java | 51 +++++++++---------- 4 files changed, 44 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8056057ad2..5d58d354a32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where the added protected term has unwanted leading and trailing whitespaces, where the formatted text has unwanted empty brackets and where the word at the cursor in the textbox can be added to the list. [#10415](https://github.com/JabRef/jabref/issues/10415) - We fixed an issue where in the merge dialog the file field of entries was not correctly merged when the first and second entry both contained values inside the file field. [#10572](https://github.com/JabRef/jabref/issues/10572) - We fixed some small inconsistencies in the user interface. [#10507](https://github.com/JabRef/jabref/issues/10507) [#10458](https://github.com/JabRef/jabref/issues/10458) +- We fixed issues in the external file type dialog, e.g., duplicate entries in the case of a language switch. [#10271](https://github.com/JabRef/jabref/issues/10271) ### Removed @@ -81,7 +82,6 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where there was a failure to access the url link for "eprint" for the ArXiv entry.[#10474](https://github.com/JabRef/jabref/issues/10474) - We fixed an issue where it was not possible to connect to a shared database once a group with entries was added or other metadata modified [#10336](https://github.com/JabRef/jabref/issues/10336) - We fixed an issue where middle-button paste in X not always worked [#7905](https://github.com/JabRef/jabref/issues/7905) -- We fixed issues in the external file type dialog, e.g., duplicate entries in the case of a language switch. [#10271](https://github.com/JabRef/jabref/issues/10271) ## [5.10] – 2023-09-02 diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java index 3d20a86ddb3..faa4cdc25dd 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java @@ -63,8 +63,9 @@ public boolean addNewType() { ExternalFileTypeItemViewModel item = new ExternalFileTypeItemViewModel(); showEditDialog(item, Localization.lang("Add new file type")); - if (!isValidExternalFileType(item)) + if (!isValidExternalFileType(item)) { return false; + } fileTypes.add(item); return true; @@ -82,8 +83,9 @@ public boolean edit(ExternalFileTypeItemViewModel type) { ExternalFileTypeItemViewModel typeToModify = new ExternalFileTypeItemViewModel(type.toExternalFileType()); showEditDialog(typeToModify, Localization.lang("Edit file type")); - if (!isValidExternalFileType(typeToModify)) + if (!isValidExternalFileType(typeToModify)) { return false; + } fileTypes.remove(type); fileTypes.add(typeToModify); @@ -93,20 +95,22 @@ public boolean edit(ExternalFileTypeItemViewModel type) { public void remove(ExternalFileTypeItemViewModel type) { fileTypes.remove(type); } - public boolean isValidExternalFileType(ExternalFileTypeItemViewModel item){ + + public boolean isValidExternalFileType(ExternalFileTypeItemViewModel item) { // Check that there are no empty strings. if (item.getName().isEmpty() || item.extensionProperty().get().isEmpty() || item.mimetypeProperty().get().isEmpty()) { LOGGER.info("One of the fields is empty or invalid!"); return false; } - //check extension need to be unique + // check extension need to be unique in the list String newExt = item.extensionProperty().get(); - for (ExternalFileTypeItemViewModel fileTypeItem : fileTypes) + for (ExternalFileTypeItemViewModel fileTypeItem : fileTypes) { if (newExt.equalsIgnoreCase(fileTypeItem.extensionProperty().get())) { LOGGER.info("File Extension exists already!"); return false; } + } return true; } diff --git a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelDTO.java b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelDTO.java index 5b055cf8189..4d10c4600de 100644 --- a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelDTO.java +++ b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelDTO.java @@ -3,20 +3,22 @@ public class ExternalFileTypeItemViewModelDTO { private ExternalFileTypeItemViewModel externalFileTypeItemViewModel = new ExternalFileTypeItemViewModel(); - public void setup(){ + public void setup() { externalFileTypeItemViewModel.nameProperty().set("Excel 2007"); externalFileTypeItemViewModel.extensionProperty().set("xlsx"); externalFileTypeItemViewModel.mimetypeProperty().set("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); externalFileTypeItemViewModel.applicationProperty().set("oocalc"); } - public void setupWithoutName(){ + + public void setupWithoutName() { externalFileTypeItemViewModel.nameProperty().set(""); } - public ExternalFileTypeItemViewModel get(){ + + public ExternalFileTypeItemViewModel get() { return externalFileTypeItemViewModel; - }; + } - public void clone(ExternalFileTypeItemViewModel updatedModel){ + public void clone(ExternalFileTypeItemViewModel updatedModel) { updatedModel.nameProperty().set(externalFileTypeItemViewModel.getName()); updatedModel.extensionProperty().set(externalFileTypeItemViewModel.extensionProperty().get()); updatedModel.mimetypeProperty().set(externalFileTypeItemViewModel.mimetypeProperty().get()); @@ -28,9 +30,10 @@ public boolean isSameValue(ExternalFileTypeItemViewModel item) { || !item.extensionProperty().get().equals(externalFileTypeItemViewModel.extensionProperty().get()) || !item.mimetypeProperty().get().equals(externalFileTypeItemViewModel.mimetypeProperty().get()) || !item.applicationProperty().get().equals(externalFileTypeItemViewModel.applicationProperty().get()) - ) + ) { return false; - else + } else { return true; + } } } diff --git a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java index c4001df295d..2dec8f1fcca 100644 --- a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java +++ b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java @@ -27,62 +27,59 @@ public class ExternalFileTypesTabViewModelTest { private ExternalFileTypeItemViewModelDTO externalFileTypeItemViewModel = new ExternalFileTypeItemViewModelDTO(); @BeforeEach void setUp() { - //arrange + // arrange externalFileTypeItemViewModel.setup(); } @Test - public void whenExternalFileTypeItemViewModelWithNonEmptyStringValueThenisValidExternalFileTypeReturnTrue(){ - //action, assert + public void whenExternalFileTypeItemViewModelWithNonEmptyStringValueThenisValidExternalFileTypeReturnTrue() { + // action, assert assertTrue(externalFileTypesTabViewModel.isValidExternalFileType(externalFileTypeItemViewModel.get())); } @Test - public void whenExternalFileTypeItemViewModelWithEmptyNameThenisValidExternalFileTypeReturnFalse(){ - - //arrange + public void whenExternalFileTypeItemViewModelWithEmptyNameThenisValidExternalFileTypeReturnFalse() { + // arrange externalFileTypeItemViewModel.setupWithoutName(); - //action, assert + // action, assert assertFalse(externalFileTypesTabViewModel.isValidExternalFileType(externalFileTypeItemViewModel.get())); } @Test - public void WhenExternalFileTypeItemViewModelIsValidThenAddNewTypeIsSuccessful(){ - - //arrange - ArgumentCaptor worldCaptor = ArgumentCaptor.forClass(ExternalFileTypeItemViewModel.class); + public void WhenExternalFileTypeItemViewModelIsValidThenAddNewTypeIsSuccessful() { + // arrange + ArgumentCaptor itemCaptor = ArgumentCaptor.forClass(ExternalFileTypeItemViewModel.class); doAnswer(mocked -> { - ExternalFileTypeItemViewModel capturedWorld = worldCaptor.getValue(); - externalFileTypeItemViewModel.clone(capturedWorld); + ExternalFileTypeItemViewModel capturedItem = itemCaptor.getValue(); + externalFileTypeItemViewModel.clone(capturedItem); return null; - }).when(externalFileTypesTabViewModel).showEditDialog(worldCaptor.capture(),any()); + }).when(externalFileTypesTabViewModel).showEditDialog(itemCaptor.capture(), any()); - //action + // action externalFileTypesTabViewModel.addNewType(); - //assert + // assert ObservableList actualFileTypes = externalFileTypesTabViewModel.getFileTypes(); - assertEquals(actualFileTypes.size(),1); + assertEquals(actualFileTypes.size(), 1); assertTrue(externalFileTypeItemViewModel.isSameValue(actualFileTypes.getFirst())); } @Test - public void WhenExternalFileTypeItemViewModelMissNameThenAddNewTypeIsFailed(){ - - //arrange + public void WhenExternalFileTypeItemViewModelMissNameThenAddNewTypeIsFailed() { + // arrange externalFileTypeItemViewModel.setupWithoutName(); - ArgumentCaptor worldCaptor = ArgumentCaptor.forClass(ExternalFileTypeItemViewModel.class); + ArgumentCaptor itemCaptor = ArgumentCaptor.forClass(ExternalFileTypeItemViewModel.class); doAnswer(mocked -> { - ExternalFileTypeItemViewModel capturedWorld = worldCaptor.getValue(); - externalFileTypeItemViewModel.clone(capturedWorld); + ExternalFileTypeItemViewModel capturedItem = itemCaptor.getValue(); + externalFileTypeItemViewModel.clone(capturedItem); return null; - }).when(externalFileTypesTabViewModel).showEditDialog(worldCaptor.capture(),any()); + }).when(externalFileTypesTabViewModel).showEditDialog(itemCaptor.capture(), any()); - //action + // action externalFileTypesTabViewModel.addNewType(); - //assert + // assert ObservableList emptyFileTypes = externalFileTypesTabViewModel.getFileTypes(); - assertEquals(emptyFileTypes.size(),0); + assertEquals(emptyFileTypes.size(), 0); } } From ca54d1753563eab56d1661e456a8f549b20b2417 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Tue, 7 Nov 2023 02:27:36 +0000 Subject: [PATCH 16/41] updated codestyle of ExternalFileTypesTab.java --- .../preferences/externalfiletypes/ExternalFileTypesTab.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTab.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTab.java index 5a9ba1a6018..4e5913c6d2a 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTab.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTab.java @@ -86,8 +86,8 @@ public void initialize() { .install(fileTypesTableDeleteColumn); } - private void editType(ExternalFileTypeItemViewModel type){ - if(viewModel.edit(type)){ + private void editType(ExternalFileTypeItemViewModel type) { + if (viewModel.edit(type)) { fileTypesTable.getSelectionModel().selectLast(); fileTypesTable.scrollTo(viewModel.getFileTypes().size() - 1); } @@ -101,7 +101,6 @@ private void addNewType() { } } - @FXML private void resetToDefault() { viewModel.resetToDefaults(); From 7da377972b333d1cc07a06943035550fc651cad1 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Tue, 7 Nov 2023 02:33:43 +0000 Subject: [PATCH 17/41] updated codestyle of ExternalFileTypesEntryDialog.java --- .../externalfiletypes/EditExternalFileTypeEntryDialog.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java index 0b9df2b1fe7..f9f901a1bf1 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java @@ -71,7 +71,6 @@ public void initialize() { selectedApplication.textProperty().bindBidirectional(viewModel.selectedApplicationProperty()); } - @FXML private void openFileChooser(ActionEvent event) { dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(path -> viewModel.selectedApplicationProperty().setValue(path.toAbsolutePath().toString())); From 4f7ce6dcaa48f9ab48f466c0957c90cec78f9011 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Tue, 7 Nov 2023 09:23:21 +0000 Subject: [PATCH 18/41] rename externalFileTypes test data file --- ...ModelDTO.java => ExternalFileTypeItemViewModelTestData.java} | 2 +- .../externalfiletypes/ExternalFileTypesTabViewModelTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/test/java/org/jabref/gui/preferences/externalfiletypes/{ExternalFileTypeItemViewModelDTO.java => ExternalFileTypeItemViewModelTestData.java} (97%) diff --git a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelDTO.java b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java similarity index 97% rename from src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelDTO.java rename to src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java index 4d10c4600de..171f319fb09 100644 --- a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelDTO.java +++ b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java @@ -1,6 +1,6 @@ package org.jabref.gui.preferences.externalfiletypes; -public class ExternalFileTypeItemViewModelDTO { +public class ExternalFileTypeItemViewModelTestData { private ExternalFileTypeItemViewModel externalFileTypeItemViewModel = new ExternalFileTypeItemViewModel(); public void setup() { diff --git a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java index 2dec8f1fcca..779990d7a21 100644 --- a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java +++ b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java @@ -24,7 +24,7 @@ public class ExternalFileTypesTabViewModelTest { private DialogService dialogService = mock(DialogService.class); @Spy private ExternalFileTypesTabViewModel externalFileTypesTabViewModel = spy(new ExternalFileTypesTabViewModel(filePreferences, dialogService)); - private ExternalFileTypeItemViewModelDTO externalFileTypeItemViewModel = new ExternalFileTypeItemViewModelDTO(); + private ExternalFileTypeItemViewModelTestData externalFileTypeItemViewModel = new ExternalFileTypeItemViewModelTestData(); @BeforeEach void setUp() { // arrange From 74aa42d8396eaf252e9f62ab2ddfc2563c3300e7 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Tue, 7 Nov 2023 09:34:24 +0000 Subject: [PATCH 19/41] gradle rewrite for some code formatting --- .../ExternalFileTypeItemViewModelTestData.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java index 171f319fb09..02a43e3fe09 100644 --- a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java +++ b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java @@ -26,14 +26,9 @@ public void clone(ExternalFileTypeItemViewModel updatedModel) { } public boolean isSameValue(ExternalFileTypeItemViewModel item) { - if (!item.getName().equals(externalFileTypeItemViewModel.getName()) - || !item.extensionProperty().get().equals(externalFileTypeItemViewModel.extensionProperty().get()) - || !item.mimetypeProperty().get().equals(externalFileTypeItemViewModel.mimetypeProperty().get()) - || !item.applicationProperty().get().equals(externalFileTypeItemViewModel.applicationProperty().get()) - ) { - return false; - } else { - return true; - } + return !(!item.getName().equals(externalFileTypeItemViewModel.getName()) + || !item.extensionProperty().get().equals(externalFileTypeItemViewModel.extensionProperty().get()) + || !item.mimetypeProperty().get().equals(externalFileTypeItemViewModel.mimetypeProperty().get()) + || !item.applicationProperty().get().equals(externalFileTypeItemViewModel.applicationProperty().get())); } } From c9f130c00d481ef15aecc2ac14ce304990e3d880 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Tue, 7 Nov 2023 09:54:21 +0000 Subject: [PATCH 20/41] refactor folder structure of ExternalFileTypeItemViewModelTestData --- .../externalfiletypes/ExternalFileTypesTabViewModelTest.java | 1 + .../ExternalFileTypeItemViewModelTestData.java | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) rename src/test/java/org/jabref/{gui/preferences/externalfiletypes => model}/ExternalFileTypeItemViewModelTestData.java (94%) diff --git a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java index 779990d7a21..29b43793d64 100644 --- a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java +++ b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java @@ -3,6 +3,7 @@ import javafx.collections.ObservableList; import org.jabref.gui.DialogService; +import org.jabref.model.ExternalFileTypeItemViewModelTestData; import org.jabref.preferences.FilePreferences; import org.junit.jupiter.api.BeforeEach; diff --git a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java b/src/test/java/org/jabref/model/ExternalFileTypeItemViewModelTestData.java similarity index 94% rename from src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java rename to src/test/java/org/jabref/model/ExternalFileTypeItemViewModelTestData.java index 02a43e3fe09..22047736b31 100644 --- a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java +++ b/src/test/java/org/jabref/model/ExternalFileTypeItemViewModelTestData.java @@ -1,4 +1,6 @@ -package org.jabref.gui.preferences.externalfiletypes; +package org.jabref.model; + +import org.jabref.gui.preferences.externalfiletypes.ExternalFileTypeItemViewModel; public class ExternalFileTypeItemViewModelTestData { private ExternalFileTypeItemViewModel externalFileTypeItemViewModel = new ExternalFileTypeItemViewModel(); From 52b1ad736b146876338cbf904f484040d7c68121 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Tue, 7 Nov 2023 10:16:09 +0000 Subject: [PATCH 21/41] reverse change of folder structure of ExternalFileTypeItemViewModelTestData --- .../ExternalFileTypeItemViewModelTestData.java | 2 +- .../externalfiletypes/ExternalFileTypesTabViewModelTest.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) rename src/test/java/org/jabref/{model => gui/preferences/externalfiletypes}/ExternalFileTypeItemViewModelTestData.java (97%) diff --git a/src/test/java/org/jabref/model/ExternalFileTypeItemViewModelTestData.java b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java similarity index 97% rename from src/test/java/org/jabref/model/ExternalFileTypeItemViewModelTestData.java rename to src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java index 22047736b31..c8fd873729f 100644 --- a/src/test/java/org/jabref/model/ExternalFileTypeItemViewModelTestData.java +++ b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java @@ -1,4 +1,4 @@ -package org.jabref.model; +package org.jabref.gui.preferences.externalfiletypes; import org.jabref.gui.preferences.externalfiletypes.ExternalFileTypeItemViewModel; diff --git a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java index 29b43793d64..779990d7a21 100644 --- a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java +++ b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java @@ -3,7 +3,6 @@ import javafx.collections.ObservableList; import org.jabref.gui.DialogService; -import org.jabref.model.ExternalFileTypeItemViewModelTestData; import org.jabref.preferences.FilePreferences; import org.junit.jupiter.api.BeforeEach; From 1cbb1e2be283794d0642d4df8e9a73e5fc82de68 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Tue, 7 Nov 2023 10:30:07 +0000 Subject: [PATCH 22/41] remove extra import statement from ExternalFileTypeItemViewModelTestData.java --- .../ExternalFileTypeItemViewModelTestData.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java index c8fd873729f..3bf8b15349d 100644 --- a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java +++ b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java @@ -1,7 +1,4 @@ package org.jabref.gui.preferences.externalfiletypes; - -import org.jabref.gui.preferences.externalfiletypes.ExternalFileTypeItemViewModel; - public class ExternalFileTypeItemViewModelTestData { private ExternalFileTypeItemViewModel externalFileTypeItemViewModel = new ExternalFileTypeItemViewModel(); From afa9a5c666cc5d4ae33bd18ccffa051287f32ff8 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Fri, 10 Nov 2023 06:52:52 +0000 Subject: [PATCH 23/41] add ExternalFileTypesTabViewModelTestData to TestArchitectureTest --- src/test/java/org/jabref/architecture/TestArchitectureTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/org/jabref/architecture/TestArchitectureTest.java b/src/test/java/org/jabref/architecture/TestArchitectureTest.java index 81f73e5a117..b9d87deb659 100644 --- a/src/test/java/org/jabref/architecture/TestArchitectureTest.java +++ b/src/test/java/org/jabref/architecture/TestArchitectureTest.java @@ -48,6 +48,7 @@ public void testNaming(JavaClasses classes) { .and().doNotHaveFullyQualifiedName("org.jabref.logic.shared.TestManager") .and().doNotHaveFullyQualifiedName("org.jabref.model.search.rules.MockSearchMatcher") .and().doNotHaveFullyQualifiedName("org.jabref.model.TreeNodeTestData") + .and().doNotHaveFullyQualifiedName("org.jabref.model.ExternalFileTypesTabViewModelTestData") .and().doNotHaveFullyQualifiedName("org.jabref.performance.BibtexEntryGenerator") .and().doNotHaveFullyQualifiedName("org.jabref.support.DisabledOnCIServer") .and().doNotHaveFullyQualifiedName("org.jabref.support.CIServerCondition") From 7eb9eeb329b7205110eb223b0acb205ead105b9d Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Fri, 10 Nov 2023 07:01:35 +0000 Subject: [PATCH 24/41] Update CHANGELOG.md Co-authored-by: Oliver Kopp --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f173157a9b..48605f246fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,7 +31,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where the added protected term has unwanted leading and trailing whitespaces, where the formatted text has unwanted empty brackets and where the word at the cursor in the textbox can be added to the list. [#10415](https://github.com/JabRef/jabref/issues/10415) - We fixed an issue where in the merge dialog the file field of entries was not correctly merged when the first and second entry both contained values inside the file field. [#10572](https://github.com/JabRef/jabref/issues/10572) - We fixed some small inconsistencies in the user interface. [#10507](https://github.com/JabRef/jabref/issues/10507) [#10458](https://github.com/JabRef/jabref/issues/10458) -- We fixed issues in the external file type dialog, e.g., duplicate entries in the case of a language switch. [#10271](https://github.com/JabRef/jabref/issues/10271) +- We fixed issues in the external file type dialog w.r.t. duplicate entries in the case of a language switch. [#10271](https://github.com/JabRef/jabref/issues/10271) ### Removed From c290c86f96caaa4fa9d2806557151447a1bb6420 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Fri, 10 Nov 2023 07:05:01 +0000 Subject: [PATCH 25/41] remove unnecessary variable --- .../externalfiletypes/EditExternalFileTypeEntryDialog.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java index f9f901a1bf1..d1008ebfeaa 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java @@ -45,8 +45,6 @@ public EditExternalFileTypeEntryDialog(ExternalFileTypeItemViewModel item, Strin .load() .setAsDialogPane(this); - final Button btOk = (Button) this.getDialogPane().lookupButton(ButtonType.OK); - this.setResultConverter(button -> { if (button == ButtonType.OK) { viewModel.storeSettings(); From 490a8a5c48364f6f4b137861f7f16edc9f204774 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Fri, 10 Nov 2023 07:10:19 +0000 Subject: [PATCH 26/41] reformat code --- .../ExternalFileTypesTabViewModelTest.java | 62 ++++++++----------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java index 779990d7a21..76627f52833 100644 --- a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java +++ b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java @@ -22,51 +22,45 @@ public class ExternalFileTypesTabViewModelTest { private FilePreferences filePreferences = mock(FilePreferences.class); private DialogService dialogService = mock(DialogService.class); + @Spy private ExternalFileTypesTabViewModel externalFileTypesTabViewModel = spy(new ExternalFileTypesTabViewModel(filePreferences, dialogService)); private ExternalFileTypeItemViewModelTestData externalFileTypeItemViewModel = new ExternalFileTypeItemViewModelTestData(); - @BeforeEach - void setUp() { - // arrange - externalFileTypeItemViewModel.setup(); - } + + @BeforeEach + void setUp() { + externalFileTypeItemViewModel.setup(); + } @Test public void whenExternalFileTypeItemViewModelWithNonEmptyStringValueThenisValidExternalFileTypeReturnTrue() { - // action, assert assertTrue(externalFileTypesTabViewModel.isValidExternalFileType(externalFileTypeItemViewModel.get())); } - @Test - public void whenExternalFileTypeItemViewModelWithEmptyNameThenisValidExternalFileTypeReturnFalse() { - // arrange - externalFileTypeItemViewModel.setupWithoutName(); - // action, assert - assertFalse(externalFileTypesTabViewModel.isValidExternalFileType(externalFileTypeItemViewModel.get())); - } - - @Test - public void WhenExternalFileTypeItemViewModelIsValidThenAddNewTypeIsSuccessful() { - // arrange - ArgumentCaptor itemCaptor = ArgumentCaptor.forClass(ExternalFileTypeItemViewModel.class); - doAnswer(mocked -> { - ExternalFileTypeItemViewModel capturedItem = itemCaptor.getValue(); - externalFileTypeItemViewModel.clone(capturedItem); - return null; - }).when(externalFileTypesTabViewModel).showEditDialog(itemCaptor.capture(), any()); - - // action - externalFileTypesTabViewModel.addNewType(); - - // assert - ObservableList actualFileTypes = externalFileTypesTabViewModel.getFileTypes(); - assertEquals(actualFileTypes.size(), 1); - assertTrue(externalFileTypeItemViewModel.isSameValue(actualFileTypes.getFirst())); - } + @Test + public void whenExternalFileTypeItemViewModelWithEmptyNameThenisValidExternalFileTypeReturnFalse() { + externalFileTypeItemViewModel.setupWithoutName(); + assertFalse(externalFileTypesTabViewModel.isValidExternalFileType(externalFileTypeItemViewModel.get())); + } + + @Test + public void WhenExternalFileTypeItemViewModelIsValidThenAddNewTypeIsSuccessful() { + ArgumentCaptor itemCaptor = ArgumentCaptor.forClass(ExternalFileTypeItemViewModel.class); + doAnswer(mocked -> { + ExternalFileTypeItemViewModel capturedItem = itemCaptor.getValue(); + externalFileTypeItemViewModel.clone(capturedItem); + return null; + }).when(externalFileTypesTabViewModel).showEditDialog(itemCaptor.capture(), any()); + + externalFileTypesTabViewModel.addNewType(); + + ObservableList actualFileTypes = externalFileTypesTabViewModel.getFileTypes(); + assertEquals(actualFileTypes.size(), 1); + assertTrue(externalFileTypeItemViewModel.isSameValue(actualFileTypes.getFirst())); + } @Test public void WhenExternalFileTypeItemViewModelMissNameThenAddNewTypeIsFailed() { - // arrange externalFileTypeItemViewModel.setupWithoutName(); ArgumentCaptor itemCaptor = ArgumentCaptor.forClass(ExternalFileTypeItemViewModel.class); doAnswer(mocked -> { @@ -75,10 +69,8 @@ public void WhenExternalFileTypeItemViewModelMissNameThenAddNewTypeIsFailed() { return null; }).when(externalFileTypesTabViewModel).showEditDialog(itemCaptor.capture(), any()); - // action externalFileTypesTabViewModel.addNewType(); - // assert ObservableList emptyFileTypes = externalFileTypesTabViewModel.getFileTypes(); assertEquals(emptyFileTypes.size(), 0); } From 8b89bf6d9090e3ee2fc57f90c4e36837a7aee26c Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Fri, 10 Nov 2023 07:20:20 +0000 Subject: [PATCH 27/41] refactor TestArchitectureTest --- src/test/java/org/jabref/architecture/TestArchitectureTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/jabref/architecture/TestArchitectureTest.java b/src/test/java/org/jabref/architecture/TestArchitectureTest.java index b9d87deb659..3a69b760303 100644 --- a/src/test/java/org/jabref/architecture/TestArchitectureTest.java +++ b/src/test/java/org/jabref/architecture/TestArchitectureTest.java @@ -38,6 +38,7 @@ public void testNaming(JavaClasses classes) { .and().doNotHaveFullyQualifiedName("org.jabref.benchmarks.Benchmarks") .and().doNotHaveFullyQualifiedName("org.jabref.http.server.TestBibFile") .and().doNotHaveFullyQualifiedName("org.jabref.gui.autocompleter.AutoCompleterUtil") + .and().doNotHaveFullyQualifiedName("org.jabref.gui.preferences.externalfiletypes.ExternalFileTypeItemViewModelTestData") .and().doNotHaveFullyQualifiedName("org.jabref.gui.search.TextFlowEqualityHelper") .and().doNotHaveFullyQualifiedName("org.jabref.logic.bibtex.BibEntryAssert") .and().doNotHaveFullyQualifiedName("org.jabref.logic.importer.fileformat.ImporterTestEngine") @@ -48,7 +49,6 @@ public void testNaming(JavaClasses classes) { .and().doNotHaveFullyQualifiedName("org.jabref.logic.shared.TestManager") .and().doNotHaveFullyQualifiedName("org.jabref.model.search.rules.MockSearchMatcher") .and().doNotHaveFullyQualifiedName("org.jabref.model.TreeNodeTestData") - .and().doNotHaveFullyQualifiedName("org.jabref.model.ExternalFileTypesTabViewModelTestData") .and().doNotHaveFullyQualifiedName("org.jabref.performance.BibtexEntryGenerator") .and().doNotHaveFullyQualifiedName("org.jabref.support.DisabledOnCIServer") .and().doNotHaveFullyQualifiedName("org.jabref.support.CIServerCondition") From 05024d3e9e360c9f12deed5a102e9ab24008edb2 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Thu, 7 Dec 2023 11:27:34 +0000 Subject: [PATCH 28/41] EditExternalFileTypeEntryDialog form OK button disabled if empty extension field --- .../EditExternalFileTypeEntryDialog.java | 5 +++ .../EditExternalFileTypeViewModel.java | 35 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java index d1008ebfeaa..b95745fad38 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java @@ -45,6 +45,11 @@ public EditExternalFileTypeEntryDialog(ExternalFileTypeItemViewModel item, Strin .load() .setAsDialogPane(this); + getDialogPane().getButtonTypes().setAll(ButtonType.OK, ButtonType.CANCEL); + + final Button confirmDialogButton = (Button) getDialogPane().lookupButton(ButtonType.OK); + confirmDialogButton.disableProperty().bind(viewModel.validationStatus().validProperty().not()); + this.setResultConverter(button -> { if (button == ButtonType.OK) { viewModel.storeSettings(); diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java index 7a095e76b94..3f07c33e531 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java @@ -6,9 +6,17 @@ import javafx.beans.property.StringProperty; import javafx.scene.Node; +import org.jabref.logic.l10n.Localization; +import org.jabref.model.strings.StringUtil; + +import de.saxsys.mvvmfx.utils.validation.CompositeValidator; +import de.saxsys.mvvmfx.utils.validation.FunctionBasedValidator; +import de.saxsys.mvvmfx.utils.validation.ValidationMessage; +import de.saxsys.mvvmfx.utils.validation.ValidationStatus; +import de.saxsys.mvvmfx.utils.validation.Validator; + public class EditExternalFileTypeViewModel { private final ExternalFileTypeItemViewModel fileTypeViewModel; - private final StringProperty nameProperty = new SimpleStringProperty(""); private final StringProperty mimeTypeProperty = new SimpleStringProperty(""); private final StringProperty extensionProperty = new SimpleStringProperty(""); @@ -16,6 +24,11 @@ public class EditExternalFileTypeViewModel { private final BooleanProperty defaultApplicationSelectedProperty = new SimpleBooleanProperty(false); private final BooleanProperty customApplicationSelectedProperty = new SimpleBooleanProperty(false); + + private Validator extensionValidator; + private Validator sameExtensionValidator; + private CompositeValidator validator; + public EditExternalFileTypeViewModel(ExternalFileTypeItemViewModel fileTypeViewModel) { this.fileTypeViewModel = fileTypeViewModel; @@ -29,6 +42,22 @@ public EditExternalFileTypeViewModel(ExternalFileTypeItemViewModel fileTypeViewM customApplicationSelectedProperty.setValue(true); selectedApplicationProperty.setValue(fileTypeViewModel.applicationProperty().getValue()); } + + setupValidation(); + } + + private void setupValidation() { + validator = new CompositeValidator(); + extensionValidator = new FunctionBasedValidator<>( + extensionProperty, + StringUtil::isNotBlank, + ValidationMessage.error(Localization.lang("Please enter a name for the extension."))); + + validator.addValidators(extensionValidator); + } + + public ValidationStatus validationStatus() { + return validator.getValidationStatus(); } public Node getIcon() { @@ -59,6 +88,10 @@ public BooleanProperty customApplicationSelectedProperty() { return customApplicationSelectedProperty; } + public BooleanProperty validExtensionTypeProperty() { + return defaultApplicationSelectedProperty; + } + public void storeSettings() { fileTypeViewModel.nameProperty().setValue(nameProperty.getValue().trim()); fileTypeViewModel.mimetypeProperty().setValue(mimeTypeProperty.getValue().trim()); From 424adb71bc7615cbc5edd17268f469580686dbc3 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Mon, 11 Dec 2023 00:29:06 +0000 Subject: [PATCH 29/41] EditExternalFileTypeEntryDialog OK button disabled if duplicated file type found --- .../CreateModifyExporterDialogViewModel.java | 2 +- .../EditExternalFileTypeEntryDialog.java | 12 +++++--- .../EditExternalFileTypeViewModel.java | 28 ++++++++++++++----- .../ExternalFileTypesTabViewModel.java | 3 +- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java index 78c808dad3c..d9e0c1bc69c 100644 --- a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java @@ -57,7 +57,7 @@ public ExporterViewModel saveExporter() { // Check that there are no empty strings. if (layoutFile.get().isEmpty() || name.get().isEmpty() || extension.get().isEmpty() || !layoutFile.get().endsWith(".layout")) { - LOGGER.info("One of the fields is empty or invalid!"); + LOGGER.info("One of the fields is empty or invalid."); return null; } diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java index b95745fad38..91d66003c35 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java @@ -1,5 +1,6 @@ package org.jabref.gui.preferences.externalfiletypes; +import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Button; @@ -34,11 +35,15 @@ public class EditExternalFileTypeEntryDialog extends BaseDialog { private final NativeDesktop nativeDesktop = OS.getNativeDesktop(); private final FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().withInitialDirectory(nativeDesktop.getApplicationDirectory()).build(); private final ExternalFileTypeItemViewModel item; + + private final ObservableList fileTypes; private EditExternalFileTypeViewModel viewModel; - public EditExternalFileTypeEntryDialog(ExternalFileTypeItemViewModel item, String dialogTitle) { - this.item = item; + + public EditExternalFileTypeEntryDialog(ExternalFileTypeItemViewModel item, String dialogTitle, ObservableList fileTypes) { + this.item = item; + this.fileTypes = fileTypes; this.setTitle(dialogTitle); ViewLoader.view(this) @@ -49,7 +54,6 @@ public EditExternalFileTypeEntryDialog(ExternalFileTypeItemViewModel item, Strin final Button confirmDialogButton = (Button) getDialogPane().lookupButton(ButtonType.OK); confirmDialogButton.disableProperty().bind(viewModel.validationStatus().validProperty().not()); - this.setResultConverter(button -> { if (button == ButtonType.OK) { viewModel.storeSettings(); @@ -60,7 +64,7 @@ public EditExternalFileTypeEntryDialog(ExternalFileTypeItemViewModel item, Strin @FXML public void initialize() { - viewModel = new EditExternalFileTypeViewModel(item); + viewModel = new EditExternalFileTypeViewModel(item, fileTypes); icon.setGraphic(viewModel.getIcon()); diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java index 3f07c33e531..938cf4b83ba 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java @@ -4,6 +4,7 @@ import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; +import javafx.collections.ObservableList; import javafx.scene.Node; import org.jabref.logic.l10n.Localization; @@ -23,15 +24,16 @@ public class EditExternalFileTypeViewModel { private final StringProperty selectedApplicationProperty = new SimpleStringProperty(""); private final BooleanProperty defaultApplicationSelectedProperty = new SimpleBooleanProperty(false); private final BooleanProperty customApplicationSelectedProperty = new SimpleBooleanProperty(false); - - + private final ObservableList fileTypes; + private final String originalExtension; private Validator extensionValidator; private Validator sameExtensionValidator; private CompositeValidator validator; - public EditExternalFileTypeViewModel(ExternalFileTypeItemViewModel fileTypeViewModel) { + public EditExternalFileTypeViewModel(ExternalFileTypeItemViewModel fileTypeViewModel, ObservableList fileTypes) { this.fileTypeViewModel = fileTypeViewModel; - + this.fileTypes = fileTypes; + this.originalExtension = fileTypeViewModel.extensionProperty().getValue(); extensionProperty.setValue(fileTypeViewModel.extensionProperty().getValue()); nameProperty.setValue(fileTypeViewModel.nameProperty().getValue()); mimeTypeProperty.setValue(fileTypeViewModel.mimetypeProperty().getValue()); @@ -51,9 +53,21 @@ private void setupValidation() { extensionValidator = new FunctionBasedValidator<>( extensionProperty, StringUtil::isNotBlank, - ValidationMessage.error(Localization.lang("Please enter a name for the extension."))); - - validator.addValidators(extensionValidator); + ValidationMessage.error(Localization.lang("Please enter a name for the extension.")) + ); + sameExtensionValidator = new FunctionBasedValidator<>( + extensionProperty, + extension -> { + for (ExternalFileTypeItemViewModel fileTypeItem : fileTypes) { + if (extension.equalsIgnoreCase(fileTypeItem.extensionProperty().get()) && !extension.equalsIgnoreCase(originalExtension)) { + return false; + } + } + return true; + }, + ValidationMessage.error(Localization.lang("There is already an exists extension with the same name.")) + ); + validator.addValidators(extensionValidator, sameExtensionValidator); } public ValidationStatus validationStatus() { diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java index faa4cdc25dd..d84ae74f6dd 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java @@ -76,7 +76,7 @@ public ObservableList getFileTypes() { } protected void showEditDialog(ExternalFileTypeItemViewModel item, String dialogTitle) { - dialogService.showCustomDialogAndWait(new EditExternalFileTypeEntryDialog(item, dialogTitle)); + dialogService.showCustomDialogAndWait(new EditExternalFileTypeEntryDialog(item, dialogTitle, fileTypes)); } public boolean edit(ExternalFileTypeItemViewModel type) { @@ -97,7 +97,6 @@ public void remove(ExternalFileTypeItemViewModel type) { } public boolean isValidExternalFileType(ExternalFileTypeItemViewModel item) { - // Check that there are no empty strings. if (item.getName().isEmpty() || item.extensionProperty().get().isEmpty() || item.mimetypeProperty().get().isEmpty()) { LOGGER.info("One of the fields is empty or invalid!"); return false; From 7bc67c402e1ff1b895998a6390c9a793b214460c Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Mon, 11 Dec 2023 00:36:16 +0000 Subject: [PATCH 30/41] remove exclamation mark in error message --- .../externalfiletypes/ExternalFileTypesTabViewModel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java index d84ae74f6dd..cc835723572 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java @@ -98,7 +98,7 @@ public void remove(ExternalFileTypeItemViewModel type) { public boolean isValidExternalFileType(ExternalFileTypeItemViewModel item) { if (item.getName().isEmpty() || item.extensionProperty().get().isEmpty() || item.mimetypeProperty().get().isEmpty()) { - LOGGER.info("One of the fields is empty or invalid!"); + LOGGER.info("One of the fields is empty or invalid."); return false; } @@ -106,7 +106,7 @@ public boolean isValidExternalFileType(ExternalFileTypeItemViewModel item) { String newExt = item.extensionProperty().get(); for (ExternalFileTypeItemViewModel fileTypeItem : fileTypes) { if (newExt.equalsIgnoreCase(fileTypeItem.extensionProperty().get())) { - LOGGER.info("File Extension exists already!"); + LOGGER.info("File Extension exists already."); return false; } } From ca9eaeb705f2e836a5670d2d0b44fb59cfc1cd7e Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Mon, 11 Dec 2023 00:39:09 +0000 Subject: [PATCH 31/41] change message File Extension exists already from info to debug --- .../externalfiletypes/ExternalFileTypesTabViewModel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java index cc835723572..3f5faa0c9e9 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java @@ -98,7 +98,7 @@ public void remove(ExternalFileTypeItemViewModel type) { public boolean isValidExternalFileType(ExternalFileTypeItemViewModel item) { if (item.getName().isEmpty() || item.extensionProperty().get().isEmpty() || item.mimetypeProperty().get().isEmpty()) { - LOGGER.info("One of the fields is empty or invalid."); + LOGGER.debug("One of the fields is empty or invalid."); return false; } @@ -106,7 +106,7 @@ public boolean isValidExternalFileType(ExternalFileTypeItemViewModel item) { String newExt = item.extensionProperty().get(); for (ExternalFileTypeItemViewModel fileTypeItem : fileTypes) { if (newExt.equalsIgnoreCase(fileTypeItem.extensionProperty().get())) { - LOGGER.info("File Extension exists already."); + LOGGER.debug("File Extension exists already."); return false; } } From eec134fdaf2c09aff5fe285b253cff4dec974a95 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Mon, 11 Dec 2023 00:51:06 +0000 Subject: [PATCH 32/41] refactor ExternalFileTypesTabViewModelTest.java --- ...ExternalFileTypeItemViewModelTestData.java | 33 ---------------- .../ExternalFileTypesTabViewModelTest.java | 39 ++++++++++++++----- 2 files changed, 30 insertions(+), 42 deletions(-) delete mode 100644 src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java diff --git a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java deleted file mode 100644 index 3bf8b15349d..00000000000 --- a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypeItemViewModelTestData.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.jabref.gui.preferences.externalfiletypes; -public class ExternalFileTypeItemViewModelTestData { - private ExternalFileTypeItemViewModel externalFileTypeItemViewModel = new ExternalFileTypeItemViewModel(); - - public void setup() { - externalFileTypeItemViewModel.nameProperty().set("Excel 2007"); - externalFileTypeItemViewModel.extensionProperty().set("xlsx"); - externalFileTypeItemViewModel.mimetypeProperty().set("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); - externalFileTypeItemViewModel.applicationProperty().set("oocalc"); - } - - public void setupWithoutName() { - externalFileTypeItemViewModel.nameProperty().set(""); - } - - public ExternalFileTypeItemViewModel get() { - return externalFileTypeItemViewModel; - } - - public void clone(ExternalFileTypeItemViewModel updatedModel) { - updatedModel.nameProperty().set(externalFileTypeItemViewModel.getName()); - updatedModel.extensionProperty().set(externalFileTypeItemViewModel.extensionProperty().get()); - updatedModel.mimetypeProperty().set(externalFileTypeItemViewModel.mimetypeProperty().get()); - updatedModel.applicationProperty().set(externalFileTypeItemViewModel.applicationProperty().get()); - } - - public boolean isSameValue(ExternalFileTypeItemViewModel item) { - return !(!item.getName().equals(externalFileTypeItemViewModel.getName()) - || !item.extensionProperty().get().equals(externalFileTypeItemViewModel.extensionProperty().get()) - || !item.mimetypeProperty().get().equals(externalFileTypeItemViewModel.mimetypeProperty().get()) - || !item.applicationProperty().get().equals(externalFileTypeItemViewModel.applicationProperty().get())); - } -} diff --git a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java index 76627f52833..f587571b8b0 100644 --- a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java +++ b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java @@ -22,25 +22,46 @@ public class ExternalFileTypesTabViewModelTest { private FilePreferences filePreferences = mock(FilePreferences.class); private DialogService dialogService = mock(DialogService.class); + private ExternalFileTypeItemViewModel externalFileTypeItemViewModel = new ExternalFileTypeItemViewModel(); @Spy private ExternalFileTypesTabViewModel externalFileTypesTabViewModel = spy(new ExternalFileTypesTabViewModel(filePreferences, dialogService)); - private ExternalFileTypeItemViewModelTestData externalFileTypeItemViewModel = new ExternalFileTypeItemViewModelTestData(); @BeforeEach void setUp() { - externalFileTypeItemViewModel.setup(); + externalFileTypeItemViewModel.nameProperty().set("Excel 2007"); + externalFileTypeItemViewModel.extensionProperty().set("xlsx"); + externalFileTypeItemViewModel.mimetypeProperty().set("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + externalFileTypeItemViewModel.applicationProperty().set("oocalc"); + } + + public void setupViewModelWithoutName() { + externalFileTypeItemViewModel.nameProperty().set(""); + } + + public void viewModelClone(ExternalFileTypeItemViewModel updatedModel) { + updatedModel.nameProperty().set(externalFileTypeItemViewModel.getName()); + updatedModel.extensionProperty().set(externalFileTypeItemViewModel.extensionProperty().get()); + updatedModel.mimetypeProperty().set(externalFileTypeItemViewModel.mimetypeProperty().get()); + updatedModel.applicationProperty().set(externalFileTypeItemViewModel.applicationProperty().get()); + } + + public boolean viewModelIsSameValue(ExternalFileTypeItemViewModel item) { + return !(!item.getName().equals(externalFileTypeItemViewModel.getName()) + || !item.extensionProperty().get().equals(externalFileTypeItemViewModel.extensionProperty().get()) + || !item.mimetypeProperty().get().equals(externalFileTypeItemViewModel.mimetypeProperty().get()) + || !item.applicationProperty().get().equals(externalFileTypeItemViewModel.applicationProperty().get())); } @Test public void whenExternalFileTypeItemViewModelWithNonEmptyStringValueThenisValidExternalFileTypeReturnTrue() { - assertTrue(externalFileTypesTabViewModel.isValidExternalFileType(externalFileTypeItemViewModel.get())); + assertTrue(externalFileTypesTabViewModel.isValidExternalFileType(externalFileTypeItemViewModel)); } @Test public void whenExternalFileTypeItemViewModelWithEmptyNameThenisValidExternalFileTypeReturnFalse() { - externalFileTypeItemViewModel.setupWithoutName(); - assertFalse(externalFileTypesTabViewModel.isValidExternalFileType(externalFileTypeItemViewModel.get())); + this.setupViewModelWithoutName(); + assertFalse(externalFileTypesTabViewModel.isValidExternalFileType(externalFileTypeItemViewModel)); } @Test @@ -48,7 +69,7 @@ public void WhenExternalFileTypeItemViewModelIsValidThenAddNewTypeIsSuccessful() ArgumentCaptor itemCaptor = ArgumentCaptor.forClass(ExternalFileTypeItemViewModel.class); doAnswer(mocked -> { ExternalFileTypeItemViewModel capturedItem = itemCaptor.getValue(); - externalFileTypeItemViewModel.clone(capturedItem); + this.viewModelClone(capturedItem); return null; }).when(externalFileTypesTabViewModel).showEditDialog(itemCaptor.capture(), any()); @@ -56,16 +77,16 @@ public void WhenExternalFileTypeItemViewModelIsValidThenAddNewTypeIsSuccessful() ObservableList actualFileTypes = externalFileTypesTabViewModel.getFileTypes(); assertEquals(actualFileTypes.size(), 1); - assertTrue(externalFileTypeItemViewModel.isSameValue(actualFileTypes.getFirst())); + assertTrue(viewModelIsSameValue(actualFileTypes.getFirst())); } @Test public void WhenExternalFileTypeItemViewModelMissNameThenAddNewTypeIsFailed() { - externalFileTypeItemViewModel.setupWithoutName(); + setupViewModelWithoutName(); ArgumentCaptor itemCaptor = ArgumentCaptor.forClass(ExternalFileTypeItemViewModel.class); doAnswer(mocked -> { ExternalFileTypeItemViewModel capturedItem = itemCaptor.getValue(); - externalFileTypeItemViewModel.clone(capturedItem); + viewModelClone(capturedItem); return null; }).when(externalFileTypesTabViewModel).showEditDialog(itemCaptor.capture(), any()); From 73cf3d51e9a5a7f7d2ece96274eee2ddb6718364 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Mon, 11 Dec 2023 00:52:37 +0000 Subject: [PATCH 33/41] updated TestArchitectureTest for removing ExternalFileTypeItemViewModelTestData class --- src/test/java/org/jabref/architecture/TestArchitectureTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/jabref/architecture/TestArchitectureTest.java b/src/test/java/org/jabref/architecture/TestArchitectureTest.java index 3a69b760303..81f73e5a117 100644 --- a/src/test/java/org/jabref/architecture/TestArchitectureTest.java +++ b/src/test/java/org/jabref/architecture/TestArchitectureTest.java @@ -38,7 +38,6 @@ public void testNaming(JavaClasses classes) { .and().doNotHaveFullyQualifiedName("org.jabref.benchmarks.Benchmarks") .and().doNotHaveFullyQualifiedName("org.jabref.http.server.TestBibFile") .and().doNotHaveFullyQualifiedName("org.jabref.gui.autocompleter.AutoCompleterUtil") - .and().doNotHaveFullyQualifiedName("org.jabref.gui.preferences.externalfiletypes.ExternalFileTypeItemViewModelTestData") .and().doNotHaveFullyQualifiedName("org.jabref.gui.search.TextFlowEqualityHelper") .and().doNotHaveFullyQualifiedName("org.jabref.logic.bibtex.BibEntryAssert") .and().doNotHaveFullyQualifiedName("org.jabref.logic.importer.fileformat.ImporterTestEngine") From d983edd54c21be71d28cfbf67135d53f55579974 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Mon, 11 Dec 2023 01:01:30 +0000 Subject: [PATCH 34/41] extract methods for logics in isValidExternalFileType() --- .../ExternalFileTypesTabViewModel.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java index 3f5faa0c9e9..89c639bb924 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java @@ -97,20 +97,31 @@ public void remove(ExternalFileTypeItemViewModel type) { } public boolean isValidExternalFileType(ExternalFileTypeItemViewModel item) { - if (item.getName().isEmpty() || item.extensionProperty().get().isEmpty() || item.mimetypeProperty().get().isEmpty()) { + if (withEmptyValue(item)){ LOGGER.debug("One of the fields is empty or invalid."); return false; } + if(!isUniqueExtension(item)){ + LOGGER.debug("File Extension exists already."); + return false; + } + + return true; + } + + private boolean withEmptyValue(ExternalFileTypeItemViewModel item){ + return item.getName().isEmpty() || item.extensionProperty().get().isEmpty() || item.mimetypeProperty().get().isEmpty(); + } + + private boolean isUniqueExtension(ExternalFileTypeItemViewModel item){ // check extension need to be unique in the list String newExt = item.extensionProperty().get(); for (ExternalFileTypeItemViewModel fileTypeItem : fileTypes) { if (newExt.equalsIgnoreCase(fileTypeItem.extensionProperty().get())) { - LOGGER.debug("File Extension exists already."); return false; } } - return true; } } From 3fa21a3472a7d45ebb27151123017e5c260f9c78 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Mon, 11 Dec 2023 01:05:28 +0000 Subject: [PATCH 35/41] add validator for name and MIME type --- .../EditExternalFileTypeViewModel.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java index 938cf4b83ba..c0c7644b95a 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java @@ -27,6 +27,8 @@ public class EditExternalFileTypeViewModel { private final ObservableList fileTypes; private final String originalExtension; private Validator extensionValidator; + private Validator nameValidator; + private Validator mimeTypeValidator; private Validator sameExtensionValidator; private CompositeValidator validator; @@ -55,6 +57,19 @@ private void setupValidation() { StringUtil::isNotBlank, ValidationMessage.error(Localization.lang("Please enter a name for the extension.")) ); + + nameValidator = new FunctionBasedValidator<>( + nameProperty, + StringUtil::isNotBlank, + ValidationMessage.error(Localization.lang("Please enter a name for the name.")) + ); + + mimeTypeValidator = new FunctionBasedValidator<>( + mimeTypeProperty, + StringUtil::isNotBlank, + ValidationMessage.error(Localization.lang("Please enter a name for the MIME type.")) + ); + sameExtensionValidator = new FunctionBasedValidator<>( extensionProperty, extension -> { @@ -67,7 +82,8 @@ private void setupValidation() { }, ValidationMessage.error(Localization.lang("There is already an exists extension with the same name.")) ); - validator.addValidators(extensionValidator, sameExtensionValidator); + + validator.addValidators(extensionValidator, sameExtensionValidator, nameValidator, mimeTypeValidator); } public ValidationStatus validationStatus() { From 59e8ff4f80e5099f703db101b5b292e0ed724b11 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Mon, 11 Dec 2023 01:16:11 +0000 Subject: [PATCH 36/41] code reformatting --- .../externalfiletypes/ExternalFileTypesTabViewModelTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java index f587571b8b0..8c730d6b583 100644 --- a/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java +++ b/src/test/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModelTest.java @@ -76,7 +76,7 @@ public void WhenExternalFileTypeItemViewModelIsValidThenAddNewTypeIsSuccessful() externalFileTypesTabViewModel.addNewType(); ObservableList actualFileTypes = externalFileTypesTabViewModel.getFileTypes(); - assertEquals(actualFileTypes.size(), 1); + assertEquals(1, actualFileTypes.size()); assertTrue(viewModelIsSameValue(actualFileTypes.getFirst())); } @@ -93,6 +93,6 @@ public void WhenExternalFileTypeItemViewModelMissNameThenAddNewTypeIsFailed() { externalFileTypesTabViewModel.addNewType(); ObservableList emptyFileTypes = externalFileTypesTabViewModel.getFileTypes(); - assertEquals(emptyFileTypes.size(), 0); + assertEquals(0, emptyFileTypes.size()); } } From 0a2bcf039f22e32f20734dccf23e2e7fb121df6f Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Mon, 11 Dec 2023 01:29:03 +0000 Subject: [PATCH 37/41] reformatting code --- .../EditExternalFileTypeEntryDialog.java | 2 -- .../externalfiletypes/ExternalFileTypesTabViewModel.java | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java index 91d66003c35..73778e6d36e 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java @@ -39,8 +39,6 @@ public class EditExternalFileTypeEntryDialog extends BaseDialog { private final ObservableList fileTypes; private EditExternalFileTypeViewModel viewModel; - - public EditExternalFileTypeEntryDialog(ExternalFileTypeItemViewModel item, String dialogTitle, ObservableList fileTypes) { this.item = item; this.fileTypes = fileTypes; diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java index 89c639bb924..faacc66b978 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/ExternalFileTypesTabViewModel.java @@ -97,12 +97,12 @@ public void remove(ExternalFileTypeItemViewModel type) { } public boolean isValidExternalFileType(ExternalFileTypeItemViewModel item) { - if (withEmptyValue(item)){ + if (withEmptyValue(item)) { LOGGER.debug("One of the fields is empty or invalid."); return false; } - if(!isUniqueExtension(item)){ + if (!isUniqueExtension(item)) { LOGGER.debug("File Extension exists already."); return false; } @@ -110,11 +110,11 @@ public boolean isValidExternalFileType(ExternalFileTypeItemViewModel item) { return true; } - private boolean withEmptyValue(ExternalFileTypeItemViewModel item){ + private boolean withEmptyValue(ExternalFileTypeItemViewModel item) { return item.getName().isEmpty() || item.extensionProperty().get().isEmpty() || item.mimetypeProperty().get().isEmpty(); } - private boolean isUniqueExtension(ExternalFileTypeItemViewModel item){ + private boolean isUniqueExtension(ExternalFileTypeItemViewModel item) { // check extension need to be unique in the list String newExt = item.extensionProperty().get(); for (ExternalFileTypeItemViewModel fileTypeItem : fileTypes) { From 275cf4693cf8a784e2aef81abb09092ea86d1d13 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Mon, 11 Dec 2023 01:55:07 +0000 Subject: [PATCH 38/41] update language key --- .../externalfiletypes/EditExternalFileTypeViewModel.java | 2 +- src/main/resources/l10n/JabRef_en.properties | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java index c0c7644b95a..ee1083fcb47 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java @@ -61,7 +61,7 @@ private void setupValidation() { nameValidator = new FunctionBasedValidator<>( nameProperty, StringUtil::isNotBlank, - ValidationMessage.error(Localization.lang("Please enter a name for the name.")) + ValidationMessage.error(Localization.lang("Please enter a name.")) ); mimeTypeValidator = new FunctionBasedValidator<>( diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index ea1e11f80ae..8a36af400ca 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2040,6 +2040,11 @@ Matching=Matching Same\ as\ --import,\ but\ will\ be\ imported\ to\ the\ opened\ tab=Same as --import, but will be imported to the opened tab Allow\ integers\ in\ 'edition'\ field\ in\ BibTeX\ mode=Allow integers in 'edition' field in BibTeX mode +Please\ enter\ a\ name\ for\ the\ MIME\ type.=Please enter a name for the MIME type. +Please\ enter\ a\ name\ for\ the\ extension.=Please enter a name for the extension. +Please\ enter\ a\ name.=Please enter a name. +There\ is\ already\ an\ exists\ extension\ with\ the\ same\ name.=There is already an exists extension with the same name. + Search\ for\ citations\ in\ LaTeX\ files...=Search for citations in LaTeX files... LaTeX\ Citations\ Search\ Results=LaTeX Citations Search Results LaTeX\ files\ directory\:=LaTeX files directory: @@ -2622,7 +2627,7 @@ Enable=Enable Keep\ disabled=Keep disabled Predatory\ journal\ %0\ found=Predatory journal %0 found - + Hide\ user\ comments=Hide user comments Show\ user\ comments\ field=Show user comments field From fd0835fcf36ccd207a684579600b30dc4bc34952 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Tue, 12 Dec 2023 13:19:51 +0000 Subject: [PATCH 39/41] add unique name and mimetype validation for OK Button of EditExternalFileTypeView --- .../EditExternalFileTypeViewModel.java | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java index ee1083fcb47..fc6489fa2e0 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java @@ -26,16 +26,22 @@ public class EditExternalFileTypeViewModel { private final BooleanProperty customApplicationSelectedProperty = new SimpleBooleanProperty(false); private final ObservableList fileTypes; private final String originalExtension; + private final String originalName; + private final String originalMimeType; private Validator extensionValidator; private Validator nameValidator; private Validator mimeTypeValidator; private Validator sameExtensionValidator; + private Validator sameNameValidator; + private Validator sameMimeTypeValidator; private CompositeValidator validator; public EditExternalFileTypeViewModel(ExternalFileTypeItemViewModel fileTypeViewModel, ObservableList fileTypes) { this.fileTypeViewModel = fileTypeViewModel; this.fileTypes = fileTypes; this.originalExtension = fileTypeViewModel.extensionProperty().getValue(); + this.originalName = fileTypeViewModel.nameProperty().getValue(); + this.originalMimeType = fileTypeViewModel.mimetypeProperty().getValue(); extensionProperty.setValue(fileTypeViewModel.extensionProperty().getValue()); nameProperty.setValue(fileTypeViewModel.nameProperty().getValue()); mimeTypeProperty.setValue(fileTypeViewModel.mimetypeProperty().getValue()); @@ -80,10 +86,36 @@ private void setupValidation() { } return true; }, - ValidationMessage.error(Localization.lang("There is already an exists extension with the same name.")) + ValidationMessage.error(Localization.lang("There is already an same external file type with same extension exists")) ); - validator.addValidators(extensionValidator, sameExtensionValidator, nameValidator, mimeTypeValidator); + sameNameValidator = new FunctionBasedValidator<>( + nameProperty, + name -> { + for (ExternalFileTypeItemViewModel fileTypeItem : fileTypes) { + if (name.equalsIgnoreCase(fileTypeItem.nameProperty().get()) && !name.equalsIgnoreCase(originalName)) { + return false; + } + } + return true; + }, + ValidationMessage.error(Localization.lang("There is already an same external file type with same name exists")) + ); + + sameMimeTypeValidator = new FunctionBasedValidator<>( + mimeTypeProperty, + mimeType -> { + for (ExternalFileTypeItemViewModel fileTypeItem : fileTypes) { + if (mimeType.equalsIgnoreCase(fileTypeItem.mimetypeProperty().get()) && !mimeType.equalsIgnoreCase(originalMimeType)) { + return false; + } + } + return true; + }, + ValidationMessage.error(Localization.lang("There is already an same external file type with same MIME type exists")) + ); + + validator.addValidators(extensionValidator, sameExtensionValidator, nameValidator, sameNameValidator, mimeTypeValidator, sameMimeTypeValidator); } public ValidationStatus validationStatus() { From 134251d691209bab68a4c580dfbe0f2d564cddd2 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Tue, 12 Dec 2023 13:31:38 +0000 Subject: [PATCH 40/41] add message in JabRef_en.properties --- src/main/resources/l10n/JabRef_en.properties | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 8a36af400ca..314e7721ae5 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2043,7 +2043,9 @@ Allow\ integers\ in\ 'edition'\ field\ in\ BibTeX\ mode=Allow integers in 'editi Please\ enter\ a\ name\ for\ the\ MIME\ type.=Please enter a name for the MIME type. Please\ enter\ a\ name\ for\ the\ extension.=Please enter a name for the extension. Please\ enter\ a\ name.=Please enter a name. -There\ is\ already\ an\ exists\ extension\ with\ the\ same\ name.=There is already an exists extension with the same name. +There\ is\ already\ an\ same\ external\ file\ type\ with\ same\ MIME\ type\ exists=There is already an same external file type with same MIME type exists +There\ is\ already\ an\ same\ external\ file\ type\ with\ same\ extension\ exists=There is already an same external file type with same extension exists +There\ is\ already\ an\ same\ external\ file\ type\ with\ same\ name\ exists=There is already an same external file type with same name exists Search\ for\ citations\ in\ LaTeX\ files...=Search for citations in LaTeX files... LaTeX\ Citations\ Search\ Results=LaTeX Citations Search Results From b4e8c219d26088b2961ce5b0f75d8cb4d7a9bdba Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 16 Dec 2023 17:49:54 +0100 Subject: [PATCH 41/41] add validation visualizaion and improve error message grammar --- .../EditExternalFileTypeEntryDialog.java | 13 ++++ .../EditExternalFileTypeViewModel.java | 67 ++++++++++++------- src/main/resources/csl-styles | 2 +- src/main/resources/l10n/JabRef_en.properties | 8 ++- 4 files changed, 60 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java index 73778e6d36e..d0dc110b581 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeEntryDialog.java @@ -1,5 +1,6 @@ package org.jabref.gui.preferences.externalfiletypes; +import javafx.application.Platform; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; @@ -14,9 +15,11 @@ import org.jabref.gui.desktop.os.NativeDesktop; import org.jabref.gui.util.BaseDialog; import org.jabref.gui.util.FileDialogConfiguration; +import org.jabref.gui.util.IconValidationDecorator; import org.jabref.logic.util.OS; import com.airhacks.afterburner.views.ViewLoader; +import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer; import jakarta.inject.Inject; public class EditExternalFileTypeEntryDialog extends BaseDialog { @@ -39,6 +42,8 @@ public class EditExternalFileTypeEntryDialog extends BaseDialog { private final ObservableList fileTypes; private EditExternalFileTypeViewModel viewModel; + private final ControlsFxVisualizer visualizer = new ControlsFxVisualizer(); + public EditExternalFileTypeEntryDialog(ExternalFileTypeItemViewModel item, String dialogTitle, ObservableList fileTypes) { this.item = item; this.fileTypes = fileTypes; @@ -62,6 +67,8 @@ public EditExternalFileTypeEntryDialog(ExternalFileTypeItemViewModel item, Strin @FXML public void initialize() { + visualizer.setDecoration(new IconValidationDecorator()); + viewModel = new EditExternalFileTypeViewModel(item, fileTypes); icon.setGraphic(viewModel.getIcon()); @@ -74,6 +81,12 @@ public void initialize() { name.textProperty().bindBidirectional(viewModel.nameProperty()); mimeType.textProperty().bindBidirectional(viewModel.mimeTypeProperty()); selectedApplication.textProperty().bindBidirectional(viewModel.selectedApplicationProperty()); + + Platform.runLater(() -> { + visualizer.initVisualization(viewModel.extensionValidation(), extension, true); + visualizer.initVisualization(viewModel.nameValidation(), name, true); + visualizer.initVisualization(viewModel.mimeTypeValidation(), mimeType, true); + }); } @FXML diff --git a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java index fc6489fa2e0..e56aa5e5114 100644 --- a/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/externalfiletypes/EditExternalFileTypeViewModel.java @@ -28,12 +28,9 @@ public class EditExternalFileTypeViewModel { private final String originalExtension; private final String originalName; private final String originalMimeType; - private Validator extensionValidator; - private Validator nameValidator; - private Validator mimeTypeValidator; - private Validator sameExtensionValidator; - private Validator sameNameValidator; - private Validator sameMimeTypeValidator; + private CompositeValidator extensionValidator; + private CompositeValidator nameValidator; + private CompositeValidator mimeTypeValidator; private CompositeValidator validator; public EditExternalFileTypeViewModel(ExternalFileTypeItemViewModel fileTypeViewModel, ObservableList fileTypes) { @@ -58,25 +55,14 @@ public EditExternalFileTypeViewModel(ExternalFileTypeItemViewModel fileTypeViewM private void setupValidation() { validator = new CompositeValidator(); - extensionValidator = new FunctionBasedValidator<>( + extensionValidator = new CompositeValidator(); + + Validator extensionisNotBlankValidator = new FunctionBasedValidator<>( extensionProperty, StringUtil::isNotBlank, ValidationMessage.error(Localization.lang("Please enter a name for the extension.")) ); - - nameValidator = new FunctionBasedValidator<>( - nameProperty, - StringUtil::isNotBlank, - ValidationMessage.error(Localization.lang("Please enter a name.")) - ); - - mimeTypeValidator = new FunctionBasedValidator<>( - mimeTypeProperty, - StringUtil::isNotBlank, - ValidationMessage.error(Localization.lang("Please enter a name for the MIME type.")) - ); - - sameExtensionValidator = new FunctionBasedValidator<>( + Validator sameExtensionValidator = new FunctionBasedValidator<>( extensionProperty, extension -> { for (ExternalFileTypeItemViewModel fileTypeItem : fileTypes) { @@ -86,10 +72,12 @@ private void setupValidation() { } return true; }, - ValidationMessage.error(Localization.lang("There is already an same external file type with same extension exists")) + ValidationMessage.error(Localization.lang("There already exists an external file type with the same extension")) ); + extensionValidator.addValidators(sameExtensionValidator, extensionisNotBlankValidator); - sameNameValidator = new FunctionBasedValidator<>( + nameValidator = new CompositeValidator(); + Validator sameNameValidator = new FunctionBasedValidator<>( nameProperty, name -> { for (ExternalFileTypeItemViewModel fileTypeItem : fileTypes) { @@ -99,10 +87,24 @@ private void setupValidation() { } return true; }, - ValidationMessage.error(Localization.lang("There is already an same external file type with same name exists")) + ValidationMessage.error(Localization.lang("There already exists an external file type with the same name")) + ); + + Validator nameIsNotBlankValidator = new FunctionBasedValidator<>( + nameProperty, + StringUtil::isNotBlank, + ValidationMessage.error(Localization.lang("Please enter a name.")) + ); + nameValidator.addValidators(sameNameValidator, nameIsNotBlankValidator); + + mimeTypeValidator = new CompositeValidator(); + Validator mimeTypeIsNotBlankValidator = new FunctionBasedValidator<>( + mimeTypeProperty, + StringUtil::isNotBlank, + ValidationMessage.error(Localization.lang("Please enter a name for the MIME type.")) ); - sameMimeTypeValidator = new FunctionBasedValidator<>( + Validator sameMimeTypeValidator = new FunctionBasedValidator<>( mimeTypeProperty, mimeType -> { for (ExternalFileTypeItemViewModel fileTypeItem : fileTypes) { @@ -112,8 +114,9 @@ private void setupValidation() { } return true; }, - ValidationMessage.error(Localization.lang("There is already an same external file type with same MIME type exists")) + ValidationMessage.error(Localization.lang("There already exists an external file type with the same MIME type")) ); + mimeTypeValidator.addValidators(sameMimeTypeValidator, mimeTypeIsNotBlankValidator); validator.addValidators(extensionValidator, sameExtensionValidator, nameValidator, sameNameValidator, mimeTypeValidator, sameMimeTypeValidator); } @@ -122,6 +125,18 @@ public ValidationStatus validationStatus() { return validator.getValidationStatus(); } + public ValidationStatus extensionValidation() { + return extensionValidator.getValidationStatus(); + } + + public ValidationStatus mimeTypeValidation() { + return mimeTypeValidator.getValidationStatus(); + } + + public ValidationStatus nameValidation() { + return nameValidator.getValidationStatus(); + } + public Node getIcon() { return fileTypeViewModel.iconProperty().getValue().getGraphicNode(); } diff --git a/src/main/resources/csl-styles b/src/main/resources/csl-styles index a3d9a63426d..42f54b22d80 160000 --- a/src/main/resources/csl-styles +++ b/src/main/resources/csl-styles @@ -1 +1 @@ -Subproject commit a3d9a63426d2390068b4c98da6f48bd4ce73b257 +Subproject commit 42f54b22d8058c957404945b7dca5cc59c1fc68d diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 314e7721ae5..019dcfcd8ae 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2043,9 +2043,11 @@ Allow\ integers\ in\ 'edition'\ field\ in\ BibTeX\ mode=Allow integers in 'editi Please\ enter\ a\ name\ for\ the\ MIME\ type.=Please enter a name for the MIME type. Please\ enter\ a\ name\ for\ the\ extension.=Please enter a name for the extension. Please\ enter\ a\ name.=Please enter a name. -There\ is\ already\ an\ same\ external\ file\ type\ with\ same\ MIME\ type\ exists=There is already an same external file type with same MIME type exists -There\ is\ already\ an\ same\ external\ file\ type\ with\ same\ extension\ exists=There is already an same external file type with same extension exists -There\ is\ already\ an\ same\ external\ file\ type\ with\ same\ name\ exists=There is already an same external file type with same name exists + +There\ already\ exists\ an\ external\ file\ type\ with\ the\ same\ MIME\ type=There already exists an external file type with the same MIME type +There\ already\ exists\ an\ external\ file\ type\ with\ the\ same\ extension=There already exists an external file type with the same extension +There\ already\ exists\ an\ external\ file\ type\ with\ the\ same\ name=There already exists an external file type with the same name + Search\ for\ citations\ in\ LaTeX\ files...=Search for citations in LaTeX files... LaTeX\ Citations\ Search\ Results=LaTeX Citations Search Results