Skip to content

Commit

Permalink
Add preference to disable validation in the entry editor by default (#…
Browse files Browse the repository at this point in the history
…3154)

* Add preference to disable validation in the entry editor by default

* Fix order of import statements

* Remove Globals dependency from entry editor validation
  • Loading branch information
lenhard authored Aug 27, 2017
1 parent 9b9cb46 commit 6a26798
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/org/jabref/gui/fieldeditors/EditorValidator.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
14 changes: 7 additions & 7 deletions src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -32,7 +31,7 @@ public class IdentifierEditor extends HBox implements FieldEditorFX {
@FXML private Button lookupIdentifierButton;
private Optional<BibEntry> 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);
Expand All @@ -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() {
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@
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 {

@FXML private JournalEditorViewModel viewModel;
@FXML private EditorTextArea textArea;
private Optional<BibEntry> 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);

Expand All @@ -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() {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/jabref/gui/fieldeditors/KeywordsEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/org/jabref/gui/fieldeditors/OwnerEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/org/jabref/gui/fieldeditors/PersonsEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6a26798

Please sign in to comment.