use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class ManageKeywordsAction method fillKeyWordList.
private void fillKeyWordList() {
BasePanel bp = frame.getCurrentBasePanel();
List<BibEntry> entries = bp.getSelectedEntries();
// fill dialog with values
keywordListModel.clear();
sortedKeywordsOfAllEntriesBeforeUpdateByUser.clear();
if (mergeKeywords.isSelected()) {
for (BibEntry entry : entries) {
KeywordList separatedKeywords = entry.getKeywords(Globals.prefs.getKeywordDelimiter());
sortedKeywordsOfAllEntriesBeforeUpdateByUser.addAll(separatedKeywords);
}
} else {
assert intersectKeywords.isSelected();
// all keywords from first entry have to be added
BibEntry firstEntry = entries.get(0);
KeywordList separatedKeywords = firstEntry.getKeywords(Globals.prefs.getKeywordDelimiter());
sortedKeywordsOfAllEntriesBeforeUpdateByUser.addAll(separatedKeywords);
// this approach ensures that one empty keyword list leads to an empty set of common keywords
for (int i = 1; i < entries.size(); i++) {
BibEntry entry = entries.get(i);
separatedKeywords = entry.getKeywords(Globals.prefs.getKeywordDelimiter());
sortedKeywordsOfAllEntriesBeforeUpdateByUser.retainAll(separatedKeywords);
}
}
for (Keyword keyword : sortedKeywordsOfAllEntriesBeforeUpdateByUser) {
keywordListModel.addElement(keyword);
}
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class ManageKeywordsAction method updateKeywords.
private NamedCompound updateKeywords(List<BibEntry> entries, KeywordList keywordsToAdd, KeywordList keywordsToRemove) {
NamedCompound ce = new NamedCompound(Localization.lang("Update keywords"));
for (BibEntry entry : entries) {
KeywordList keywords = entry.getKeywords(Globals.prefs.getKeywordDelimiter());
// update keywords
keywords.removeAll(keywordsToRemove);
keywords.addAll(keywordsToAdd);
// put keywords back
Optional<FieldChange> change = entry.putKeywords(keywords, Globals.prefs.getKeywordDelimiter());
if (change.isPresent()) {
ce.addEdit(new UndoableFieldChange(change.get()));
}
if (Globals.prefs.isKeywordSyncEnabled()) {
SpecialFieldsUtils.syncSpecialFieldsFromKeywords(entry, Globals.prefs.getKeywordDelimiter());
}
}
ce.end();
return ce;
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class SaveDatabaseAction method saveDatabase.
private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding) throws SaveException {
SaveSession session;
// block user input
frame.block();
try {
SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs).withEncoding(encoding);
BibtexDatabaseWriter<SaveSession> databaseWriter = new BibtexDatabaseWriter<>(FileSaveSession::new);
if (selectedOnly) {
session = databaseWriter.savePartOfDatabase(panel.getBibDatabaseContext(), panel.getSelectedEntries(), prefs);
} else {
session = databaseWriter.saveDatabase(panel.getBibDatabaseContext(), prefs);
}
panel.registerUndoableChanges(session);
} catch (UnsupportedCharsetException ex) {
JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + Localization.lang("Character encoding '%0' is not supported.", encoding.displayName()), Localization.lang("Save library"), JOptionPane.ERROR_MESSAGE);
// FIXME: rethrow anti-pattern
throw new SaveException("rt");
} catch (SaveException ex) {
if (ex == SaveException.FILE_LOCKED) {
throw ex;
}
if (ex.specificEntry()) {
BibEntry entry = ex.getEntry();
// Error occured during processing of an entry. Highlight it!
panel.highlightEntry(entry);
} else {
LOGGER.error("A problem occured when trying to save the file", ex);
}
JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + ".\n" + ex.getMessage(), Localization.lang("Save library"), JOptionPane.ERROR_MESSAGE);
// FIXME: rethrow anti-pattern
throw new SaveException("rt");
} finally {
// re-enable user input
frame.unblock();
}
// handle encoding problems
boolean success = true;
if (!session.getWriter().couldEncodeAll()) {
FormBuilder builder = FormBuilder.create().layout(new FormLayout("left:pref, 4dlu, fill:pref", "pref, 4dlu, pref"));
JTextArea ta = new JTextArea(session.getWriter().getProblemCharacters());
ta.setEditable(false);
builder.add(Localization.lang("The chosen encoding '%0' could not encode the following characters:", session.getEncoding().displayName())).xy(1, 1);
builder.add(ta).xy(3, 1);
builder.add(Localization.lang("What do you want to do?")).xy(1, 3);
String tryDiff = Localization.lang("Try different encoding");
int answer = JOptionPane.showOptionDialog(frame, builder.getPanel(), Localization.lang("Save library"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, new String[] { Localization.lang("Save"), tryDiff, Localization.lang("Cancel") }, tryDiff);
if (answer == JOptionPane.NO_OPTION) {
// The user wants to use another encoding.
Object choice = JOptionPane.showInputDialog(frame, Localization.lang("Select encoding"), Localization.lang("Save library"), JOptionPane.QUESTION_MESSAGE, null, Encodings.ENCODINGS_DISPLAYNAMES, encoding);
if (choice == null) {
success = false;
} else {
Charset newEncoding = Charset.forName((String) choice);
return saveDatabase(file, selectedOnly, newEncoding);
}
} else if (answer == JOptionPane.CANCEL_OPTION) {
success = false;
}
}
// backup file?
try {
if (success) {
session.commit(file.toPath());
// Make sure to remember which encoding we used.
panel.getBibDatabaseContext().getMetaData().setEncoding(encoding, ChangePropagation.DO_NOT_POST_EVENT);
} else {
session.cancel();
}
} catch (SaveException e) {
int ans = JOptionPane.showConfirmDialog(null, Localization.lang("Save failed during backup creation") + ". " + Localization.lang("Save without backup?"), Localization.lang("Unable to create backup"), JOptionPane.YES_NO_OPTION);
if (ans == JOptionPane.YES_OPTION) {
session.setUseBackup(false);
session.commit(file.toPath());
panel.getBibDatabaseContext().getMetaData().setEncoding(encoding, ChangePropagation.DO_NOT_POST_EVENT);
} else {
success = false;
}
}
return success;
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class DocumentViewerViewModel method setCurrentEntries.
private void setCurrentEntries(List<BibEntry> entries) {
if (!entries.isEmpty()) {
BibEntry firstSelectedEntry = entries.get(0);
setCurrentEntry(firstSelectedEntry);
}
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class EntryEditorTabRelatedArticles method setHtmlText.
/**
* Takes a List of HTML snippets stored in the field "html_representation" of a list of bibentries and sets it in the JEditorPane
*
* @param list of bib entries having a field html_representation
*/
public void setHtmlText(List<BibEntry> list) {
StringBuilder htmlContent = new StringBuilder();
URL url = IconTheme.getIconUrl("mdlListIcon");
htmlContent.append("<html><head><title></title></head><body bgcolor='#ffffff'>");
htmlContent.append("<ul style='list-style-image:(");
htmlContent.append(url);
htmlContent.append(")'>");
list.stream().map(bibEntry -> bibEntry.getField("html_representation")).filter(Optional::isPresent).map(o -> "<li style='margin: 5px'>" + o.get() + "</li>").forEach(html -> htmlContent.append(html));
htmlContent.append("</ul>");
htmlContent.append("<br><div style='margin-left: 5px'>");
htmlContent.append("<a href='http://mr-dlib.org/information-for-users/information-about-mr-dlib-for-jabref-users/#'>");
htmlContent.append(Localization.lang("What_is_Mr._DLib?"));
htmlContent.append("</a></div>");
htmlContent.append("</body></html>");
this.setText(htmlContent.toString());
}
Aggregations