use of org.jabref.gui.undo.UndoableInsertString in project jabref by JabRef.
the class StringAddChange method makeChange.
@Override
public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound undoEdit) {
if (panel.getDatabase().hasStringLabel(string.getName())) {
// The name to change to is already in the database, so we can't comply.
LOGGER.info("Cannot add string '" + string.getName() + "' because the name " + "is already in use.");
}
try {
panel.getDatabase().addString(string);
undoEdit.addEdit(new UndoableInsertString(panel, panel.getDatabase(), string));
} catch (KeyCollisionException ex) {
LOGGER.info("Error: could not add string '" + string.getName() + "': " + ex.getMessage(), ex);
}
try {
secondary.addString(new BibtexString(string.getName(), string.getContent()));
} catch (KeyCollisionException ex) {
LOGGER.info("Error: could not add string '" + string.getName() + "' to tmp database: " + ex.getMessage(), ex);
}
return true;
}
use of org.jabref.gui.undo.UndoableInsertString in project jabref by JabRef.
the class AppendDatabaseAction method mergeFromBibtex.
private static void mergeFromBibtex(BasePanel panel, ParserResult parserResult, boolean importEntries, boolean importStrings, boolean importGroups, boolean importSelectorWords) throws KeyCollisionException {
BibDatabase fromDatabase = parserResult.getDatabase();
List<BibEntry> appendedEntries = new ArrayList<>();
List<BibEntry> originalEntries = new ArrayList<>();
BibDatabase database = panel.getDatabase();
NamedCompound ce = new NamedCompound(Localization.lang("Append library"));
MetaData meta = parserResult.getMetaData();
if (importEntries) {
// Add entries
boolean overwriteOwner = Globals.prefs.getBoolean(JabRefPreferences.OVERWRITE_OWNER);
boolean overwriteTimeStamp = Globals.prefs.getBoolean(JabRefPreferences.OVERWRITE_TIME_STAMP);
for (BibEntry originalEntry : fromDatabase.getEntries()) {
BibEntry entry = (BibEntry) originalEntry.clone();
UpdateField.setAutomaticFields(entry, overwriteOwner, overwriteTimeStamp, Globals.prefs.getUpdateFieldPreferences());
database.insertEntry(entry);
appendedEntries.add(entry);
originalEntries.add(originalEntry);
ce.addEdit(new UndoableInsertEntry(database, entry, panel));
}
}
if (importStrings) {
for (BibtexString bs : fromDatabase.getStringValues()) {
if (!database.hasStringLabel(bs.getName())) {
database.addString(bs);
ce.addEdit(new UndoableInsertString(panel, database, bs));
}
}
}
if (importGroups) {
meta.getGroups().ifPresent(newGroups -> {
if (newGroups.getGroup() instanceof AllEntriesGroup) {
try {
ExplicitGroup group = new ExplicitGroup("Imported", GroupHierarchyType.INDEPENDENT, Globals.prefs.getKeywordDelimiter());
newGroups.setGroup(group);
group.add(appendedEntries);
} catch (IllegalArgumentException e) {
LOGGER.error(e);
}
}
addGroups(newGroups, ce);
});
}
if (importSelectorWords) {
for (ContentSelector selector : meta.getContentSelectorList()) {
panel.getBibDatabaseContext().getMetaData().addContentSelector(selector);
}
}
ce.end();
panel.getUndoManager().addEdit(ce);
panel.markBaseChanged();
}
use of org.jabref.gui.undo.UndoableInsertString in project jabref by JabRef.
the class StringChange method makeChange.
@Override
public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound undoEdit) {
if (string == null) {
// The string was removed or renamed locally. We guess that it was removed.
BibtexString bs = new BibtexString(label, disk);
try {
panel.getDatabase().addString(bs);
undoEdit.addEdit(new UndoableInsertString(panel, panel.getDatabase(), bs));
} catch (KeyCollisionException ex) {
LOGGER.info("Error: could not add string '" + bs.getName() + "': " + ex.getMessage(), ex);
}
} else {
string.setContent(disk);
undoEdit.addEdit(new UndoableStringChange(panel, string, false, mem, disk));
}
// Update tmp database:
if (tmpString == null) {
BibtexString bs = new BibtexString(label, disk);
secondary.addString(bs);
} else {
tmpString.setContent(disk);
}
return true;
}
use of org.jabref.gui.undo.UndoableInsertString in project jabref by JabRef.
the class StringNameChange method makeChange.
@Override
public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound undoEdit) {
if (panel.getDatabase().hasStringLabel(disk)) {
// The name to change to is already in the database, so we can't comply.
LOGGER.info("Cannot rename string '" + mem + "' to '" + disk + "' because the name " + "is already in use.");
}
if (string == null) {
// The string was removed or renamed locally. We guess that it was removed.
BibtexString bs = new BibtexString(disk, content);
try {
panel.getDatabase().addString(bs);
undoEdit.addEdit(new UndoableInsertString(panel, panel.getDatabase(), bs));
} catch (KeyCollisionException ex) {
LOGGER.info("Error: could not add string '" + bs.getName() + "': " + ex.getMessage(), ex);
}
} else {
string.setName(disk);
undoEdit.addEdit(new UndoableStringChange(panel, string, true, mem, disk));
}
// Update tmp database:
if (tmpString == null) {
BibtexString bs = new BibtexString(disk, content);
secondary.addString(bs);
} else {
tmpString.setName(disk);
}
return true;
}
Aggregations