-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Changes from 2 commits
d5c219c
a6a5ad7
04e7d14
5c9db09
83f5682
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @azatyamanaev Do you use IntelliJ 2024.1 or something of 2023? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,5 +26,6 @@ public enum FieldProperty { | |
TYPE, | ||
VERBATIM, | ||
YES_NO, | ||
COMMENT | ||
COMMENT, | ||
CUSTOM_FIELD | ||
} |
There was a problem hiding this comment.
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