コード例 #1
0
  /**
   * 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();
    }
  }
コード例 #2
0
ファイル: WriteXMPAction.java プロジェクト: GeorgLink/Desktop
  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..."));
  }
コード例 #3
0
  /**
   * 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);
    }
  }
コード例 #4
0
 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);
   }
 }