use of org.jabref.gui.BasePanel in project jabref by JabRef.
the class SendAsEMailAction method run.
@Override
public void run() {
if (!Desktop.isDesktopSupported()) {
message = Localization.lang("Error creating email");
return;
}
BasePanel panel = frame.getCurrentBasePanel();
if (panel == null) {
return;
}
if (panel.getSelectedEntries().isEmpty()) {
message = Localization.lang("This operation requires one or more entries to be selected.");
return;
}
StringWriter sw = new StringWriter();
List<BibEntry> bes = panel.getSelectedEntries();
// write the entries using sw, which is used later to form the email content
BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(Globals.prefs.getLatexFieldFormatterPreferences()), true);
for (BibEntry entry : bes) {
try {
bibtexEntryWriter.write(entry, sw, panel.getBibDatabaseContext().getMode());
} catch (IOException e) {
LOGGER.warn("Problem creating BibTeX file for mailing.", e);
}
}
List<String> attachments = new ArrayList<>();
// open folders is needed to indirectly support email programs, which cannot handle
// the unofficial "mailto:attachment" property
boolean openFolders = JabRefPreferences.getInstance().getBoolean(JabRefPreferences.OPEN_FOLDERS_OF_ATTACHED_FILES);
List<Path> fileList = FileUtil.getListOfLinkedFiles(bes, frame.getCurrentBasePanel().getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences()));
for (Path f : fileList) {
attachments.add(f.toAbsolutePath().toString());
if (openFolders) {
try {
JabRefDesktop.openFolderAndSelectFile(f.toAbsolutePath());
} catch (IOException e) {
LOGGER.debug("Cannot open file", e);
}
}
}
String mailTo = "?Body=".concat(sw.getBuffer().toString());
mailTo = mailTo.concat("&Subject=");
mailTo = mailTo.concat(JabRefPreferences.getInstance().get(JabRefPreferences.EMAIL_SUBJECT));
for (String path : attachments) {
mailTo = mailTo.concat("&Attachment=\"").concat(path);
mailTo = mailTo.concat("\"");
}
URI uriMailTo;
try {
uriMailTo = new URI("mailto", mailTo, null);
} catch (URISyntaxException e1) {
message = Localization.lang("Error creating email");
LOGGER.warn(message, e1);
return;
}
Desktop desktop = Desktop.getDesktop();
try {
desktop.mail(uriMailTo);
} catch (IOException e) {
message = Localization.lang("Error creating email");
LOGGER.warn(message, e);
return;
}
message = String.format("%s: %d", Localization.lang("Entries added to an email"), bes.size());
}
use of org.jabref.gui.BasePanel in project jabref by JabRef.
the class SearchResultsTest method testSearchFieldQuery.
@Test
public void testSearchFieldQuery() {
frameFixture.menuItemWithPath("Search", "Search").click();
JTextComponentFixture searchField = frameFixture.textBox();
ComponentFinder finder = robot().finder();
BasePanel panel = finder.findByType(BasePanel.class);
Collection<BibEntry> entries = panel.getDatabase().getEntries();
searchField.deleteText().enterText("");
Assert.assertEquals(19, entries.size());
searchField.deleteText().enterText("entrytype=article");
Assert.assertFalse(entries.stream().noneMatch(entry -> entry.isSearchHit()));
Assert.assertEquals(5, entries.stream().filter(entry -> entry.isSearchHit()).count());
searchField.deleteText().enterText("entrytype=proceedings");
Assert.assertFalse(entries.stream().noneMatch(entry -> entry.isSearchHit()));
Assert.assertEquals(13, entries.stream().filter(entry -> entry.isSearchHit()).count());
searchField.deleteText().enterText("entrytype=book");
Assert.assertFalse(entries.stream().noneMatch(entry -> entry.isSearchHit()));
Assert.assertEquals(1, entries.stream().filter(entry -> entry.isSearchHit()).count());
}
use of org.jabref.gui.BasePanel in project jabref by JabRef.
the class SearchResultsTest method testSeachWithoutResults.
@Test
public void testSeachWithoutResults() {
frameFixture.menuItemWithPath("Search", "Search").click();
JTextComponentFixture searchField = frameFixture.textBox();
ComponentFinder finder = robot().finder();
BasePanel panel = finder.findByType(BasePanel.class);
Collection<BibEntry> entries = panel.getDatabase().getEntries();
searchField.deleteText().enterText("asdf");
Assert.assertTrue(entries.stream().noneMatch(entry -> entry.isSearchHit()));
}
use of org.jabref.gui.BasePanel in project jabref by JabRef.
the class ManageKeywordsAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
BasePanel bp = frame.getCurrentBasePanel();
if (bp == null) {
return;
}
if (bp.getSelectedEntries().isEmpty()) {
bp.output(Localization.lang("Select at least one entry to manage keywords."));
return;
}
// Lazy creation of the dialog:
createDialog();
canceled = true;
fillKeyWordList();
diag.pack();
diag.setLocationRelativeTo(frame);
diag.setVisible(true);
if (canceled) {
return;
}
KeywordList keywordsToAdd = new KeywordList();
KeywordList userSelectedKeywords = new KeywordList();
// build keywordsToAdd and userSelectedKeywords in parallel
for (Enumeration<Keyword> keywords = keywordListModel.elements(); keywords.hasMoreElements(); ) {
Keyword keyword = keywords.nextElement();
userSelectedKeywords.add(keyword);
if (!sortedKeywordsOfAllEntriesBeforeUpdateByUser.contains(keyword)) {
keywordsToAdd.add(keyword);
}
}
KeywordList keywordsToRemove = new KeywordList();
for (Keyword kword : sortedKeywordsOfAllEntriesBeforeUpdateByUser) {
if (!userSelectedKeywords.contains(kword)) {
keywordsToRemove.add(kword);
}
}
if (keywordsToAdd.isEmpty() && keywordsToRemove.isEmpty()) {
// nothing to be done if nothing is new and nothing is obsolete
return;
}
if (Globals.prefs.isKeywordSyncEnabled() && !keywordsToAdd.isEmpty()) {
SpecialFieldsUtils.synchronizeSpecialFields(keywordsToAdd, keywordsToRemove);
}
NamedCompound ce = updateKeywords(bp.getSelectedEntries(), keywordsToAdd, keywordsToRemove);
bp.getUndoManager().addEdit(ce);
bp.markBaseChanged();
}
use of org.jabref.gui.BasePanel in project jabref by JabRef.
the class FromAuxDialog method parseActionPerformed.
private void parseActionPerformed() {
parseButton.setEnabled(false);
BasePanel bp = (BasePanel) parentTabbedPane.getComponentAt(dbChooser.getSelectedIndex());
notFoundList.removeAll();
statusInfos.setText(null);
BibDatabase refBase = bp.getDatabase();
String auxName = auxFileField.getText();
if ((auxName != null) && (refBase != null) && !auxName.isEmpty()) {
auxParser = new AuxParser(auxName, refBase);
AuxParserResult result = auxParser.parse();
notFoundList.setListData(result.getUnresolvedKeys().toArray(new String[result.getUnresolvedKeys().size()]));
statusInfos.append(result.getInformation(false));
generateButton.setEnabled(true);
// the generated database contains no entries -> no active generate-button
if (!result.getGeneratedBibDatabase().hasEntries()) {
statusInfos.append("\n" + Localization.lang("empty library"));
generateButton.setEnabled(false);
}
} else {
generateButton.setEnabled(false);
}
parseButton.setEnabled(true);
}
Aggregations