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 drag and drop in EntryEditor #9965

Merged
merged 18 commits into from
Jun 5, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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 @@ -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)) {
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/org/jabref/gui/fieldeditors/GroupEditor.java
Original file line number Diff line number Diff line change
@@ -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> 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<String> draggedGroups = (List<String>) 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);
}
}