Example #1
0
  public void run() {
    // net.sf.jabref.journals.JournalList.downloadJournalList(frame);

    BibtexEntry[] entries = panel.getSelectedEntries();
    if (entries == null) return;
    NamedCompound ce = new NamedCompound("Abbreviate journal names");
    int count = 0;
    for (BibtexEntry entry : entries) {
      if (Globals.journalAbbrev.abbreviate(panel.database(), entry, "journal", ce, iso)) count++;
      if (Globals.journalAbbrev.abbreviate(panel.database(), entry, "journaltitle", ce, iso))
        count++;
    }
    if (count > 0) {
      ce.end();
      panel.undoManager.addEdit(ce);
      panel.markBaseChanged();
      message = Globals.lang("Abbreviated %0 journal names.", String.valueOf(count));
    } else {
      message = Globals.lang("No journal names could be abbreviated.");
    }
  }
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);
  }