コード例 #1
0
ファイル: PdfImporter.java プロジェクト: kifetew/SWAT
 private void createNewBlankEntry(String fileName) {
   BibtexEntry newEntry = createNewEntry();
   if (newEntry != null) {
     DroppedFileHandler dfh = new DroppedFileHandler(frame, panel);
     dfh.linkPdfToEntry(fileName, entryTable, newEntry);
   }
 }
コード例 #2
0
  /**
   * Take a set of filenames. Those with names indicating bib files are opened as such if possible.
   * All other files we will attempt to import into the current database.
   *
   * @param fileNames The names of the files to open.
   * @param dropRow success status for the operation
   */
  private void loadOrImportFiles(String[] fileNames, int dropRow) {

    OpenDatabaseAction openAction = new OpenDatabaseAction(frame, false);
    List<String> notBibFiles = new ArrayList<>();
    List<String> bibFiles = new ArrayList<>();
    for (String fileName : fileNames) {
      // Find the file's extension, if any:
      String extension = "";
      ExternalFileType fileType = null;
      int index = fileName.lastIndexOf('.');
      if ((index >= 0) && (index < fileName.length())) {
        extension = fileName.substring(index + 1).toLowerCase();
      }
      if ("bib".equals(extension)) {
        // we assume that it is a BibTeX file.
        // When a user wants to import something with file extension "bib", but which is not a
        // BibTeX file, he should use "file -> import"
        bibFiles.add(fileName);
        continue;
      }

      fileType = Globals.prefs.getExternalFileTypeByExt(extension);
      /*
       * This is a linkable file. If the user dropped it on an entry, we
       * should offer options for autolinking to this files:
       *
       * TODO we should offer an option to highlight the row the user is on too.
       */
      if ((fileType != null) && (dropRow >= 0)) {

        /*
         * TODO: need to signal if this is a local or autodownloaded
         * file
         */
        boolean local = true;

        /*
         * TODO: make this an instance variable?
         */
        DroppedFileHandler dfh = new DroppedFileHandler(frame, panel);
        dfh.handleDroppedfile(fileName, fileType, local, entryTable, dropRow);

        continue;
      }
      notBibFiles.add(fileName);
    }

    openAction.openFilesAsStringList(bibFiles, true);

    if (!notBibFiles.isEmpty()) {
      String[] toImport = new String[notBibFiles.size()];
      notBibFiles.toArray(toImport);

      // Import into new if entryTable==null, otherwise into current
      // database:
      ImportMenuItem importer = new ImportMenuItem(frame, entryTable == null);
      importer.automatedImport(toImport);
    }
  }
コード例 #3
0
ファイル: PdfImporter.java プロジェクト: kifetew/SWAT
  private boolean importPdfFiles(List<String> fileNames) {
    if (panel == null) return false;
    for (String fileName : fileNames) {
      List<BibtexEntry> xmpEntriesInFile = readXmpEntries(fileName);
      ImportDialog importDialog = new ImportDialog(dropRow, fileName);
      if (!hasXmpEntries(xmpEntriesInFile)) {
        importDialog.getRadioButtonXmp().setEnabled(false);
      }
      Tools.centerRelativeToWindow(importDialog, frame);
      importDialog.showDialog();
      if (importDialog.getResult() == JOptionPane.OK_OPTION) {
        if (importDialog.getRadioButtonXmp().isSelected()) {
          // SplDatabaseChangeListener dataListener = new SplDatabaseChangeListener(frame, panel,
          // entryTable, fileName);
          // panel.database().addDatabaseChangeListener(dataListener);
          ImportMenuItem importer = new ImportMenuItem(frame, (entryTable == null));
          importer.automatedImport(new String[] {fileName});

        } else if (importDialog.getRadioButtonMrDlib().isSelected()) {
          MetaDataListDialog metaDataListDialog = new MetaDataListDialog(fileName, true);
          Tools.centerRelativeToWindow(metaDataListDialog, frame);
          metaDataListDialog.showDialog();
          XmlDocuments documents = metaDataListDialog.getXmlDocuments();
          if (documents != null
              && documents.getDocuments() != null
              && documents.getDocuments().size() > 0
              && metaDataListDialog.getResult() == JOptionPane.OK_OPTION) {
            int selected = metaDataListDialog.getTableMetadata().getSelectedRow();
            if (selected > -1 && selected < documents.getDocuments().size()) {
              XmlDocument document = documents.getDocuments().get(selected);
              String id = Util.createNeutralId();
              BibtexEntry entry = new BibtexEntry(id);
              if (fieldExists(document.getType())) {
                BibtexEntryType type = BibtexEntryType.getStandardType(document.getType());
                if (type == null) {
                  type = BibtexEntryType.ARTICLE;
                }
                entry.setType(type);
              } else {
                entry.setType(BibtexEntryType.ARTICLE);
              }
              ArrayList<BibtexEntry> list = new ArrayList<BibtexEntry>();
              list.add(entry);
              Util.setAutomaticFields(list, true, true, false);
              insertFields(entry.getRequiredFields(), entry, document);
              insertFields(entry.getGeneralFields(), entry, document);
              insertFields(entry.getOptionalFields(), entry, document);
              panel.database().insertEntry(entry);
              DroppedFileHandler dfh = new DroppedFileHandler(frame, panel);
              dfh.linkPdfToEntry(fileName, entryTable, entry);
              LabelPatternUtil.makeLabel(Globals.prefs.getKeyPattern(), panel.database(), entry);
            } else {
              createNewBlankEntry(fileName);
            }
          } else if (metaDataListDialog.getResult() == JOptionPane.CANCEL_OPTION) {
            continue;
          } else if (metaDataListDialog.getResult() == JOptionPane.NO_OPTION) {
            createNewBlankEntry(fileName);
          } else if (documents == null
              || documents.getDocuments() == null
              || documents.getDocuments().size() <= 0
                  && metaDataListDialog.getResult() == JOptionPane.OK_OPTION) {
            createNewBlankEntry(fileName);
          }
        } else if (importDialog.getRadioButtonNoMeta().isSelected()) {
          createNewBlankEntry(fileName);
        } else if (importDialog.getRadioButtonUpdateEmptyFields().isSelected()) {
          MetaDataListDialog metaDataListDialog = new MetaDataListDialog(fileName, false);
          Tools.centerRelativeToWindow(metaDataListDialog, frame);
          metaDataListDialog.showDialog();
          XmlDocuments documents = metaDataListDialog.getXmlDocuments();
          if (documents != null
              && documents.getDocuments() != null
              && documents.getDocuments().size() > 0
              && metaDataListDialog.getResult() == JOptionPane.OK_OPTION) {
            int selected = metaDataListDialog.getTableMetadata().getSelectedRow();
            if (selected > -1 && selected < documents.getDocuments().size()) {
              XmlDocument document = documents.getDocuments().get(selected);
              BibtexEntry entry = entryTable.getEntryAt(dropRow);
              if (fieldExists(document.getType())) {
                BibtexEntryType type = BibtexEntryType.getStandardType(document.getType());
                if (type != null) {
                  entry.setType(type);
                }
              }
              insertFields(entry.getRequiredFields(), entry, document);
              insertFields(entry.getGeneralFields(), entry, document);
              insertFields(entry.getOptionalFields(), entry, document);

              DroppedFileHandler dfh = new DroppedFileHandler(frame, panel);
              dfh.linkPdfToEntry(fileName, entryTable, dropRow);
            }
          }
        } else if (importDialog.getRadioButtononlyAttachPDF().isSelected()) {
          DroppedFileHandler dfh = new DroppedFileHandler(frame, panel);
          dfh.linkPdfToEntry(fileName, entryTable, dropRow);
        }
      }
    }
    return true;
  }