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 2 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Added

- We added a new keyboard shortcut <kbd>ctrl</kbd> + <kbd>,</kbd> to open the preferences. [#11154](https://github.com/JabRef/jabref/pull/11154)
- [azatayamanaev](https://github.com/azatyamanaev) added value selection(like for month) for content selectors in custom entry types. [#11109](https://github.com/JabRef/jabref/issues/11109)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not include our names here. Names are already part of the commit and committers will be highlighted at the release blog posts


### Changed

### Fixed
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;
}
}
5 changes: 4 additions & 1 deletion 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 All @@ -112,7 +114,8 @@ private static SuggestionProvider<?> getSuggestionProvider(Field field, Suggesti
// Enrich auto completion by content selector values
try {
return new ContentSelectorSuggestionProvider((SuggestionProvider<String>) suggestionProvider, contentSelectorValues);
} catch (ClassCastException exception) {
} catch (
ClassCastException exception) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unfortuantely an intellih formatting bug, please move this back to the previous line

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@azatyamanaev Do you use IntelliJ 2024.1 or something of 2023?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I use 2024.1

LOGGER.error("Content selectors are only supported for normal fields with string-based auto completion.");
return suggestionProvider;
}
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