Example #1
0
  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..."));
  }
Example #2
0
  @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);
  }