Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add value selection(like for month) for custom fields #11162

Merged
merged 5 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading