Skip to content

Commit

Permalink
Add value selection(like for month) for custom fields (#11162)
Browse files Browse the repository at this point in the history
* Add editor class for custom fields to enable value selection from a dropdown

* resolve conflicts with CHANGELOG.md

* fix formatting in FieldEditors and remove contributor name in CHANGELOG

* Update CHANGELOG.md

---------

Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
  • Loading branch information
azatyamanaev and koppor committed Apr 8, 2024
1 parent 1ee1add commit 6e6523f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 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 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

- We added support for offline extracting refereferences from PDFs following the IEEE format. [#11156](https://github.com/JabRef/jabref/pull/11156)
- We added a new keyboard shortcut <kbd>ctrl</kbd> + <kbd>,</kbd> to open the preferences. [#11154](https://github.com/JabRef/jabref/pull/11154)
- We added value selection (such as for month) for content selectors in custom entry types. [#11109](https://github.com/JabRef/jabref/issues/11109)

### Changed

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.jabref.gui.fieldeditors;

import java.util.List;

import javax.swing.undo.UndoManager;

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

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;

public class CustomFieldEditorViewModel extends MapBasedEditorViewModel<String> {

private BiMap<String, String> itemMap;

public CustomFieldEditorViewModel(Field field, SuggestionProvider<?> suggestionProvider,
FieldCheckers fieldCheckers, UndoManager undoManager, BibDatabaseContext databaseContext) {
super(field, suggestionProvider, fieldCheckers, undoManager);

List<String> values = databaseContext.getMetaData().getContentSelectorValuesForField(field);
itemMap = HashBiMap.create(values.size());
for (String value : values) {
itemMap.put(value, value);
}
}

@Override
protected BiMap<String, String> getItemMap() {
return itemMap;
}

@Override
public String convertToDisplayText(String object) {
return object;
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ public enum FieldProperty {
TYPE,
VERBATIM,
YES_NO,
COMMENT
COMMENT,
CUSTOM_FIELD
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public UnknownField(String name, String displayName, FieldProperty first, FieldP
}

public static UnknownField fromDisplayName(String displayName) {
return new UnknownField(displayName.toLowerCase(Locale.ROOT), displayName);
return new UnknownField(displayName.toLowerCase(Locale.ROOT), displayName, FieldProperty.CUSTOM_FIELD);
}

@Override
Expand Down

0 comments on commit 6e6523f

Please sign in to comment.