Пример #1
0
  @Override
  public void actionPerformed(ActionEvent e) {
    BasePanel bp = frame.basePanel();
    if (bp == null) {
      return;
    }
    BibtexEntry[] entries = bp.getSelectedEntries();
    // Lazy creation of the dialog:
    if (diag == null) {
      createDialog();
    }
    cancelled = true;
    prepareDialog(entries.length > 0);
    Util.placeDialog(diag, frame);
    diag.setVisible(true);
    if (cancelled) {
      return;
    }

    Collection<BibtexEntry> entryList;
    // If all entries should be treated, change the entries array:
    if (all.isSelected()) {
      entryList = bp.database().getEntries();
    } else {
      entryList = Arrays.asList(entries);
    }
    String toSet = text.getText();
    if (toSet.isEmpty()) {
      toSet = null;
    }
    String[] fields = getFieldNames(field.getText().trim().toLowerCase());
    NamedCompound ce = new NamedCompound(Globals.lang("Set field"));
    if (rename.isSelected()) {
      if (fields.length > 1) {
        // TODO: message: can only rename a single field
      } else {
        ce.addEdit(
            Util.massRenameField(entryList, fields[0], renameTo.getText(), overwrite.isSelected()));
      }
    } else {
      for (String field1 : fields) {
        ce.addEdit(
            Util.massSetField(
                entryList, field1, set.isSelected() ? toSet : null, overwrite.isSelected()));
      }
    }
    ce.end();
    bp.undoManager.addEdit(ce);
    bp.markBaseChanged();
  }
  /**
   * Cycle through all databases, and make sure everything is updated with the new type
   * customization. This includes making sure all entries have a valid type, that no obsolete entry
   * editors are around, and that the right-click menus' change type menu is up-to-date.
   */
  private void updateTypesForEntries(String typeName) {
    if (frame.getTabbedPane().getTabCount() == 0) {
      return;
    }
    for (int i = 0; i < frame.getTabbedPane().getTabCount(); i++) {
      BasePanel bp = (BasePanel) frame.getTabbedPane().getComponentAt(i);

      // Invalidate associated cached entry editor
      bp.entryEditors.remove(typeName);

      for (BibtexEntry entry : bp.database().getEntries()) {
        entry.updateType();
      }
    }
  }
Пример #3
0
  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;
  }
Пример #4
0
  private BibtexEntry createNewEntry() {

    // Find out what type is wanted.
    EntryTypeDialog etd = new EntryTypeDialog(frame);
    // We want to center the dialog, to make it look nicer.
    Util.placeDialog(etd, frame);
    etd.setVisible(true);
    BibtexEntryType type = etd.getChoice();

    if (type != null) { // Only if the dialog was not cancelled.
      String id = Util.createNeutralId();
      final BibtexEntry be = new BibtexEntry(id, type);
      try {
        panel.database().insertEntry(be);

        // Set owner/timestamp if options are enabled:
        ArrayList<BibtexEntry> list = new ArrayList<BibtexEntry>();
        list.add(be);
        Util.setAutomaticFields(list, true, true, false);

        // Create an UndoableInsertEntry object.
        panel.undoManager.addEdit(new UndoableInsertEntry(panel.database(), be, panel));
        panel.output(
            Globals.lang("Added new")
                + " '"
                + type.getName().toLowerCase()
                + "' "
                + Globals.lang("entry")
                + ".");

        // We are going to select the new entry. Before that, make sure that we are in
        // show-entry mode. If we aren't already in that mode, enter the WILL_SHOW_EDITOR
        // mode which makes sure the selection will trigger display of the entry editor
        // and adjustment of the splitter.
        if (panel.getMode() != panel.SHOWING_EDITOR) {
          panel.setMode(panel.WILL_SHOW_EDITOR);
        }

        /*int row = entryTable.findEntry(be);
        if (row >= 0)
            // Selects the entry. The selection listener will open the editor.
             if (row >= 0) {
                try{
                    entryTable.setRowSelectionInterval(row, row);
                }catch(IllegalArgumentException e){
                    System.out.println("RowCount: " + entryTable.getRowCount());
                }

                //entryTable.setActiveRow(row);
                entryTable.ensureVisible(row);
             }
        else {
            // The entry is not visible in the table, perhaps due to a filtering search
            // or group selection. Show the entry editor anyway:
            panel.showEntry(be);
        }   */
        panel.showEntry(be);
        panel.markBaseChanged(); // The database just changed.
        new FocusRequester(panel.getEntryEditor(be));
        return be;
      } catch (KeyCollisionException ex) {
        Util.pr(ex.getMessage());
      }
    }
    return null;
  }