/** * Check the database to find out whether any of a set of fields are used for any of the entries. * * @param database The bib database. * @param fields The set of fields to look for. * @return true if at least one of the given fields is set in at least one entry, false otherwise. */ private boolean linksFound(BibtexDatabase database, String[] fields) { for (BibtexEntry entry : database.getEntries()) { for (String field : fields) { if (entry.getField(field) != null) { return true; } } } return false; }
public void setEntry(BibtexEntry entry) { try { updating = true; Iterator<FieldEditor> i = editors.values().iterator(); while (i.hasNext()) { FieldEditor editor = i.next(); Object content = entry.getField(editor.getFieldName()); String toSet = (content == null) ? "" : content.toString(); if (!toSet.equals(editor.getText())) editor.setText(toSet); } this.entry = entry; } finally { updating = false; } }
private void insertFields(String[] fields, BibtexEntry entry, XmlDocument xmlDocument) { DocumentWrapper document = new DocumentWrapper(xmlDocument); for (String field : fields) { if (entry.getField(field) != null) { continue; } if (field.equalsIgnoreCase("author")) { entry.setField(field, document.getAuthors("and")); } if (field.equalsIgnoreCase("title")) { entry.setField(field, document.getTitle()); } if (field.equalsIgnoreCase("abstract")) { entry.setField(field, document.getAbstract()); } if (field.equalsIgnoreCase("keywords")) { entry.setField(field, document.getKeyWords()); } if (field.equalsIgnoreCase("doi")) { entry.setField(field, document.getDoi()); } if (field.equalsIgnoreCase("pages")) { entry.setField(field, document.getPages()); } if (field.equalsIgnoreCase("volume")) { entry.setField(field, document.getVolume()); } if (field.equalsIgnoreCase("number")) { entry.setField(field, document.getNumber()); } if (field.equalsIgnoreCase("year")) { entry.setField(field, document.getYear()); } if (field.equalsIgnoreCase("month")) { entry.setField(field, document.getMonth()); } if (field.equalsIgnoreCase("day")) { entry.setField(field, document.getDay()); } if (field.equalsIgnoreCase("booktitle")) { entry.setField(field, document.getVenue()); } if (field.equalsIgnoreCase("journal")) { entry.setField(field, document.getVenue()); } } }
public void run() { if (!goOn) return; for (int i = 0; i < entries.length; i++) { BibtexEntry entry = entries[i]; // Make a list of all PDFs linked from this entry: List<File> files = new ArrayList<File>(); // First check the (legacy) "pdf" field: String pdf = entry.getField("pdf"); String dir = panel.metaData().getFileDirectory("pdf"); File f = Util.expandFilename(pdf, new String[] {dir, "."}); if (f != null) files.add(f); // Then check the "file" field: dir = panel.metaData().getFileDirectory(GUIGlobals.FILE_FIELD); String field = entry.getField(GUIGlobals.FILE_FIELD); if (field != null) { FileListTableModel tm = new FileListTableModel(); tm.setContent(field); for (int j = 0; j < tm.getRowCount(); j++) { FileListEntry flEntry = tm.getEntry(j); if ((flEntry.getType() != null) && (flEntry.getType().getName().toLowerCase().equals("pdf"))) { f = Util.expandFilename(flEntry.getLink(), new String[] {dir, "."}); if (f != null) files.add(f); } } } optDiag.progressArea.append(entry.getCiteKey() + "\n"); if (files.size() == 0) { skipped++; optDiag.progressArea.append(" " + Globals.lang("Skipped - No PDF linked") + ".\n"); } else for (File file : files) { if (!file.exists()) { skipped++; optDiag.progressArea.append( " " + Globals.lang("Skipped - PDF does not exist") + ":\n"); optDiag.progressArea.append(" " + file.getPath() + "\n"); } else { try { XMPUtil.writeXMP(file, entry, database); optDiag.progressArea.append(" " + Globals.lang("Ok") + ".\n"); entriesChanged++; } catch (Exception e) { optDiag.progressArea.append( " " + Globals.lang("Error while writing") + " '" + file.getPath() + "':\n"); optDiag.progressArea.append(" " + e.getLocalizedMessage() + "\n"); errors++; } } } if (optDiag.canceled) { optDiag.progressArea.append("\n" + Globals.lang("Operation canceled.\n")); break; } } optDiag.progressArea.append( "\n" + Globals.lang( "Finished writing XMP for %0 file (%1 skipped, %2 errors).", String.valueOf(entriesChanged), String.valueOf(skipped), String.valueOf(errors))); optDiag.done(); }
public RightClickMenu(BasePanel panel_, MetaData metaData_) { panel = panel_; metaData = metaData_; // Are multiple entries selected? boolean multiple = panel.mainTable.getSelectedRowCount() > 1; // If only one entry is selected, get a reference to it for adapting the menu. BibtexEntry be = null; if (panel.mainTable.getSelectedRowCount() == 1) { be = panel.mainTable.getSelected().get(0); } addPopupMenuListener(this); add( new AbstractAction(Globals.lang("Copy"), GUIGlobals.getImage("copy")) { @Override public void actionPerformed(ActionEvent e) { try { panel.runCommand("copy"); } catch (Throwable ex) { LOGGER.warn("Could not execute copy", ex); } } }); add( new AbstractAction(Globals.lang("Paste"), GUIGlobals.getImage("paste")) { @Override public void actionPerformed(ActionEvent e) { try { panel.runCommand("paste"); } catch (Throwable ex) { LOGGER.warn("Could not execute paste", ex); } } }); add( new AbstractAction(Globals.lang("Cut"), GUIGlobals.getImage("cut")) { @Override public void actionPerformed(ActionEvent e) { try { panel.runCommand("cut"); } catch (Throwable ex) { LOGGER.warn("Could not execute cut", ex); } } }); add( new AbstractAction(Globals.lang("Delete"), GUIGlobals.getImage("delete")) { @Override public void actionPerformed(ActionEvent e) { /*SwingUtilities.invokeLater(new Runnable () { public void run() {*/ try { panel.runCommand("delete"); } catch (Throwable ex) { LOGGER.warn("Could not execute delete", ex); } /*} }); */ } }); addSeparator(); add( new AbstractAction(Globals.lang("Export to clipboard")) { @Override public void actionPerformed(ActionEvent e) { try { panel.runCommand("exportToClipboard"); } catch (Throwable ex) { LOGGER.warn("Could not execute exportToClipboard", ex); } } }); add( new AbstractAction(Globals.lang("Send as email")) { @Override public void actionPerformed(ActionEvent e) { try { panel.runCommand("sendAsEmail"); } catch (Throwable ex) { LOGGER.warn("Could not execute sendAsEmail", ex); } } }); addSeparator(); JMenu markSpecific = JabRefFrame.subMenu("Mark specific color"); JabRefFrame frame = panel.frame; for (int i = 0; i < EntryMarker.MAX_MARKING_LEVEL; i++) { markSpecific.add(new MarkEntriesAction(frame, i).getMenuItem()); } if (multiple) { add( new AbstractAction(Globals.lang("Mark entries"), GUIGlobals.getImage("markEntries")) { @Override public void actionPerformed(ActionEvent e) { try { panel.runCommand("markEntries"); } catch (Throwable ex) { LOGGER.warn("Could not execute markEntries", ex); } } }); add(markSpecific); add( new AbstractAction(Globals.lang("Unmark entries"), GUIGlobals.getImage("unmarkEntries")) { @Override public void actionPerformed(ActionEvent e) { try { panel.runCommand("unmarkEntries"); } catch (Throwable ex) { LOGGER.warn("Could not execute unmarkEntries", ex); } } }); addSeparator(); } else if (be != null) { String marked = be.getField(BibtexFields.MARKED); // We have to check for "" too as the marked field may be empty if (marked == null || marked.isEmpty()) { add( new AbstractAction(Globals.lang("Mark entry"), GUIGlobals.getImage("markEntries")) { @Override public void actionPerformed(ActionEvent e) { try { panel.runCommand("markEntries"); } catch (Throwable ex) { LOGGER.warn("Could not execute markEntries", ex); } } }); add(markSpecific); } else { add(markSpecific); add( new AbstractAction(Globals.lang("Unmark entry"), GUIGlobals.getImage("unmarkEntries")) { @Override public void actionPerformed(ActionEvent e) { try { panel.runCommand("unmarkEntries"); } catch (Throwable ex) { LOGGER.warn("Could not execute unmarkEntries", ex); } } }); } addSeparator(); } if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SPECIALFIELDSENABLED)) { if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_RANKING)) { JMenu rankingMenu = new JMenu(); RightClickMenu.populateSpecialFieldMenu(rankingMenu, Rank.getInstance(), panel.frame); add(rankingMenu); } // TODO: multiple handling for relevance and quality-assurance // if multiple values are selected ("if (multiple)"), two options (set / clear) should be // offered // if one value is selected either set or clear should be offered if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_RELEVANCE)) { add(Relevance.getInstance().getValues().get(0).getMenuAction(panel.frame)); } if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_QUALITY)) { add(Quality.getInstance().getValues().get(0).getMenuAction(panel.frame)); } if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_PRINTED)) { add(Printed.getInstance().getValues().get(0).getMenuAction(panel.frame)); } if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_PRIORITY)) { JMenu priorityMenu = new JMenu(); RightClickMenu.populateSpecialFieldMenu(priorityMenu, Priority.getInstance(), panel.frame); add(priorityMenu); } if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_READ)) { JMenu readStatusMenu = new JMenu(); RightClickMenu.populateSpecialFieldMenu( readStatusMenu, ReadStatus.getInstance(), panel.frame); add(readStatusMenu); } addSeparator(); } add( new AbstractAction(Globals.lang("Open folder"), GUIGlobals.getImage("openFolder")) { @Override public void actionPerformed(ActionEvent e) { try { panel.runCommand("openFolder"); } catch (Throwable ex) { LOGGER.warn("Could not open folder", ex); } } }); add( new AbstractAction(Globals.lang("Open file"), GUIGlobals.getImage("openExternalFile")) { @Override public void actionPerformed(ActionEvent e) { try { panel.runCommand("openExternalFile"); } catch (Throwable ex) { LOGGER.warn("Could not open external file", ex); } } }); add( new AbstractAction(Globals.lang("Attach file"), GUIGlobals.getImage("open")) { @Override public void actionPerformed(ActionEvent e) { try { panel.runCommand("addFileLink"); } catch (Throwable ex) { LOGGER.warn("Could not attach file", ex); } } }); /*add(new AbstractAction(Globals.lang("Open PDF or PS"), GUIGlobals.getImage("openFile")) { public void actionPerformed(ActionEvent e) { try { panel.runCommand("openFile"); } catch (Throwable ex) {} } });*/ add( new AbstractAction(Globals.lang("Open URL or DOI"), GUIGlobals.getImage("www")) { @Override public void actionPerformed(ActionEvent e) { try { panel.runCommand("openUrl"); } catch (Throwable ex) { LOGGER.warn("Could not execute open URL", ex); } } }); add( new AbstractAction(Globals.lang("Copy BibTeX key")) { @Override public void actionPerformed(ActionEvent e) { try { panel.runCommand("copyKey"); } catch (Throwable ex) { LOGGER.warn("Could not copy BibTex key", ex); } } }); add( new AbstractAction(Globals.lang("Copy") + " \\cite{" + Globals.lang("BibTeX key") + '}') { @Override public void actionPerformed(ActionEvent e) { try { panel.runCommand("copyCiteKey"); } catch (Throwable ex) { LOGGER.warn("Could not copy cite key", ex); } } }); addSeparator(); populateTypeMenu(); add(typeMenu); add( new AbstractAction(Globals.lang("Plain text import")) { @Override public void actionPerformed(ActionEvent e) { try { panel.runCommand("importPlainText"); } catch (Throwable ex) { LOGGER.debug("Could not import plain text", ex); } } }); add(JabRef.jrf.massSetField); add(JabRef.jrf.manageKeywords); addSeparator(); // for "add/move/remove to/from group" entries (appended here) groupAdd = new JMenuItem( new AbstractAction(Globals.lang("Add to group")) { @Override public void actionPerformed(ActionEvent e) { try { panel.runCommand("addToGroup"); // BibtexEntry[] bes = panel.getSelectedEntries(); // JMenu groupMenu = buildGroupMenu(bes, true, false); } catch (Throwable ex) { LOGGER.debug("Could not add to group", ex); } } }); add(groupAdd); groupRemove = new JMenuItem( new AbstractAction(Globals.lang("Remove from group")) { @Override public void actionPerformed(ActionEvent e) { try { panel.runCommand("removeFromGroup"); } catch (Throwable ex) { LOGGER.debug("Could not remove from group", ex); } } }); add(groupRemove); JMenuItem groupMoveTo = add( new AbstractAction(Globals.lang("Move to group")) { @Override public void actionPerformed(ActionEvent e) { try { panel.runCommand("moveToGroup"); } catch (Throwable ex) { LOGGER.debug("Could not execute move to group", ex); } } }); add(groupMoveTo); floatMarked.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Globals.prefs.putBoolean( JabRefPreferences.FLOAT_MARKED_ENTRIES, floatMarked.isSelected()); panel.mainTable.refreshSorting(); // Bad remote access } }); }