Skip to content

Commit

Permalink
Fix content selector present for custom entry type (JabRef#11371)
Browse files Browse the repository at this point in the history
* Fix typos

* Add JavaDoc

* Group map-based field editors into org.jabref.gui.fieldeditors.mapbased

* Introduce package org.jabref.gui.fieldeditors.optioneditors

* Introduce StringMapBasedEditorViewModel

* Use selector dropdown only if there if selections are available

* Fix import
  • Loading branch information
koppor authored Jun 13, 2024
1 parent c5a03d5 commit e0333c4
Show file tree
Hide file tree
Showing 19 changed files with 221 additions and 246 deletions.

This file was deleted.

This file was deleted.

22 changes: 18 additions & 4 deletions src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
import org.jabref.gui.autocompleter.SuggestionProvider;
import org.jabref.gui.autocompleter.SuggestionProviders;
import org.jabref.gui.fieldeditors.identifier.IdentifierEditor;
import org.jabref.gui.fieldeditors.optioneditors.MonthEditorViewModel;
import org.jabref.gui.fieldeditors.optioneditors.OptionEditor;
import org.jabref.gui.fieldeditors.optioneditors.mapbased.CustomFieldEditorViewModel;
import org.jabref.gui.fieldeditors.optioneditors.mapbased.EditorTypeEditorViewModel;
import org.jabref.gui.fieldeditors.optioneditors.mapbased.GenderEditorViewModel;
import org.jabref.gui.fieldeditors.optioneditors.mapbased.PaginationEditorViewModel;
import org.jabref.gui.fieldeditors.optioneditors.mapbased.PatentTypeEditorViewModel;
import org.jabref.gui.fieldeditors.optioneditors.mapbased.TypeEditorViewModel;
import org.jabref.gui.fieldeditors.optioneditors.mapbased.YesNoEditorViewModel;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.integrity.FieldCheckers;
import org.jabref.logic.journals.JournalAbbreviationRepository;
Expand Down Expand Up @@ -98,11 +107,16 @@ public static FieldEditorFX getForField(final Field field,
return new CitationKeyEditor(field, suggestionProvider, fieldCheckers, databaseContext);
} else if (fieldProperties.contains(FieldProperty.MARKDOWN)) {
return new MarkdownEditor(field, suggestionProvider, fieldCheckers, preferences, undoManager);
} else if (fieldProperties.contains(FieldProperty.CUSTOM_FIELD) && !isMultiLine) {
return new OptionEditor<>(new CustomFieldEditorViewModel(field, suggestionProvider, fieldCheckers, undoManager, databaseContext));
} else {
// default
return new SimpleEditor(field, suggestionProvider, fieldCheckers, preferences, isMultiLine, undoManager);
// There was no specific editor found

// Check whether there are selectors defined for the field at hand
List<String> selectorValues = databaseContext.getMetaData().getContentSelectorValuesForField(field);
if (!isMultiLine && !selectorValues.isEmpty()) {
return new OptionEditor<>(new CustomFieldEditorViewModel(field, suggestionProvider, fieldCheckers, undoManager, selectorValues));
} else {
return new SimpleEditor(field, suggestionProvider, fieldCheckers, preferences, isMultiLine, undoManager);
}
}
}

Expand Down

This file was deleted.

This file was deleted.

40 changes: 0 additions & 40 deletions src/main/java/org/jabref/gui/fieldeditors/TypeEditorViewModel.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.jabref.gui.fieldeditors;
package org.jabref.gui.fieldeditors.optioneditors;

import java.util.Arrays;
import java.util.List;
import java.util.Collection;

import javax.swing.undo.UndoManager;

Expand Down Expand Up @@ -50,7 +50,7 @@ public Month fromString(String string) {
}

@Override
public List<Month> getItems() {
public Collection<Month> getItems() {
return Arrays.asList(Month.values());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.layout.HBox?>
<fx:root xmlns:fx="http://javafx.com/fxml/1" type="HBox" xmlns="http://javafx.com/javafx/8.0.112"
fx:controller="org.jabref.gui.fieldeditors.OptionEditor">
fx:controller="org.jabref.gui.fieldeditors.optioneditors.OptionEditor">
<ComboBox fx:id="comboBox" editable="true" prefHeight="0" HBox.hgrow="ALWAYS" maxHeight="Infinity"
maxWidth="Infinity"/>
</fx:root>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jabref.gui.fieldeditors;
package org.jabref.gui.fieldeditors.optioneditors;

import javafx.fxml.FXML;
import javafx.scene.Parent;
Expand All @@ -7,6 +7,7 @@
import javafx.scene.layout.HBox;

import org.jabref.gui.Globals;
import org.jabref.gui.fieldeditors.FieldEditorFX;
import org.jabref.gui.fieldeditors.contextmenu.EditorContextAction;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.model.entry.BibEntry;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.jabref.gui.fieldeditors;
package org.jabref.gui.fieldeditors.optioneditors;

import java.util.List;
import java.util.Collection;

import javax.swing.undo.UndoManager;

import javafx.util.StringConverter;

import org.jabref.gui.autocompleter.SuggestionProvider;
import org.jabref.gui.fieldeditors.AbstractEditorViewModel;
import org.jabref.logic.integrity.FieldCheckers;
import org.jabref.model.entry.field.Field;

Expand All @@ -16,9 +17,18 @@ public OptionEditorViewModel(Field field, SuggestionProvider<?> suggestionProvid
super(field, suggestionProvider, fieldCheckers, undoManager);
}

/**
* Converts the user input to a String used in BibTeX
*/
public abstract StringConverter<T> getStringConverter();

public abstract List<T> getItems();
/**
* Returns all available items
*/
public abstract Collection<T> getItems();

/**
* Used for filling the ComboBox for selecting a value. Needs to return something meaningful for each item in {@link #getItems()}
*/
public abstract String convertToDisplayText(T object);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.jabref.gui.fieldeditors.optioneditors.mapbased;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.undo.UndoManager;

import org.jabref.gui.autocompleter.SuggestionProvider;
import org.jabref.logic.integrity.FieldCheckers;
import org.jabref.model.entry.field.Field;

public class CustomFieldEditorViewModel extends StringMapBasedEditorViewModel {

public CustomFieldEditorViewModel(Field field, SuggestionProvider<?> suggestionProvider,
FieldCheckers fieldCheckers, UndoManager undoManager, List<String> selectorValues) {
super(field, suggestionProvider, fieldCheckers, undoManager, getMap(selectorValues));
}

private static Map<String, String> getMap(List<String> selectorValues) {
Map<String, String> map = new HashMap<>();
for (String value : selectorValues) {
map.put(value, value);
}
return map;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.jabref.gui.fieldeditors.optioneditors.mapbased;

import java.util.Map;

import javax.swing.undo.UndoManager;

import org.jabref.gui.autocompleter.SuggestionProvider;
import org.jabref.logic.integrity.FieldCheckers;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.entry.field.Field;

public class EditorTypeEditorViewModel extends StringMapBasedEditorViewModel {

public EditorTypeEditorViewModel(Field field, SuggestionProvider<?> suggestionProvider, FieldCheckers fieldCheckers, UndoManager undoManager) {
super(field, suggestionProvider, fieldCheckers, undoManager, Map.of(
"editor", Localization.lang("Editor"),
"compiler", Localization.lang("Compiler"),
"founder", Localization.lang("Founder"),
"continuator", Localization.lang("Continuator"),
"redactor", Localization.lang("Redactor"),
"reviser", Localization.lang("Reviser"),
"collaborator", Localization.lang("Collaborator")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.jabref.gui.fieldeditors.optioneditors.mapbased;

import java.util.Map;

import javax.swing.undo.UndoManager;

import org.jabref.gui.autocompleter.SuggestionProvider;
import org.jabref.logic.integrity.FieldCheckers;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.entry.field.Field;

public class GenderEditorViewModel extends StringMapBasedEditorViewModel {

public GenderEditorViewModel(Field field, SuggestionProvider<?> suggestionProvider, FieldCheckers fieldCheckers, UndoManager undoManager) {
super(field, suggestionProvider, fieldCheckers, undoManager, Map.of(
"sf", Localization.lang("Female name"),
"sm", Localization.lang("Male name"),
"sn", Localization.lang("Neuter name"),
"pf", Localization.lang("Female names"),
"pm", Localization.lang("Male names"),
"pn", Localization.lang("Neuter names"),
"pp", Localization.lang("Mixed names")));
}
}
Loading

0 comments on commit e0333c4

Please sign in to comment.