use of org.jabref.model.database.KeyCollisionException in project jabref by JabRef.
the class BasePanel method newEntry.
/**
* This method is called from JabRefFrame when the user wants to create a new entry. If the argument is null, the
* user is prompted for an entry type.
*
* @param type The type of the entry to create.
* @return The newly created BibEntry or null the operation was canceled by the user.
*/
public BibEntry newEntry(EntryType type) {
EntryType actualType = type;
if (actualType == null) {
// Find out what type is wanted.
final EntryTypeDialog etd = new EntryTypeDialog(frame);
// We want to center the dialog, to make it look nicer.
etd.setLocationRelativeTo(frame);
etd.setVisible(true);
actualType = etd.getChoice();
}
if (actualType != null) {
// Only if the dialog was not canceled.
final BibEntry be = new BibEntry(actualType.getName());
try {
bibDatabaseContext.getDatabase().insertEntry(be);
// Set owner/timestamp if options are enabled:
List<BibEntry> list = new ArrayList<>();
list.add(be);
UpdateField.setAutomaticFields(list, true, true, Globals.prefs.getUpdateFieldPreferences());
// Create an UndoableInsertEntry object.
getUndoManager().addEdit(new UndoableInsertEntry(bibDatabaseContext.getDatabase(), be, BasePanel.this));
output(Localization.lang("Added new '%0' entry.", actualType.getName().toLowerCase(Locale.ROOT)));
// and adjustment of the splitter.
if (mode != BasePanelMode.SHOWING_EDITOR) {
mode = BasePanelMode.WILL_SHOW_EDITOR;
}
highlightEntry(be);
// The database just changed.
markBaseChanged();
final EntryEditor entryEditor = getEntryEditor(be);
this.showEntryEditor(entryEditor);
entryEditor.requestFocus();
return be;
} catch (KeyCollisionException ex) {
LOGGER.info(ex.getMessage(), ex);
}
}
return null;
}
use of org.jabref.model.database.KeyCollisionException 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.model.database.KeyCollisionException in project jabref by JabRef.
the class AppendDatabaseAction method openIt.
private void openIt(boolean importEntries, boolean importStrings, boolean importGroups, boolean importSelectorWords) {
if (filesToOpen.isEmpty()) {
return;
}
for (Path file : filesToOpen) {
try {
Globals.prefs.put(JabRefPreferences.WORKING_DIRECTORY, file.getParent().toString());
// Should this be done _after_ we know it was successfully opened?
ParserResult parserResult = OpenDatabase.loadDatabase(file.toFile(), Globals.prefs.getImportFormatPreferences());
AppendDatabaseAction.mergeFromBibtex(panel, parserResult, importEntries, importStrings, importGroups, importSelectorWords);
panel.output(Localization.lang("Imported from library") + " '" + file + "'");
} catch (IOException | KeyCollisionException ex) {
LOGGER.warn("Could not open database", ex);
JOptionPane.showMessageDialog(panel, ex.getMessage(), Localization.lang("Open library"), JOptionPane.ERROR_MESSAGE);
}
}
}
use of org.jabref.model.database.KeyCollisionException in project jabref by JabRef.
the class BibtexParser method parseBibtexString.
private void parseBibtexString() throws IOException {
BibtexString bibtexString = parseString();
bibtexString.setParsedSerialization(dumpTextReadSoFarToString());
try {
database.addString(bibtexString);
} catch (KeyCollisionException ex) {
parserResult.addWarning(Localization.lang("Duplicate string name") + ": " + bibtexString.getName());
}
}
use of org.jabref.model.database.KeyCollisionException in project jabref by JabRef.
the class PdfImporter method createNewEntry.
private Optional<BibEntry> createNewEntry() {
// Find out what type is desired
EntryTypeDialog etd = new EntryTypeDialog(frame);
// We want to center the dialog, to make it look nicer.
etd.setLocationRelativeTo(frame);
etd.setVisible(true);
EntryType type = etd.getChoice();
if (type != null) {
// Only if the dialog was not canceled.
final BibEntry bibEntry = new BibEntry(type.getName());
try {
panel.getDatabase().insertEntry(bibEntry);
// Set owner/timestamp if options are enabled:
List<BibEntry> list = new ArrayList<>();
list.add(bibEntry);
UpdateField.setAutomaticFields(list, true, true, Globals.prefs.getUpdateFieldPreferences());
// Create an UndoableInsertEntry object.
panel.getUndoManager().addEdit(new UndoableInsertEntry(panel.getDatabase(), bibEntry, panel));
panel.output(Localization.lang("Added new") + " '" + type.getName().toLowerCase(Locale.ROOT) + "' " + Localization.lang("entry") + ".");
// and adjustment of the splitter.
if (panel.getMode() != BasePanelMode.SHOWING_EDITOR) {
panel.setMode(BasePanelMode.WILL_SHOW_EDITOR);
}
SwingUtilities.invokeLater(() -> panel.showEntry(bibEntry));
// The database just changed.
panel.markBaseChanged();
return Optional.of(bibEntry);
} catch (KeyCollisionException ex) {
LOGGER.info("Key collision occurred", ex);
}
}
return Optional.empty();
}
Aggregations