Skip to content

Commit

Permalink
Implement drag and drop for maintable (#3765)
Browse files Browse the repository at this point in the history
* Implement drag and drop for maintable
TODO: DataFormat - Whole entries?

* Use BibtexWriter to serialize all entries and parser to deserialize

* try further around with serializing and deserializing

* Add new Dataformat for List<BibEntry>
Add LocalDragboard

* Add DragAndDropDataFormat

* drag and drop to groups works now

* Prepare File Dropping

* No reordering of items in the maintable via drag and drop
Rename getEntriesFiltered to better distinguish it

* add basic support for adding droppped file to entry

* add check for transfer mode move and link

* Add link to file handler
Add files and move them to file directory via cleanup operation
Remove unsused parameter LayoutFormatterPreferences from  Cleanup

* add dialog for importing entries from xmp

* prepare pdf content importer code
Add missing keybinding

* remove no longer needed loop

* add XMPPreferences to ImportFormatPreferences
add dialog to show if new entrie should be imported or file linked

* when no modifier is avaiable show Dialog if xmp entries found

* rework copy options using clipboard manager

* TODO: Find out why  dnd  doesn't work on preview panel

* fix checkstyle and compile error

* enable dnd on preview pane

* add method for opening or import db

* add l10n

* checkstyle

* Open bib files dragged to tab pane

* handle import of dropped bib files
works only if table is not empty, otherwise it will be just opened
Call timestamp update method
fix merge erros

* add drag and drop copy handler
add debug output on gesture target

* fix event propagation

* fix checkstyle

* literals first in comparison

* add l10n for error message

* remove old swing related dnd stuff
Use local dragboard for transfering entries
fix checkstyle
expand group node on drag over

* fix merge error

* fix NPE discovered on linux when row.getItem is null

* Put Dragboard Instance into Gui Globals
remove old TransferableBibtexEntry

* checkstyle

* fix checkstyle

* fix l10n

* fix copying on linux
fix moving if not pdf

* remove old drag and drop popup classes
remove some println

* fix import order

* extract part to logic

* extract files adding and content importer to own class

* some cleanups
reworked debug logging
pass customlocaldragboard as parameter to groups

* Add fileUtil method for checking if it's a bib file
move from logic to gui because of the externalFileType stuff
add property to speedup rendering pdf content
move and rename

* fix l10n

* cleanup

* add methods for putting and getting bib entries of localdragboard
clear clipboard on put
fix drag and drop to groups by adding clipboard stuff

* add javadoc

* Fix build
  • Loading branch information
Siedlerchr authored and tobiasdiez committed Aug 19, 2018
1 parent 6e27922 commit 1f14795
Show file tree
Hide file tree
Showing 47 changed files with 957 additions and 1,268 deletions.
38 changes: 17 additions & 21 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.jabref.gui;

import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.Transferable;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
Expand Down Expand Up @@ -134,7 +131,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BasePanel extends StackPane implements ClipboardOwner {
public class BasePanel extends StackPane {

private static final Logger LOGGER = LoggerFactory.getLogger(BasePanel.class);

private final BibDatabaseContext bibDatabaseContext;
Expand Down Expand Up @@ -227,8 +225,10 @@ public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabas

this.entryEditor = new EntryEditor(this, preferences.getEntryEditorPreferences(), Globals.getFileUpdateMonitor(), dialogService);

this.preview = new PreviewPanel(this, getBibDatabaseContext(), preferences.getKeyBindings(), preferences.getPreviewPreferences(), dialogService);
this.preview = new PreviewPanel(this, getBibDatabaseContext(), preferences.getKeyBindings(), preferences.getPreviewPreferences(), dialogService, externalFileTypes);
frame().getGlobalSearchBar().getSearchQueryHighlightObservable().addSearchListener(preview);


}

@Subscribe
Expand Down Expand Up @@ -680,15 +680,16 @@ public void runCommand(final Actions command) {
*/
private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding,
SavePreferences.DatabaseSaveType saveType)
throws SaveException {
throws SaveException {
SaveSession session;
final String SAVE_DATABASE = Localization.lang("Save library");
try {
SavePreferences prefs = Globals.prefs.loadForSaveFromPreferences()
.withEncoding(encoding)
.withSaveType(saveType);
.withEncoding(encoding)
.withSaveType(saveType);

BibtexDatabaseWriter<SaveSession> databaseWriter = new BibtexDatabaseWriter<>(
FileSaveSession::new);
FileSaveSession::new);
if (selectedOnly) {
session = databaseWriter.savePartOfDatabase(bibDatabaseContext, mainTable.getSelectedEntries(), prefs);
} else {
Expand All @@ -700,7 +701,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding,
// FIXME: not sure if this is really thrown anywhere
catch (UnsupportedCharsetException ex) {
frame.getDialogService().showErrorDialogAndWait(Localization.lang("Save library"), Localization.lang("Could not save file.")
+ Localization.lang("Character encoding '%0' is not supported.", encoding.displayName()));
+ Localization.lang("Character encoding '%0' is not supported.", encoding.displayName()));
throw new SaveException("rt");
} catch (SaveException ex) {
if (ex.specificEntry()) {
Expand Down Expand Up @@ -1145,7 +1146,7 @@ public void entryEditorClosing(EntryEditor editor) {
*/
public void ensureNotShowingBottomPanel(BibEntry entry) {
if (((mode == BasePanelMode.SHOWING_EDITOR) && (entryEditor.getEntry() == entry))
|| ((mode == BasePanelMode.SHOWING_PREVIEW) && (preview.getEntry() == entry))) {
|| ((mode == BasePanelMode.SHOWING_PREVIEW) && (preview.getEntry() == entry))) {
closeBottomPane();
}
}
Expand Down Expand Up @@ -1312,11 +1313,6 @@ private void saveDividerLocation(Number position) {
}
}

// Method pertaining to the ClipboardOwner interface.
@Override
public void lostOwnership(Clipboard clipboard, Transferable contents) {
// Nothing
}

/**
* Perform necessary cleanup when this BasePanel is closed.
Expand Down Expand Up @@ -1500,7 +1496,7 @@ public void listen(EntryAddedEvent addedEntryEvent) {
if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP)) {
final List<BibEntry> entries = Collections.singletonList(addedEntryEvent.getBibEntry());
Globals.stateManager.getSelectedGroup(bibDatabaseContext).forEach(
selectedGroup -> selectedGroup.addEntriesToGroup(entries));
selectedGroup -> selectedGroup.addEntriesToGroup(entries));
}
}
}
Expand Down Expand Up @@ -1600,10 +1596,10 @@ public void action() {
List<LinkedFile> files = bes.get(0).getFiles();

Optional<LinkedFile> linkedFile = files.stream()
.filter(file -> (FieldName.URL.equalsIgnoreCase(file.getFileType())
|| FieldName.PS.equalsIgnoreCase(file.getFileType())
|| FieldName.PDF.equalsIgnoreCase(file.getFileType())))
.findFirst();
.filter(file -> (FieldName.URL.equalsIgnoreCase(file.getFileType())
|| FieldName.PS.equalsIgnoreCase(file.getFileType())
|| FieldName.PDF.equalsIgnoreCase(file.getFileType())))
.findFirst();

if (linkedFile.isPresent()) {

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/jabref/gui/DragAndDropDataFormats.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.jabref.gui;

import java.util.List;

import javafx.scene.input.DataFormat;

import org.jabref.model.entry.BibEntry;

/**
* Contains all the different {@link DataFormat}s that may occur in JabRef.
*/
Expand All @@ -10,4 +14,6 @@ public class DragAndDropDataFormats {
public static final DataFormat GROUP = new DataFormat("dnd/org.jabref.model.groups.GroupTreeNode");
public static final DataFormat LINKED_FILE = new DataFormat("dnd/org.jabref.model.entry.LinkedFile");
public static final DataFormat ENTRIES = new DataFormat("dnd/org.jabref.model.entry.BibEntries");
@SuppressWarnings("unchecked") public static final Class<List<BibEntry>> BIBENTRY_LIST_CLASS = (Class<List<BibEntry>>) (Class<?>) List.class;

}
160 changes: 0 additions & 160 deletions src/main/java/org/jabref/gui/DragDropPane.java

This file was deleted.

31 changes: 0 additions & 31 deletions src/main/java/org/jabref/gui/DragDropPopupPane.java

This file was deleted.

7 changes: 5 additions & 2 deletions src/main/java/org/jabref/gui/GUIGlobals.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.jabref.Globals;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.keyboard.EmacsKeyBindings;
import org.jabref.gui.util.CustomLocalDragboard;
import org.jabref.logic.l10n.Localization;
import org.jabref.preferences.JabRefPreferences;

Expand All @@ -16,12 +17,15 @@
* Static variables for graphics files and keyboard shortcuts.
*/
public class GUIGlobals {

public static Color editorTextColor;
public static Color validFieldBackgroundColor;
public static Color activeBackgroundColor;
public static Color invalidFieldBackgroundColor;
public static Font currentFont;

public static CustomLocalDragboard localDragboard = new CustomLocalDragboard();

public static final int WIDTH_ICON_COL = 16 + 12; // add some additional space to improve appearance

public static final int WIDTH_ICON_COL_RANKING = 5 * 16; // Width of Ranking Icon Column
Expand Down Expand Up @@ -58,13 +62,12 @@ public static void init() {

IconTheme.loadFonts();
GUIGlobals.currentFont = new Font(Globals.prefs.get(JabRefPreferences.FONT_FAMILY),
Globals.prefs.getInt(JabRefPreferences.FONT_STYLE), Globals.prefs.getInt(JabRefPreferences.FONT_SIZE));
Globals.prefs.getInt(JabRefPreferences.FONT_STYLE), Globals.prefs.getInt(JabRefPreferences.FONT_SIZE));
}

public static void setFont(int size) {
currentFont = new Font(currentFont.getFamily(), currentFont.getStyle(), size);
// update preferences
Globals.prefs.putInt(JabRefPreferences.FONT_SIZE, size);
}

}
Loading

0 comments on commit 1f14795

Please sign in to comment.