Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into improve-DOI-import-…
Browse files Browse the repository at this point in the history
…failure-dialog

* upstream/main:
  Reworded t in pr (JabRef#8989)
  Fixed checkstyle (JabRef#8990)
  Fix RfcFetcherTest (JabRef#8988)
  Fixes JabRef#521 - Allow to drag&drop selected bib entries to other library tabs (JabRef#8982)

# Conflicts:
#	src/main/java/org/jabref/gui/maintable/MainTable.java
#	src/test/java/org/jabref/logic/importer/fetcher/JstorFetcherTest.java
  • Loading branch information
Siedlerchr committed Jul 19, 2022
2 parents 5060e34 + be4a7c5 commit b8a83ac
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We added an extra option in the 'Find Unlinked Files' dialog view to ignore unnecessary files like Thumbs.db, DS_Store, etc. [koppor#373](https://github.com/koppor/jabref/issues/373)
- JabRef now writes log files. Linux: `$home/.cache/jabref/logs/version`, Windows: `%APPDATA%\..\Local\harawata\jabref\version\logs`, Mac: `Users/.../Library/Logs/jabref/version`
- We added an importer for Citavi backup files, support ".ctv5bak" and ".ctv6bak" file formats. [#8322](https://github.com/JabRef/jabref/issues/8322)
- We added a feature to drag selected entries and drop them to other opened inactive library tabs [koppor521](https://github.com/koppor/jabref/issues/521).

### Changed

Expand Down
48 changes: 48 additions & 0 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,54 @@ private void initDragAndDrop() {
} else {
tabbedPane.getTabs().remove(dndIndicator);
}
// Accept drag entries from MainTable
if (event.getDragboard().hasContent(DragAndDropDataFormats.ENTRIES)) {
event.acceptTransferModes(TransferMode.COPY);
event.consume();
}
});

this.getScene().setOnDragEntered(event -> {
// It is necessary to setOnDragOver for newly opened tabs
// drag'n'drop on tabs covered dnd on tabbedPane, so dnd on tabs should contain all dnds on tabbedPane
tabbedPane.lookupAll(".tab").forEach(tab -> {
tab.setOnDragOver(tabDragEvent -> {
if (DragAndDropHelper.hasBibFiles(tabDragEvent.getDragboard())) {
tabDragEvent.acceptTransferModes(TransferMode.ANY);
if (!tabbedPane.getTabs().contains(dndIndicator)) {
tabbedPane.getTabs().add(dndIndicator);
}
event.consume();
} else {
tabbedPane.getTabs().remove(dndIndicator);
}

if (tabDragEvent.getDragboard().hasContent(DragAndDropDataFormats.ENTRIES)) {
tabDragEvent.acceptTransferModes(TransferMode.COPY);
tabDragEvent.consume();
}
});
tab.setOnDragExited(event1 -> tabbedPane.getTabs().remove(dndIndicator));
tab.setOnDragDropped(tabDragEvent -> {
if (DragAndDropHelper.hasBibFiles(tabDragEvent.getDragboard())) {
tabbedPane.getTabs().remove(dndIndicator);
List<Path> bibFiles = DragAndDropHelper.getBibFiles(tabDragEvent.getDragboard());
OpenDatabaseAction openDatabaseAction = this.getOpenDatabaseAction();
openDatabaseAction.openFiles(bibFiles, true);
tabDragEvent.setDropCompleted(true);
tabDragEvent.consume();
} else {
for (Tab libraryTab : tabbedPane.getTabs()) {
if (libraryTab.getId().equals(tab.getId()) &&
!tabbedPane.getSelectionModel().getSelectedItem().equals(libraryTab)) {
((LibraryTab) libraryTab).dropEntry(stateManager.getLocalDragboard().getBibEntries());
}
}
tabDragEvent.consume();
}
});
});
event.consume();
});

this.getScene().setOnDragExited(event -> tabbedPane.getTabs().remove(dndIndicator));
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Random;

import javafx.animation.PauseTransition;
import javafx.application.Platform;
Expand Down Expand Up @@ -157,6 +158,10 @@ public LibraryTab(JabRefFrame frame,

this.entryEditor = new EntryEditor(this, externalFileTypes);

// set LibraryTab ID for drag'n'drop
// ID content doesn't matter, we only need different tabs to have different ID
this.setId(Long.valueOf(new Random().nextLong()).toString());

Platform.runLater(() -> {
EasyBind.subscribe(changedProperty, this::updateTabTitle);
stateManager.getOpenDatabases().addListener((ListChangeListener<BibDatabaseContext>) c ->
Expand Down Expand Up @@ -764,6 +769,10 @@ public void paste() {
mainTable.paste();
}

public void dropEntry(List<BibEntry> entriesToAdd) {
mainTable.dropEntry(entriesToAdd);
}

public void cut() {
mainTable.cut();
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ private List<BibEntry> handleNonBibteXStringData() {
}
}
return entries;

public void dropEntry(List<BibEntry> entriesToAdd) {
for (BibEntry entry : entriesToAdd) {
importHandler.importEntryWithDuplicateCheck(database, (BibEntry) entry.clone());
}
}

private void handleOnDragOver(TableRow<BibEntryTableViewModel> row, BibEntryTableViewModel item, DragEvent event) {
Expand Down Expand Up @@ -383,8 +388,9 @@ private void handleOnDragDetected(TableRow<BibEntryTableViewModel> row, BibEntry

// The following is necesary to initiate the drag and drop in javafx, although we don't need the contents
// It doesn't work without
// Drag'n'drop to other tabs use COPY TransferMode, drop to group sidepane use MOVE
ClipboardContent content = new ClipboardContent();
Dragboard dragboard = startDragAndDrop(TransferMode.MOVE);
Dragboard dragboard = startDragAndDrop(TransferMode.COPY_OR_MOVE);
content.put(DragAndDropDataFormats.ENTRIES, "");
dragboard.setContent(content);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

@FetcherTest
@Disabled("CiteSeer is down as of 2022-07-18")
class CiteSeerTest {

private CiteSeer fetcher = new CiteSeer();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.jabref.logic.importer.fetcher;

import java.io.IOException;
import java.net.URL;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.SearchBasedFetcher;
import org.jabref.model.entry.BibEntry;
Expand Down Expand Up @@ -40,8 +40,7 @@ public class JstorFetcherTest implements SearchBasedFetcherCapabilityTest {
.withField(StandardField.PAGES, "63--73")
.withField(StandardField.VOLUME, "20")
.withField(StandardField.URL, "http://www.jstor.org/stable/90002164")
.withField(StandardField.YEAR, "2017")
.withField(StandardField.URLDATE, "2022-07-16");
.withField(StandardField.YEAR, "2017");

private final BibEntry doiEntry = new BibEntry(StandardEntryType.Article)
.withCitationKey("10.1086/501484")
Expand All @@ -64,13 +63,19 @@ void searchByTitle() throws Exception {
}

@Test
void searchById() throws FetcherException {
void searchById() throws Exception {
bibEntry.setField(StandardField.URLDATE, LocalDate.now().format(DateTimeFormatter.ISO_DATE));
assertEquals(Optional.of(bibEntry), fetcher.performSearchById("90002164"));
}

@Test
void searchByUrlUsingId() throws Exception {
doiEntry.setField(StandardField.URLDATE, LocalDate.now().format(DateTimeFormatter.ISO_DATE));
assertEquals(Optional.of(doiEntry), fetcher.performSearchById("https://www.jstor.org/stable/10.1086/501484?seq=1"));
}

@Test
void fetchPDF() throws IOException {
void fetchPDF() throws Exception {
Optional<URL> url = fetcher.findFullText(bibEntry);
assertEquals(Optional.of(new URL("https://www.jstor.org/stable/pdf/90002164.pdf")), url);
}
Expand Down

0 comments on commit b8a83ac

Please sign in to comment.