Skip to content

Commit 8c4b6fb

Browse files
committed
Enable PdfCommentImporter to import multiple files
1 parent 66171be commit 8c4b6fb

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/main/java/net/sf/jabref/gui/entryeditor/PdfCommentsTab.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.awt.BorderLayout;
44
import java.awt.Dimension;
5+
import java.io.IOException;
6+
import java.util.ArrayList;
57
import java.util.HashMap;
68
import java.util.Optional;
79

@@ -15,6 +17,7 @@
1517
import net.sf.jabref.gui.BasePanel;
1618
import net.sf.jabref.gui.JabRefFrame;
1719
import net.sf.jabref.logic.pdf.PdfCommentImporter;
20+
import net.sf.jabref.model.entry.BibEntry;
1821
import net.sf.jabref.model.entry.FieldName;
1922

2023
public class PdfCommentsTab extends JPanel {
@@ -43,6 +46,8 @@ public class PdfCommentsTab extends JPanel {
4346

4447
private JScrollPane siteScrollPane = new JScrollPane(siteArea);
4548

49+
DefaultListModel<String> listModel;
50+
4651
private final EntryEditor parent;
4752

4853
private final String tabTitle;
@@ -57,18 +62,27 @@ public PdfCommentsTab(EntryEditor parent, JabRefFrame frame, BasePanel basePanel
5762
this.basePanel = basePanel;
5863
this.tabTitle = "PDF comments";
5964
this.setUpInformationPanel();
60-
this.setUpPdfCommentsTab();
65+
listModel = new DefaultListModel<>();
66+
try {
67+
this.setUpPdfCommentsTab();
68+
} catch (IOException e) {
69+
e.printStackTrace();
70+
}
6171
}
6272

63-
private void setUpPdfCommentsTab() {
73+
private void setUpPdfCommentsTab() throws IOException {
6474
Optional<String> field = parent.getEntry().getField(FieldName.FILE);
6575
if (field.isPresent()) {
66-
DefaultListModel<String> listModel = new DefaultListModel<>();
76+
6777
commentList.setModel(listModel);
6878
PdfCommentImporter commentImporter = new PdfCommentImporter();
69-
String pdfPath = field.get().replaceFirst(".*?:", System.getProperty("file.separator")).replaceAll(":PDF", "");
70-
HashMap<String, String> importedNotes = commentImporter.importNotes(pdfPath);
71-
importedNotes.values().stream().forEach((note) -> listModel.addElement(note));
79+
ArrayList<BibEntry> entries = new ArrayList<>();
80+
entries.add(parent.getEntry());
81+
commentImporter.importPdfFile(entries, basePanel.getBibDatabaseContext());
82+
83+
HashMap<String, String> importedNotes = commentImporter.importNotes(commentImporter.importPdfFile(entries,
84+
basePanel.getBibDatabaseContext()).get(0));
85+
updateShownComments(importedNotes);
7286
}
7387

7488
commentScrollPane.setPreferredSize(new Dimension(450,200));
@@ -77,6 +91,10 @@ private void setUpPdfCommentsTab() {
7791
this.add(informationPanel,BorderLayout.WEST);
7892
}
7993

94+
private void updateShownComments(HashMap<String, String> importedNotes){
95+
importedNotes.values().stream().forEach((note) -> listModel.addElement(note));
96+
}
97+
8098

8199
private void setUpInformationPanel(){
82100
authorArea.setEditable(false);

src/main/java/net/sf/jabref/logic/pdf/PdfCommentImporter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public HashMap<String, String> importNotes(final PDDocument document) {
4444
try {
4545
for (PDAnnotation annotation : page.getAnnotations()) {
4646
annotationsMap.put(annotation.getAnnotationName(), annotation.getContents());
47+
annotation.get
4748
}
4849
} catch (IOException e1) {
4950
e1.printStackTrace();
@@ -52,7 +53,7 @@ public HashMap<String, String> importNotes(final PDDocument document) {
5253
return annotationsMap;
5354
}
5455

55-
private List<PDDocument> importPdfFile(final List<BibEntry> entryList, final BibDatabaseContext bibDatabaseContext) throws IOException {
56+
public List<PDDocument> importPdfFile(final List<BibEntry> entryList, final BibDatabaseContext bibDatabaseContext) throws IOException {
5657

5758
final List<File> files = FileUtil.getListOfLinkedFiles(entryList,
5859
bibDatabaseContext.getFileDirectory(Globals.prefs.getFileDirectoryPreferences()));

0 commit comments

Comments
 (0)