Examples of NamedCompound


Examples of net.sf.jabref.undo.NamedCompound

  public AbstractUndoableEdit add(BibtexEntry[] entries) {
    if (!supportsAdd())
      return null;
    if ((entries != null) && (entries.length > 0)) {
      NamedCompound ce = new NamedCompound(Globals
          .lang("add entries to group"));
      boolean modified = false;
      for (int i = 0; i < entries.length; i++) {
        if (applyRule(null, entries[i]) == 0) {
          String oldContent = entries[i]
              .getField(m_searchField),
              pre = Globals.prefs.get("groupKeywordSeparator");
          String newContent = (oldContent == null ? "" : oldContent
              + pre)
              + m_searchExpression;
          entries[i].setField(m_searchField, newContent);

          // Store undo information.
          ce.addEdit(new UndoableFieldChange(entries[i],
              m_searchField, oldContent, newContent));
          modified = true;
        }
      }
      if (modified)
        ce.end();

      return modified ? ce : null;
    }

    return null;
View Full Code Here

Examples of net.sf.jabref.undo.NamedCompound

  public AbstractUndoableEdit remove(BibtexEntry[] entries) {
    if (!supportsRemove())
      return null;

    if ((entries != null) && (entries.length > 0)) {
      NamedCompound ce = new NamedCompound(Globals
          .lang("remove from group"));
      boolean modified = false;
      for (int i = 0; i < entries.length; ++i) {
        if (applyRule(null, entries[i]) > 0) {
          String oldContent = entries[i]
              .getField(m_searchField);
          removeMatches(entries[i]);
          // Store undo information.
          ce.addEdit(new UndoableFieldChange(entries[i],
              m_searchField, oldContent, entries[i]
                  .getField(m_searchField)));
          modified = true;
        }
      }
      if (modified)
        ce.end();

      return modified ? ce : null;
    }

    return null;
View Full Code Here

Examples of net.sf.jabref.undo.NamedCompound

                }
            }

            // The compund undo action used to contain all changes made by this
            // dialog.
            NamedCompound ce = new NamedCompound(undoName);

            // See if we should remove any old entries for duplicate resolving:
            if (entriesToDelete.size() > 0) {
                for (Iterator<BibtexEntry> i = entriesToDelete.iterator(); i.hasNext();) {
                    BibtexEntry entry = i.next();
                    ce.addEdit(new UndoableRemoveEntry(panel.database(), entry, panel));
                    panel.database().removeEntry(entry.getId());
                }
            }

            // If "Generate keys" is checked, generate keys unless it's already
            // been done:
            if (autoGenerate.isSelected() && !generatedKeys) {
                generateKeys(false);
            }
            // Remember the choice until next time:
            Globals.prefs.putBoolean("generateKeysAfterInspection", autoGenerate.isSelected());

            final List<BibtexEntry> selected = getSelectedEntries();

            if (selected.size() > 0) {

                if (newDatabase) {
                    // Create a new BasePanel for the entries:
                    BibtexDatabase base = new BibtexDatabase();
                    panel = new BasePanel(frame, base, null, new HashMap<String, String>(),
                        Globals.prefs.get("defaultEncoding"));
                }

                boolean groupingCanceled = false;

                // Set owner/timestamp if options are enabled:
                Util.setAutomaticFields(selected, Globals.prefs.getBoolean("overwriteOwner"),
                    Globals.prefs.getBoolean("overwriteTimeStamp"), Globals.prefs.getBoolean("markImportedEntries"));


                // Check if we should unmark entries before adding the new ones:
                if (Globals.prefs.getBoolean("unmarkAllEntriesBeforeImporting"))
                    for (BibtexEntry entry : panel.database().getEntries()) {
                        Util.unmarkEntry(entry, panel.database(), ce);
                    }

                for (Iterator<BibtexEntry> i = selected.iterator(); i.hasNext();) {
                    BibtexEntry entry = i.next();
                    // entry.clone();

                    // Remove settings to group/search hit status:
                    entry.setSearchHit(false);
                    entry.setGroupHit(false);

                    // If this entry should be added to any groups, do it now:
                    Set<GroupTreeNode> groups = groupAdditions.get(entry);
                    if (!groupingCanceled && (groups != null)) {
                        if (entry.getField(BibtexFields.KEY_FIELD) == null) {
                            // The entry has no key, so it can't be added to the
                            // group.
                            // The best course of ation is probably to ask the
                            // user if a key should be generated
                            // immediately.
                            int answer = JOptionPane
                                .showConfirmDialog(
                                    ImportInspectionDialog.this,
                                    Globals
                                        .lang("Cannot add entries to group without generating keys. Generate keys now?"),
                                    Globals.lang("Add to group"), JOptionPane.YES_NO_OPTION);
                            if (answer == JOptionPane.YES_OPTION) {
                                generateKeys(false);
                            } else
                                groupingCanceled = true;
                        }

                        // If the key was list, or has been list now, go ahead:
                        if (entry.getField(BibtexFields.KEY_FIELD) != null) {
                            for (Iterator<GroupTreeNode> i2 = groups.iterator(); i2.hasNext();) {
                                GroupTreeNode node = i2.next();
                                if (node.getGroup().supportsAdd()) {
                                    // Add the entry:
                                    AbstractUndoableEdit undo = node.getGroup().add(
                                        new BibtexEntry[] { entry });
                                    if (undo instanceof UndoableChangeAssignment)
                                        ((UndoableChangeAssignment) undo).setEditedNode(node);
                                    ce.addEdit(undo);

                                } else {
                                    // Shouldn't happen...
                                }
                            }
                        }
                    }

                    try {
                        entry.setId(Util.createNeutralId());
                        panel.database().insertEntry(entry);
                        // Let the autocompleters, if any, harvest words from
                        // the entry:
                        Util.updateCompletersForEntry(panel.getAutoCompleters(), entry);
                        ce.addEdit(new UndoableInsertEntry(panel.database(), entry, panel));
                    } catch (KeyCollisionException e) {
                        e.printStackTrace();
                    }
                }

                ce.end();
                panel.undoManager.addEdit(ce);
            }

            dispose();
            SwingUtilities.invokeLater(new Thread() {
View Full Code Here

Examples of net.sf.jabref.undo.NamedCompound

       
    }
   
    public void run() {
        HashSet<BibtexEntry> toRemove = new HashSet<BibtexEntry>();
        NamedCompound ce = new NamedCompound(Globals.lang("Remove duplicates"));
        panel.output(Globals.lang("Searching for duplicates..."));
        Object[] keys = panel.database.getKeySet().toArray();
        if ((keys == null) || (keys.length < 2))
            return;
        BibtexEntry[] bes = new BibtexEntry[keys.length];
        for (int i=0; i<keys.length; i++)
            bes[i] = panel.database.getEntryById((String)keys[i]);
       
        for (int i = 0; i<bes.length-1; i++) {
            for (int j = i + 1; j<bes.length; j++) {
                // We only check the entries if none of the two are already marked for removal.
                if (!toRemove.contains(bes[i]) && !toRemove.contains(bes[j]) &&
                    DuplicateCheck.compareEntriesStrictly(bes[i], bes[j]) > 1) {
                    // These two entries are exactly the same, so we can remove one.                   
                    if (!toRemove.contains(bes[i]) && !toRemove.contains(bes[j])) {
                        toRemove.add(bes[j]);
                    }
                }
            }
         }
   
        if (toRemove.size() == 0) {
            panel.output(Globals.lang("No duplicates found")+".");
            return;
        }
              
        // Finished searching. Now, remove all entries scheduled for removal:
        int answer = JOptionPane.showConfirmDialog(panel.frame(), Globals.lang("Duplicates found")+": "+
            toRemove.size()+". "+Globals.lang("Remove all?"), Globals.lang("Remove duplicates"),
            JOptionPane.OK_CANCEL_OPTION);
        if (answer == JOptionPane.CANCEL_OPTION)
            return;
       
        panel.output(Globals.lang("Duplicates removed")+": "+toRemove.size());
       
        for (Iterator<BibtexEntry> i=toRemove.iterator(); i.hasNext();) {
            BibtexEntry entry = i.next();
            panel.database.removeEntry(entry.getId());       
            ce.addEdit(new UndoableRemoveEntry(panel.database, entry, panel));
        }
    
        ce.end();
        panel.undoManager.addEdit(ce);
       
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {               
                panel.markBaseChanged();
View Full Code Here

Examples of net.sf.jabref.undo.NamedCompound


        BibtexEntry[] entries = panel.getSelectedEntries();
        if (entries == null)
            return;
        NamedCompound ce = new NamedCompound("Abbreviate journal names");
        int count = 0;
        for (int i = 0; i < entries.length; i++) {
            if (Globals.journalAbbrev.abbreviate(entries[i], "journal", 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.");
View Full Code Here

Examples of net.sf.jabref.undo.NamedCompound


        BibtexEntry[] entries = panel.getSelectedEntries();
        if (entries == null)
            return;
        NamedCompound ce = new NamedCompound("Unabbreviate journal names");
        int count = 0;
        for (int i = 0; i < entries.length; i++) {
            if (Globals.journalAbbrev.unabbreviate(entries[i], "journal", ce))
                count++;
        }
        if (count > 0) {
            ce.end();
            panel.undoManager.addEdit(ce);
            panel.markBaseChanged();
            message = Globals.lang("Unabbreviated %0 journal names.", String.valueOf(count));
        } else {
            message = Globals.lang("No journal names could be unabbreviated.");
View Full Code Here

Examples of net.sf.jabref.undo.NamedCompound

                            keyword, false, false, AbstractGroup.INDEPENDENT);
                    autoGroupsRoot.add(new GroupTreeNode(group));
                }

                m_groupsRoot.add(autoGroupsRoot);
                NamedCompound ce = new NamedCompound(Globals
                        .lang("Autogenerate groups"));
                UndoableAddOrRemoveGroup undo = new UndoableAddOrRemoveGroup(
                        gs, m_groupsRoot, autoGroupsRoot,
                        UndoableAddOrRemoveGroup.ADD_NODE);
                undo.setRevalidate(true);
                ce.addEdit(undo);

                panel.markBaseChanged(); // a change always occurs
                gs.revalidateGroups();
                frame.output(Globals.lang("Created groups."));
                ce.end();
                panel.undoManager.addEdit(ce);
            }
        };
        remove.addActionListener(okListener);
        field.addActionListener(okListener);
View Full Code Here

Examples of net.sf.jabref.undo.NamedCompound

        // 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);
View Full Code Here

Examples of net.sf.jabref.undo.NamedCompound

                throw new Exception("More than one entry found.");

            if (db.getEntryCount() < 1)
                throw new Exception("No entries found.");

            NamedCompound compound = new NamedCompound(Globals.lang("source edit"));
            BibtexEntry nu = db.getEntryById(db.getKeySet().iterator().next());
            String id = entry.getId();
            String
            // oldKey = entry.getCiteKey(),
            newKey = nu.getCiteKey();
            boolean anyChanged = false;
            boolean changedType = false;
            boolean duplicateWarning = false;
            boolean emptyWarning = newKey == null || newKey.equals("");

            if (panel.database.setCiteKeyForEntry(id, newKey)) {
                duplicateWarning = true;

                // First, remove fields that the user have removed.
            }

            for (String field : entry.getAllFields()){
                if (BibtexFields.isDisplayableField(field.toString())) {
                    if (nu.getField(field.toString()) == null) {
                        compound.addEdit(new UndoableFieldChange(entry, field.toString(), entry
                            .getField(field.toString()), null));
                        entry.clearField(field.toString());
                        anyChanged = true;
                    }
                }
            }

            // Then set all fields that have been set by the user.
            for (String field : nu.getAllFields()){
                if (entry.getField(field.toString()) != nu.getField(field.toString())) {
                    String toSet = nu.getField(field.toString());

                    // Test if the field is legally set.
                    (new LatexFieldFormatter()).format(toSet, field.toString());

                    compound.addEdit(new UndoableFieldChange(entry, field.toString(), entry
                        .getField(field.toString()), toSet));
                    entry.setField(field.toString(), toSet);
                    anyChanged = true;
                }
            }

            // See if the user has changed the entry type:
            if (nu.getType() != entry.getType()) {
                compound.addEdit(new UndoableChangeType(entry,
                      entry.getType(), nu.getType()));
                entry.setType(nu.getType());
                anyChanged = true;
                changedType = true;
            }
            compound.end();

            if (!anyChanged)
                return true;

            panel.undoManager.addEdit(compound);
View Full Code Here

Examples of net.sf.jabref.undo.NamedCompound

  public DuplicateSearch(BasePanel bp) {
    panel = bp;
  }

public void run() {
  final NamedCompound ce = new NamedCompound(Globals.lang("duplicate removal"));
  int duplicateCounter = 0;
 
  autoRemoveExactDuplicates = false;
  panel.output(Globals.lang("Searching for duplicates..."));
  Object[] keys = panel.database.getKeySet().toArray();
  if ((keys == null) || (keys.length < 2))
    return;
  bes = new BibtexEntry[keys.length];
  for (int i=0; i<keys.length; i++)
    bes[i] = panel.database.getEntryById((String)keys[i]);

  SearcherThread st = new SearcherThread();
  st.setPriority(Thread.MIN_PRIORITY);
  st.start();
  int current = 0;

   final ArrayList<BibtexEntry> toRemove = new ArrayList<BibtexEntry>();
  while (!st.finished() || (current < duplicates.size()))
  {

    if (current >= duplicates.size() )
    {
      // wait until the search thread puts something into duplicates vector
      // or finish its work
      synchronized(duplicates)
      {
         try
         {
           duplicates.wait();
         }
         catch (Exception e) {}
      }
    } else  // duplicates found
    {


        BibtexEntry[] be = duplicates.get(current);
        current++;
        if (!toRemove.contains(be[0]) && !toRemove.contains(be[1])) {
            // Check if they are exact duplicates:
            boolean askAboutExact = false;
            if (DuplicateCheck.compareEntriesStrictly(be[0], be[1]) > 1) {
                if (autoRemoveExactDuplicates) {
                    toRemove.add(be[1]);
                    duplicateCounter++;
                    continue;
                } else {
                    askAboutExact = true;
                }
            }

            DuplicateCallBack cb = new DuplicateCallBack(panel.frame, be[0], be[1],
                    askAboutExact ? DuplicateResolverDialog.DUPLICATE_SEARCH_WITH_EXACT :
                            DuplicateResolverDialog.DUPLICATE_SEARCH);
            ((CallBack)(Spin.over(cb))).update();

            duplicateCounter++;
            int answer = cb.getSelected();
            if ((answer == DuplicateResolverDialog.KEEP_UPPER)
                    || (answer == DuplicateResolverDialog.AUTOREMOVE_EXACT)) {
                toRemove.add(be[1]);
                if (answer == DuplicateResolverDialog.AUTOREMOVE_EXACT)
                    autoRemoveExactDuplicates = true; // Remember choice
            } else if (answer == DuplicateResolverDialog.KEEP_LOWER) {
                toRemove.add(be[0]);
            } else if (answer == DuplicateResolverDialog.BREAK) {
                st.setFinished(); // thread killing
                current = Integer.MAX_VALUE;
                duplicateCounter--; // correct counter
            }
        }
    }
  }

    final int dupliC = duplicateCounter;
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            // Now, do the actual removal:
            if (toRemove.size() > 0) {
                for (Iterator<BibtexEntry> iterator = toRemove.iterator(); iterator.hasNext();) {
                    BibtexEntry entry = iterator.next();
                    panel.database.removeEntry(entry.getId());
                    ce.addEdit(new UndoableRemoveEntry(panel.database, entry, panel));
                }
                panel.markBaseChanged();
            }
            panel.output(Globals.lang("Duplicate pairs found") + ": " + duplicates.size()
                       +" " +Globals.lang("pairs processed") +": " +dupliC );


                ce.end();
                panel.undoManager.addEdit(ce);

        }

    });
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.