diff --git a/CHANGELOG.md b/CHANGELOG.md index 78686128d69..a1976aafae2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We added the possibility to automatically fetch entries when an ISBN is pasted on the main table. [#9864](https://github.com/JabRef/jabref/issues/9864) - We added the option to disable the automatic linking of files in the entry editor [#5105](https://github.com/JabRef/jabref/issues/5105) - We added the link icon for ISBNs in linked identifiers column. [#9819](https://github.com/JabRef/jabref/issues/9819) +- We added drag and drop events for field 'Groups' in entry editor panel. [#569](https://github.com/koppor/jabref/issues/569) - We added support for parsing MathML in the Medline importer. [#4273](https://github.com/JabRef/jabref/issues/4273) ### Changed diff --git a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java index 1b8f687b4f0..083c7717c9a 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java +++ b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java @@ -67,6 +67,8 @@ public static FieldEditorFX getForField(final Field field, return new IdentifierEditor(field, taskExecutor, dialogService, suggestionProvider, fieldCheckers, preferences); } else if (field == StandardField.OWNER) { return new OwnerEditor(field, preferences, suggestionProvider, fieldCheckers); + } else if (field == StandardField.GROUPS) { + return new GroupEditor(field, suggestionProvider, fieldCheckers, preferences, isMultiLine); } else if (fieldProperties.contains(FieldProperty.FILE_EDITOR)) { return new LinkedFilesEditor(field, dialogService, databaseContext, taskExecutor, suggestionProvider, fieldCheckers, preferences); } else if (fieldProperties.contains(FieldProperty.YES_NO)) { diff --git a/src/main/java/org/jabref/gui/fieldeditors/GroupEditor.java b/src/main/java/org/jabref/gui/fieldeditors/GroupEditor.java new file mode 100644 index 00000000000..db516806b03 --- /dev/null +++ b/src/main/java/org/jabref/gui/fieldeditors/GroupEditor.java @@ -0,0 +1,57 @@ +package org.jabref.gui.fieldeditors; + +import java.util.List; +import java.util.Optional; + +import javafx.scene.input.TransferMode; + +import org.jabref.gui.DragAndDropDataFormats; +import org.jabref.gui.autocompleter.SuggestionProvider; +import org.jabref.logic.integrity.FieldCheckers; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.StandardField; +import org.jabref.preferences.PreferencesService; + +public class GroupEditor extends SimpleEditor { + + private Optional bibEntry; + + public GroupEditor(final Field field, + final SuggestionProvider suggestionProvider, + final FieldCheckers fieldCheckers, + final PreferencesService preferences, + final boolean isMultiLine) { + super(field, suggestionProvider, fieldCheckers, preferences, isMultiLine); + + this.setOnDragOver(event -> { + if (event.getDragboard().hasContent(DragAndDropDataFormats.GROUP)) { + event.acceptTransferModes(TransferMode.MOVE); + } + event.consume(); + }); + + this.setOnDragDropped(event -> { + boolean success = false; + if (event.getDragboard().hasContent(DragAndDropDataFormats.GROUP)) { + List draggedGroups = (List) event.getDragboard().getContent(DragAndDropDataFormats.GROUP); + if (bibEntry.isPresent() && draggedGroups.get(0) != null) { + String newGroup = bibEntry.map(entry -> entry.getField(StandardField.GROUPS) + .map(oldGroups -> oldGroups + (preferences.getBibEntryPreferences().getKeywordSeparator()) + (draggedGroups.get(0))) + .orElse(draggedGroups.get(0))) + .orElse(null); + bibEntry.map(entry -> entry.setField(StandardField.GROUPS, newGroup)); + success = true; + } + } + event.setDropCompleted(success); + event.consume(); + }); + } + + @Override + public void bindToEntry(BibEntry entry) { + super.bindToEntry(entry); + this.bibEntry = Optional.of(entry); + } +}