/** * If the user has signalled the opening of a context menu, the event gets redirected to this * method. Here we open a file link menu if the user is pointing at a file link icon. Otherwise * a general context menu should be shown. * * @param e The triggering mouse event. */ public void processPopupTrigger(MouseEvent e) { BibtexEntry entry = sortedEntries.get(entryTable.rowAtPoint(e.getPoint())); BasePanel p = entryHome.get(entry); int col = entryTable.columnAtPoint(e.getPoint()); JPopupMenu menu = new JPopupMenu(); int count = 0; if (col == FILE_COL) { // We use a FileListTableModel to parse the field content: Object o = entry.getField(GUIGlobals.FILE_FIELD); FileListTableModel fileList = new FileListTableModel(); fileList.setContent((String) o); // If there are one or more links, open the first one: for (int i = 0; i < fileList.getRowCount(); i++) { FileListEntry flEntry = fileList.getEntry(i); String description = flEntry.getDescription(); if ((description == null) || (description.trim().length() == 0)) description = flEntry.getLink(); menu.add( new ExternalFileMenuItem( p.frame(), entry, description, flEntry.getLink(), flEntry.getType().getIcon(), p.metaData(), flEntry.getType())); count++; } } if (count > 0) menu.show(entryTable, e.getX(), e.getY()); }
/** * This method performs the actual changes. * * @param panel * @param pr * @param fileDir The path to the file directory to set, or null if it should not be set. */ private void makeChanges( BasePanel panel, ParserResult pr, boolean upgradePrefs, boolean upgradeDatabase, String fileDir) { if (upgradeDatabase) { // Update file links links in the database: NamedCompound ce = Util.upgradePdfPsToFile(pr.getDatabase(), FileLinksUpgradeWarning.FIELDS_TO_LOOK_FOR); panel.undoManager.addEdit(ce); panel.markBaseChanged(); } if (fileDir != null) { Globals.prefs.put(GUIGlobals.FILE_FIELD + "Directory", fileDir); } if (upgradePrefs) { // Exchange table columns: Globals.prefs.putBoolean(JabRefPreferences.PDF_COLUMN, Boolean.FALSE); Globals.prefs.putBoolean(JabRefPreferences.FILE_COLUMN, Boolean.TRUE); // Modify General fields if necessary: // If we don't find the file field, insert it at the bottom of the first tab: if (!showsFileInGenFields()) { String gfs = Globals.prefs.get(JabRefPreferences.CUSTOM_TAB_FIELDS + "0"); // System.out.println(gfs); StringBuilder sb = new StringBuilder(gfs); if (gfs.length() > 0) { sb.append(";"); } sb.append(GUIGlobals.FILE_FIELD); Globals.prefs.put(JabRefPreferences.CUSTOM_TAB_FIELDS + "0", sb.toString()); Globals.prefs.updateEntryEditorTabList(); panel.frame().removeCachedEntryEditors(); } panel.frame().setupAllTables(); } }
public void init() { // Get entries and check if it makes sense to perform this operation entries = panel.getSelectedEntries(); if (entries.length == 0) { database = panel.getDatabase(); entries = database.getEntries().toArray(new BibtexEntry[] {}); if (entries.length == 0) { JOptionPane.showMessageDialog( panel, Globals.lang("This operation requires at least one entry."), Globals.lang("Write XMP-metadata"), JOptionPane.ERROR_MESSAGE); goOn = false; return; } else { int response = JOptionPane.showConfirmDialog( panel, Globals.lang("Write XMP-metadata for all PDFs in current database?"), Globals.lang("Write XMP-metadata"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (response != JOptionPane.YES_OPTION) { goOn = false; return; } } } errors = entriesChanged = skipped = 0; if (optDiag == null) { optDiag = new OptionsDialog(panel.frame().getFrame()); } optDiag.open(); panel.output(Globals.lang("Writing XMP metadata...")); }
public CleanUpAction(BasePanel panel) { this.panel = panel; this.frame = panel.frame(); initOptionsPanel(); }
/** * This method presents a dialog box explaining and offering to make the changes. If the user * confirms, the changes are performed. * * @param panel * @param pr */ @Override public void performAction(BasePanel panel, ParserResult pr) { // Find out which actions should be offered: // Only offer to change Preferences if file column is not already visible: boolean offerChangeSettings = !Globals.prefs.getBoolean(JabRefPreferences.FILE_COLUMN) || !showsFileInGenFields(); // Only offer to upgrade links if the pdf/ps fields are used: boolean offerChangeDatabase = linksFound(pr.getDatabase(), FileLinksUpgradeWarning.FIELDS_TO_LOOK_FOR); // If the "file" directory is not set, offer to migrate pdf/ps dir: boolean offerSetFileDir = !Globals.prefs.hasKey(GUIGlobals.FILE_FIELD + "Directory") && (Globals.prefs.hasKey("pdfDirectory") || Globals.prefs.hasKey("psDirectory")); if (!offerChangeDatabase && !offerChangeSettings && !offerSetFileDir) { return; // Nothing to do, just return. } JCheckBox changeSettings = new JCheckBox( Globals.lang("Change table column and General fields settings to use the new feature"), offerChangeSettings); JCheckBox changeDatabase = new JCheckBox( Globals.lang("Upgrade old external file links to use the new feature"), offerChangeDatabase); JCheckBox setFileDir = new JCheckBox(Globals.lang("Set main external file directory") + ":", offerSetFileDir); JTextField fileDir = new JTextField(30); JCheckBox doNotShowDialog = new JCheckBox(Globals.lang("Do not show these options in the future"), false); JPanel message = new JPanel(); DefaultFormBuilder b = new DefaultFormBuilder(new FormLayout("left:pref", ""), message); // Keep the formatting of these lines. Otherwise, strings have to be translated again. // See updated JabRef_en.properties modifications by python syncLang.py -s -u b.append( new JLabel( "<html>" + Globals.lang("This database was written using an older version of JabRef.") + "<br>" + Globals.lang( "The current version features a new way of handling links to external files.<br>To take advantage of this, your links must be changed into the new format, and<br>JabRef must be configured to show the new links.") + "<p>" + Globals.lang("Do you want JabRef to do the following operations?") + "</html>")); b.nextLine(); if (offerChangeSettings) { b.append(changeSettings); b.nextLine(); } if (offerChangeDatabase) { b.append(changeDatabase); b.nextLine(); } if (offerSetFileDir) { if (Globals.prefs.hasKey("pdfDirectory")) { fileDir.setText(Globals.prefs.get("pdfDirectory")); } else { fileDir.setText(Globals.prefs.get("psDirectory")); } JPanel pan = new JPanel(); pan.add(setFileDir); pan.add(fileDir); JButton browse = new JButton(Globals.lang("Browse")); browse.addActionListener(BrowseAction.buildForDir(fileDir)); pan.add(browse); b.append(pan); b.nextLine(); } b.append(""); b.nextLine(); b.append(doNotShowDialog); int answer = JOptionPane.showConfirmDialog( panel.frame(), message, Globals.lang("Upgrade file"), JOptionPane.YES_NO_OPTION); if (doNotShowDialog.isSelected()) { Globals.prefs.putBoolean(JabRefPreferences.SHOW_FILE_LINKS_UPGRADE_WARNING, false); } if (answer == JOptionPane.YES_OPTION) { makeChanges( panel, pr, changeSettings.isSelected(), changeDatabase.isSelected(), setFileDir.isSelected() ? fileDir.getText() : null); } }
@Override public void actionPerformed(ActionEvent evt) { final BibtexEntry[] entries = m_panel.getSelectedEntries(); final Vector<GroupTreeNode> removeGroupsNodes = new Vector<GroupTreeNode>(); // used only when moving if (m_move) { // collect warnings for removal Enumeration<GroupTreeNode> e = ((GroupTreeNode) m_node.getRoot()).preorderEnumeration(); GroupTreeNode node; while (e.hasMoreElements()) { node = e.nextElement(); if (!node.getGroup().supportsRemove()) { continue; } for (BibtexEntry entry : entries) { if (node.getGroup().contains(entry)) { removeGroupsNodes.add(node); } } } // warning for all groups from which the entries are removed, and // for the one to which they are added! hence the magical +1 AbstractGroup[] groups = new AbstractGroup[removeGroupsNodes.size() + 1]; for (int i = 0; i < removeGroupsNodes.size(); ++i) { groups[i] = removeGroupsNodes.elementAt(i).getGroup(); } groups[groups.length - 1] = m_node.getGroup(); if (!Util.warnAssignmentSideEffects( groups, entries, m_panel.getDatabase(), m_panel.frame())) { return; // user aborted operation } } else { // warn if assignment has undesired side effects (modifies a field != keywords) if (!Util.warnAssignmentSideEffects( new AbstractGroup[] {m_node.getGroup()}, entries, m_panel.getDatabase(), m_panel.frame())) { return; // user aborted operation } } // if an editor is showing, its fields must be updated // after the assignment, and before that, the current // edit has to be stored: m_panel.storeCurrentEdit(); NamedCompound undoAll = new NamedCompound(Globals.lang("change assignment of entries")); if (m_move) { // first remove for (int i = 0; i < removeGroupsNodes.size(); ++i) { GroupTreeNode node = removeGroupsNodes.elementAt(i); if (node.getGroup().containsAny(entries)) { undoAll.addEdit(node.removeFromGroup(entries)); } } // then add AbstractUndoableEdit undoAdd = m_node.addToGroup(entries); if (undoAdd != null) { undoAll.addEdit(undoAdd); } } else { AbstractUndoableEdit undoAdd = m_node.addToGroup(entries); if (undoAdd == null) { return; // no changed made } undoAll.addEdit(undoAdd); } undoAll.end(); m_panel.undoManager.addEdit(undoAll); m_panel.markBaseChanged(); m_panel.updateEntryEditorIfShowing(); m_panel.getGroupSelector().valueChanged(null); }
public void update() { // pdfURL = new URL("http://geog-www.sbs.ohio-state.edu/faculty/bmark/abbott_etal_ppp03.pdf"); if (result.url != null) { // System.out.println("PDF URL: "+result.url); String bibtexKey = entry.getCiteKey(); String fileDir = basePanel.metaData().getFileDirectory(GUIGlobals.FILE_FIELD); if (fileDir == null) { // TODO: error message if file dir not defined // JOptionPane.showMessageDialog(frame, Globals.lang); return; } DownloadExternalFile def = new DownloadExternalFile(basePanel.frame(), basePanel.metaData(), bibtexKey); try { def.download( result.url, new DownloadExternalFile.DownloadCallback() { public void downloadComplete(FileListEntry file) { System.out.println("finished"); FileListTableModel tm = new FileListTableModel(); String oldValue = entry.getField(GUIGlobals.FILE_FIELD); tm.setContent(oldValue); tm.addEntry(tm.getRowCount(), file); String newValue = tm.getStringRepresentation(); UndoableFieldChange edit = new UndoableFieldChange(entry, GUIGlobals.FILE_FIELD, oldValue, newValue); entry.setField(GUIGlobals.FILE_FIELD, newValue); basePanel.undoManager.addEdit(edit); basePanel.markBaseChanged(); } }); } catch (IOException e) { e.printStackTrace(); } basePanel.output(Globals.lang("Finished downloading full text document")); } else { String message = null; switch (result.status) { case FindFullText.UNKNOWN_DOMAIN: message = Globals.lang( "Unable to find full text article. No search algorithm " + "defined for the '%0' web site.", result.host); break; case FindFullText.WRONG_MIME_TYPE: message = Globals.lang( "Found pdf link, but received the wrong MIME type. " + "This could indicate that you don't have access to the fulltext article."); break; case FindFullText.LINK_NOT_FOUND: message = Globals.lang("Unable to find full text document in the linked web page."); break; case FindFullText.IO_EXCEPTION: message = Globals.lang("Connection error when trying to find full text document."); break; case FindFullText.NO_URLS_DEFINED: message = Globals.lang("This entry provides no URL or DOI links."); break; } basePanel.output(Globals.lang("Full text article download failed")); JOptionPane.showMessageDialog( basePanel.frame(), message, Globals.lang("Full text article download failed"), JOptionPane.ERROR_MESSAGE); } }