// see if there
// are unresolved duplicates, and warn if yes.
if (Globals.prefs.getBoolean("warnAboutDuplicatesInInspection")) {
for (Iterator<BibtexEntry> i = entries.iterator(); i.hasNext();) {
BibtexEntry entry = i.next();
// Only check entries that are to be imported. Keep status
// is indicated
// through the search hit status of the entry:
if (!entry.isSearchHit())
continue;
// Check if the entry is a suspected, unresolved, duplicate.
// This status
// is indicated by the entry's group hit status:
if (entry.isGroupHit()) {
CheckBoxMessage cbm = new CheckBoxMessage(
Globals
.lang("There are possible duplicates (marked with a 'D' icon) that haven't been resolved. Continue?"),
Globals.lang("Disable this confirmation dialog"), false);
int answer = JOptionPane.showConfirmDialog(ImportInspectionDialog.this,
cbm, Globals.lang("Duplicates found"), JOptionPane.YES_NO_OPTION);
if (cbm.isSelected())
Globals.prefs.putBoolean("warnAboutDuplicatesInInspection", false);
if (answer == JOptionPane.NO_OPTION)
return;
break;
}
}
}
// 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));