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

Found entries will be shown when dropping a pdf with xmp meta data #2150

Merged
merged 2 commits into from
Oct 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Improve language quality of the German translation of shared database
- Change "Recent files" to "Recent databases" to keep the file menu consistent
- Customized importer files need to be slightly changed since the class `ImportFormat` was renamed to `Importer`
- [koppor#5](https://github.com/koppor/jabref/issues/5) When entries are found while dropping a pdf with xmp meta data the found entries will be displayed in the import dialog

### Fixed
- Fixed [#2092](https://github.com/JabRef/jabref/issues/2092): "None"-button in date picker clears the date field
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package net.sf.jabref.gui.externalfiles;

import java.awt.BorderLayout;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.List;
import java.util.Optional;

import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
Expand Down Expand Up @@ -239,8 +242,19 @@ private boolean tryXmpImport(String fileName, ExternalFileType fileType, NamedCo
Localization.lang("The PDF contains one or several BibTeX-records.")
+ "\n"
+ Localization.lang("Do you want to import these as new entries into the current database?"));

int reply = JOptionPane.showConfirmDialog(frame, confirmationMessage,
JPanel entriesPanel = new JPanel();
entriesPanel.setLayout(new BoxLayout(entriesPanel, BoxLayout.Y_AXIS));
xmpEntriesInFile.forEach(entry -> {
JTextArea entryArea = new JTextArea(entry.toString());
entryArea.setEditable(false);
entriesPanel.add(entryArea);
});

JPanel contentPanel = new JPanel(new BorderLayout());
contentPanel.add(confirmationMessage, BorderLayout.NORTH);
contentPanel.add(entriesPanel, BorderLayout.CENTER);

int reply = JOptionPane.showConfirmDialog(frame, contentPanel,
Localization.lang("XMP-metadata found in PDF: %0", fileName), JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);

Expand Down
30 changes: 30 additions & 0 deletions src/main/java/net/sf/jabref/pdfimport/ImportDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
Expand All @@ -19,11 +23,14 @@
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;
import javax.swing.WindowConstants;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.xmp.XMPUtil;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.strings.StringUtil;
import net.sf.jabref.preferences.JabRefPreferences;

Expand Down Expand Up @@ -80,6 +87,15 @@ public ImportDialog(boolean targetIsARow, String fileName) {
checkBoxDoNotShowAgain = new JCheckBox(Localization.lang("Do not show this box again for this import"));
useDefaultPDFImportStyle = new JCheckBox(Localization.lang("Always use this PDF import style (and do not ask for each import)"));
DefaultFormBuilder b = new DefaultFormBuilder(new FormLayout("left:pref, 5dlu, left:pref:grow", ""));
List<BibEntry> foundEntries = getEntriesFromXMP(fileName);
JPanel entriesPanel = new JPanel();
entriesPanel.setLayout(new BoxLayout(entriesPanel, BoxLayout.Y_AXIS));
foundEntries.forEach(entry -> {
JTextArea entryArea = new JTextArea(entry.toString());
entryArea.setEditable(false);
entriesPanel.add(entryArea);
});

b.appendSeparator(Localization.lang("Create new entry"));
b.append(radioButtonNoMeta, 3);
b.append(radioButtonXmp, 3);
Expand All @@ -89,6 +105,10 @@ public ImportDialog(boolean targetIsARow, String fileName) {
b.nextLine();
b.append(checkBoxDoNotShowAgain);
b.append(useDefaultPDFImportStyle);
if (!foundEntries.isEmpty()) {
b.appendSeparator(Localization.lang("XMP-metadata"));
b.append(entriesPanel, 3);
}
b.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
ButtonBarBuilder bb = new ButtonBarBuilder();
bb.addGlue();
Expand Down Expand Up @@ -155,6 +175,16 @@ public void windowClosing(WindowEvent e) {
this.setSize(555, 371);
}

private List<BibEntry> getEntriesFromXMP(String fileName) {
List<BibEntry> foundEntries = new ArrayList<>();
try {
foundEntries = XMPUtil.readXMP(fileName, Globals.prefs.getXMPPreferences());
} catch (IOException e) {
e.printStackTrace();
}
return foundEntries;
}

private void onOK() {
this.result = JOptionPane.OK_OPTION;
Globals.prefs.putInt(JabRefPreferences.IMPORT_DEFAULT_PDF_IMPORT_STYLE, this.getChoice());
Expand Down