From 6a26798aa88d49e72977cfbc464324baa73c9d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Lenhard?= Date: Sun, 27 Aug 2017 18:10:34 +0200 Subject: [PATCH] Add preference to disable validation in the entry editor by default (#3154) * Add preference to disable validation in the entry editor by default * Fix order of import statements * Remove Globals dependency from entry editor validation --- CHANGELOG.md | 1 + .../gui/fieldeditors/EditorValidator.java | 22 +++++++++++++++++++ .../jabref/gui/fieldeditors/FieldEditors.java | 14 ++++++------ .../gui/fieldeditors/IdentifierEditor.java | 8 +++---- .../gui/fieldeditors/JournalEditor.java | 11 ++++------ .../gui/fieldeditors/KeywordsEditor.java | 5 +++-- .../jabref/gui/fieldeditors/OwnerEditor.java | 5 +---- .../gui/fieldeditors/PersonsEditor.java | 11 ++++------ .../jabref/gui/fieldeditors/SimpleEditor.java | 8 +++---- .../jabref/gui/fieldeditors/UrlEditor.java | 8 +++---- .../jabref/preferences/JabRefPreferences.java | 2 ++ 11 files changed, 53 insertions(+), 42 deletions(-) create mode 100644 src/main/java/org/jabref/gui/fieldeditors/EditorValidator.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 638cea03704..e91f87e8ccd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# ### Changed +- We turned the validation feature in the entry editor off by default, because of a bug in the library we have been using [#3145](https://github.com/JabRef/jabref/issues/3145) - Added 'Filter All' and 'Filter None' buttons with corresponding functionality to Quality Check tool. - We increased the size of the keywords and file text areas in the entry editor - When the entry that is currently shown in the entry editor is deleted externally, the editor is now closed automatically [#2946](https://github.com/JabRef/jabref/issues/2946) diff --git a/src/main/java/org/jabref/gui/fieldeditors/EditorValidator.java b/src/main/java/org/jabref/gui/fieldeditors/EditorValidator.java new file mode 100644 index 00000000000..a380c2f29b5 --- /dev/null +++ b/src/main/java/org/jabref/gui/fieldeditors/EditorValidator.java @@ -0,0 +1,22 @@ +package org.jabref.gui.fieldeditors; + +import org.jabref.preferences.JabRefPreferences; + +import de.saxsys.mvvmfx.utils.validation.ValidationStatus; +import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer; + +public class EditorValidator { + + private final JabRefPreferences preferences; + + public EditorValidator(JabRefPreferences preferences) { + this.preferences = preferences; + } + + public void configureValidation(ValidationStatus status, EditorTextArea area) { + if (preferences.getBoolean(JabRefPreferences.VALIDATE_IN_ENTRY_EDITOR)) { + ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer(); + validationVisualizer.initVisualization(status, area); + } + } +} diff --git a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java index f75e13ebd8f..09e1328ee9c 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java +++ b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java @@ -34,18 +34,18 @@ public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecu FieldCheckers fieldCheckers = new FieldCheckers(databaseContext, preferences.getFileDirectoryPreferences()); - if (Globals.prefs.getTimestampPreferences().getTimestampField().equals(fieldName) || fieldExtras.contains(FieldProperty.DATE)) { + if (preferences.getTimestampPreferences().getTimestampField().equals(fieldName) || fieldExtras.contains(FieldProperty.DATE)) { if (fieldExtras.contains(FieldProperty.ISO_DATE)) { return new DateEditor(fieldName, DateTimeFormatter.ofPattern("[uuuu][-MM][-dd]"), suggestionProvider, fieldCheckers); } else { return new DateEditor(fieldName, DateTimeFormatter.ofPattern(Globals.prefs.getTimestampPreferences().getTimestampFormat()), suggestionProvider, fieldCheckers); } } else if (fieldExtras.contains(FieldProperty.EXTERNAL)) { - return new UrlEditor(fieldName, dialogService, suggestionProvider, fieldCheckers); + return new UrlEditor(fieldName, dialogService, suggestionProvider, fieldCheckers, preferences); } else if (fieldExtras.contains(FieldProperty.JOURNAL_NAME)) { - return new JournalEditor(fieldName, journalAbbreviationLoader, journalAbbreviationPreferences, suggestionProvider, fieldCheckers); + return new JournalEditor(fieldName, journalAbbreviationLoader, preferences, suggestionProvider, fieldCheckers); } else if (fieldExtras.contains(FieldProperty.DOI) || fieldExtras.contains(FieldProperty.EPRINT) || fieldExtras.contains(FieldProperty.ISBN)) { - return new IdentifierEditor(fieldName, taskExecutor, dialogService, suggestionProvider, fieldCheckers); + return new IdentifierEditor(fieldName, taskExecutor, dialogService, suggestionProvider, fieldCheckers, preferences); } else if (fieldExtras.contains(FieldProperty.OWNER)) { return new OwnerEditor(fieldName, preferences, suggestionProvider, fieldCheckers); } else if (fieldExtras.contains(FieldProperty.FILE_EDITOR)) { @@ -69,13 +69,13 @@ public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecu } else if (fieldExtras.contains(FieldProperty.SINGLE_ENTRY_LINK) || fieldExtras.contains(FieldProperty.MULTIPLE_ENTRY_LINK)) { return new LinkedEntriesEditor(fieldName, databaseContext, suggestionProvider, fieldCheckers); } else if (fieldExtras.contains(FieldProperty.PERSON_NAMES)) { - return new PersonsEditor(fieldName, suggestionProvider, preferences.getAutoCompletePreferences(), fieldCheckers); + return new PersonsEditor(fieldName, suggestionProvider, preferences, fieldCheckers); } else if (FieldName.KEYWORDS.equals(fieldName)) { - return new KeywordsEditor(fieldName, suggestionProvider, fieldCheckers); + return new KeywordsEditor(fieldName, suggestionProvider, fieldCheckers, preferences); } // default - return new SimpleEditor(fieldName, suggestionProvider, fieldCheckers); + return new SimpleEditor(fieldName, suggestionProvider, fieldCheckers, preferences); } @SuppressWarnings("unchecked") diff --git a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditor.java b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditor.java index d99389be2e6..12d546554a6 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditor.java @@ -21,8 +21,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.FieldName; - -import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer; +import org.jabref.preferences.JabRefPreferences; public class IdentifierEditor extends HBox implements FieldEditorFX { @@ -32,7 +31,7 @@ public class IdentifierEditor extends HBox implements FieldEditorFX { @FXML private Button lookupIdentifierButton; private Optional entry; - public IdentifierEditor(String fieldName, TaskExecutor taskExecutor, DialogService dialogService, AutoCompleteSuggestionProvider suggestionProvider, FieldCheckers fieldCheckers) { + public IdentifierEditor(String fieldName, TaskExecutor taskExecutor, DialogService dialogService, AutoCompleteSuggestionProvider suggestionProvider, FieldCheckers fieldCheckers, JabRefPreferences preferences) { this.viewModel = new IdentifierEditorViewModel(fieldName, suggestionProvider, taskExecutor, dialogService, fieldCheckers); ControlHelper.loadFXMLForControl(this); @@ -51,8 +50,7 @@ public IdentifierEditor(String fieldName, TaskExecutor taskExecutor, DialogServi menuItems.addAll(EditorMenus.getDefaultMenu(textArea)); textArea.addToContextMenu(menuItems); - ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer(); - validationVisualizer.initVisualization(viewModel.getFieldValidator().getValidationStatus(), textArea); + new EditorValidator(preferences).configureValidation(viewModel.getFieldValidator().getValidationStatus(), textArea); } public IdentifierEditorViewModel getViewModel() { diff --git a/src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java b/src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java index 71eb2bacbc6..5bf822128fa 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java @@ -13,10 +13,8 @@ import org.jabref.gui.util.ControlHelper; import org.jabref.logic.integrity.FieldCheckers; import org.jabref.logic.journals.JournalAbbreviationLoader; -import org.jabref.logic.journals.JournalAbbreviationPreferences; import org.jabref.model.entry.BibEntry; - -import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer; +import org.jabref.preferences.JabRefPreferences; public class JournalEditor extends HBox implements FieldEditorFX { @@ -24,8 +22,8 @@ public class JournalEditor extends HBox implements FieldEditorFX { @FXML private EditorTextArea textArea; private Optional entry; - public JournalEditor(String fieldName, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences, AutoCompleteSuggestionProvider suggestionProvider, FieldCheckers fieldCheckers) { - this.viewModel = new JournalEditorViewModel(fieldName, suggestionProvider, journalAbbreviationLoader, journalAbbreviationPreferences, fieldCheckers); + public JournalEditor(String fieldName, JournalAbbreviationLoader journalAbbreviationLoader, JabRefPreferences preferences, AutoCompleteSuggestionProvider suggestionProvider, FieldCheckers fieldCheckers) { + this.viewModel = new JournalEditorViewModel(fieldName, suggestionProvider, journalAbbreviationLoader, preferences.getJournalAbbreviationPreferences(), fieldCheckers); ControlHelper.loadFXMLForControl(this); @@ -34,8 +32,7 @@ public JournalEditor(String fieldName, JournalAbbreviationLoader journalAbbrevia AutoCompletionTextInputBinding.autoComplete(textArea, viewModel::complete); - ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer(); - validationVisualizer.initVisualization(viewModel.getFieldValidator().getValidationStatus(), textArea); + new EditorValidator(preferences).configureValidation(viewModel.getFieldValidator().getValidationStatus(), textArea); } public JournalEditorViewModel getViewModel() { diff --git a/src/main/java/org/jabref/gui/fieldeditors/KeywordsEditor.java b/src/main/java/org/jabref/gui/fieldeditors/KeywordsEditor.java index 65d0f49e344..b0d46e749fc 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/KeywordsEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/KeywordsEditor.java @@ -2,11 +2,12 @@ import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.integrity.FieldCheckers; +import org.jabref.preferences.JabRefPreferences; public class KeywordsEditor extends SimpleEditor implements FieldEditorFX { - public KeywordsEditor(String fieldName, AutoCompleteSuggestionProvider suggestionProvider, FieldCheckers fieldCheckers) { - super (fieldName, suggestionProvider, fieldCheckers); + public KeywordsEditor(String fieldName, AutoCompleteSuggestionProvider suggestionProvider, FieldCheckers fieldCheckers, JabRefPreferences preferences) { + super (fieldName, suggestionProvider, fieldCheckers, preferences); } @Override diff --git a/src/main/java/org/jabref/gui/fieldeditors/OwnerEditor.java b/src/main/java/org/jabref/gui/fieldeditors/OwnerEditor.java index c1558ed8899..0b05e11ca5f 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/OwnerEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/OwnerEditor.java @@ -11,8 +11,6 @@ import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; -import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer; - public class OwnerEditor extends HBox implements FieldEditorFX { @FXML private OwnerEditorViewModel viewModel; @@ -25,8 +23,7 @@ public OwnerEditor(String fieldName, JabRefPreferences preferences, AutoComplete textArea.textProperty().bindBidirectional(viewModel.textProperty()); - ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer(); - validationVisualizer.initVisualization(viewModel.getFieldValidator().getValidationStatus(), textArea); + new EditorValidator(preferences).configureValidation(viewModel.getFieldValidator().getValidationStatus(), textArea); } public OwnerEditorViewModel getViewModel() { diff --git a/src/main/java/org/jabref/gui/fieldeditors/PersonsEditor.java b/src/main/java/org/jabref/gui/fieldeditors/PersonsEditor.java index f328bbb59bc..9e5afaf0cc0 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/PersonsEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/PersonsEditor.java @@ -5,21 +5,19 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; -import org.jabref.gui.autocompleter.AutoCompletePreferences; import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.autocompleter.AutoCompletionTextInputBinding; import org.jabref.gui.fieldeditors.contextmenu.EditorMenus; import org.jabref.logic.integrity.FieldCheckers; import org.jabref.model.entry.BibEntry; - -import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer; +import org.jabref.preferences.JabRefPreferences; public class PersonsEditor extends HBox implements FieldEditorFX { @FXML private final PersonsEditorViewModel viewModel; - public PersonsEditor(String fieldName, AutoCompleteSuggestionProvider suggestionProvider, AutoCompletePreferences autoCompletePreferences, FieldCheckers fieldCheckers) { - this.viewModel = new PersonsEditorViewModel(fieldName, suggestionProvider, autoCompletePreferences, fieldCheckers); + public PersonsEditor(String fieldName, AutoCompleteSuggestionProvider suggestionProvider, JabRefPreferences preferences, FieldCheckers fieldCheckers) { + this.viewModel = new PersonsEditorViewModel(fieldName, suggestionProvider, preferences.getAutoCompletePreferences(), fieldCheckers); EditorTextArea textArea = new EditorTextArea(); HBox.setHgrow(textArea, Priority.ALWAYS); @@ -29,8 +27,7 @@ public PersonsEditor(String fieldName, AutoCompleteSuggestionProvider suggest AutoCompletionTextInputBinding.autoComplete(textArea, viewModel::complete, viewModel.getAutoCompletionConverter(), viewModel.getAutoCompletionStrategy()); - ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer(); - validationVisualizer.initVisualization(viewModel.getFieldValidator().getValidationStatus(), textArea); + new EditorValidator(preferences).configureValidation(viewModel.getFieldValidator().getValidationStatus(), textArea); } @Override diff --git a/src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java b/src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java index 168a3819a7a..00e0e991183 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java @@ -11,14 +11,13 @@ import org.jabref.gui.fieldeditors.contextmenu.EditorMenus; import org.jabref.logic.integrity.FieldCheckers; import org.jabref.model.entry.BibEntry; - -import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer; +import org.jabref.preferences.JabRefPreferences; public class SimpleEditor extends HBox implements FieldEditorFX { @FXML private final SimpleEditorViewModel viewModel; - public SimpleEditor(String fieldName, AutoCompleteSuggestionProvider suggestionProvider, FieldCheckers fieldCheckers) { + public SimpleEditor(String fieldName, AutoCompleteSuggestionProvider suggestionProvider, FieldCheckers fieldCheckers, JabRefPreferences preferences) { this.viewModel = new SimpleEditorViewModel(fieldName, suggestionProvider, fieldCheckers); EditorTextArea textArea = new EditorTextArea(); @@ -33,8 +32,7 @@ public SimpleEditor(String fieldName, AutoCompleteSuggestionProvider suggesti autoCompleter.setShowOnFocus(true); } - ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer(); - validationVisualizer.initVisualization(viewModel.getFieldValidator().getValidationStatus(), textArea); + new EditorValidator(preferences).configureValidation(viewModel.getFieldValidator().getValidationStatus(), textArea); } @Override diff --git a/src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java b/src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java index 7a621b5325a..558f6de516c 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java @@ -10,23 +10,21 @@ import org.jabref.gui.util.ControlHelper; import org.jabref.logic.integrity.FieldCheckers; import org.jabref.model.entry.BibEntry; - -import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer; +import org.jabref.preferences.JabRefPreferences; public class UrlEditor extends HBox implements FieldEditorFX { @FXML private UrlEditorViewModel viewModel; @FXML private EditorTextArea textArea; - public UrlEditor(String fieldName, DialogService dialogService, AutoCompleteSuggestionProvider suggestionProvider, FieldCheckers fieldCheckers) { + public UrlEditor(String fieldName, DialogService dialogService, AutoCompleteSuggestionProvider suggestionProvider, FieldCheckers fieldCheckers, JabRefPreferences preferences) { this.viewModel = new UrlEditorViewModel(fieldName, suggestionProvider, dialogService, fieldCheckers); ControlHelper.loadFXMLForControl(this); textArea.textProperty().bindBidirectional(viewModel.textProperty()); - ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer(); - validationVisualizer.initVisualization(viewModel.getFieldValidator().getValidationStatus(), textArea); + new EditorValidator(preferences).configureValidation(viewModel.getFieldValidator().getValidationStatus(), textArea); } public UrlEditorViewModel getViewModel() { diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 78ad2e63395..1b37d7777ba 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -314,6 +314,7 @@ public class JabRefPreferences implements PreferencesService { public static final String NAME_FORMATER_KEY = "nameFormatterNames"; public static final String PUSH_TO_APPLICATION = "pushToApplication"; public static final String SHOW_RECOMMENDATIONS = "showRecommendations"; + public static final String VALIDATE_IN_ENTRY_EDITOR = "validateInEntryEditor"; // Dropped file handler public static final String DROPPEDFILEHANDLER_RENAME = "DroppedFileHandler_RenameFile"; public static final String DROPPEDFILEHANDLER_MOVE = "DroppedFileHandler_MoveFile"; @@ -572,6 +573,7 @@ private JabRefPreferences() { defaults.put(MERGE_ENTRIES_DIFF_MODE, 2); defaults.put(SHOW_RECOMMENDATIONS, Boolean.TRUE); + defaults.put(VALIDATE_IN_ENTRY_EDITOR, Boolean.FALSE); defaults.put(EDITOR_EMACS_KEYBINDINGS, Boolean.FALSE); defaults.put(EDITOR_EMACS_KEYBINDINGS_REBIND_CA, Boolean.TRUE); defaults.put(EDITOR_EMACS_KEYBINDINGS_REBIND_CF, Boolean.TRUE);