Search in sources :

Example 16 with BasePanel

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());
}
Also used : Path(java.nio.file.Path) BibEntry(org.jabref.model.entry.BibEntry) BasePanel(org.jabref.gui.BasePanel) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) BibEntryWriter(org.jabref.logic.bibtex.BibEntryWriter) URI(java.net.URI) LatexFieldFormatter(org.jabref.logic.bibtex.LatexFieldFormatter) StringWriter(java.io.StringWriter) Desktop(java.awt.Desktop) JabRefDesktop(org.jabref.gui.desktop.JabRefDesktop)

Example 17 with BasePanel

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());
}
Also used : ComponentFinder(org.assertj.swing.core.ComponentFinder) FailOnThreadViolationRepaintManager(org.assertj.swing.edt.FailOnThreadViolationRepaintManager) BeforeClass(org.junit.BeforeClass) AssertJSwingJUnitTestCase(org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase) Collection(java.util.Collection) BibEntry(org.jabref.model.entry.BibEntry) WindowFinder(org.assertj.swing.finder.WindowFinder) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) BasePanel(org.jabref.gui.BasePanel) TestUtils(org.jabref.testutils.TestUtils) GUITests(org.jabref.testutils.category.GUITests) TimeUnit(java.util.concurrent.TimeUnit) ComponentFinder(org.assertj.swing.core.ComponentFinder) JTextComponentFixture(org.assertj.swing.fixture.JTextComponentFixture) FrameFixture(org.assertj.swing.fixture.FrameFixture) JFrame(javax.swing.JFrame) Assert(org.junit.Assert) BibEntry(org.jabref.model.entry.BibEntry) BasePanel(org.jabref.gui.BasePanel) JTextComponentFixture(org.assertj.swing.fixture.JTextComponentFixture) Test(org.junit.Test)

Example 18 with BasePanel

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()));
}
Also used : ComponentFinder(org.assertj.swing.core.ComponentFinder) FailOnThreadViolationRepaintManager(org.assertj.swing.edt.FailOnThreadViolationRepaintManager) BeforeClass(org.junit.BeforeClass) AssertJSwingJUnitTestCase(org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase) Collection(java.util.Collection) BibEntry(org.jabref.model.entry.BibEntry) WindowFinder(org.assertj.swing.finder.WindowFinder) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) BasePanel(org.jabref.gui.BasePanel) TestUtils(org.jabref.testutils.TestUtils) GUITests(org.jabref.testutils.category.GUITests) TimeUnit(java.util.concurrent.TimeUnit) ComponentFinder(org.assertj.swing.core.ComponentFinder) JTextComponentFixture(org.assertj.swing.fixture.JTextComponentFixture) FrameFixture(org.assertj.swing.fixture.FrameFixture) JFrame(javax.swing.JFrame) Assert(org.junit.Assert) BibEntry(org.jabref.model.entry.BibEntry) BasePanel(org.jabref.gui.BasePanel) JTextComponentFixture(org.assertj.swing.fixture.JTextComponentFixture) Test(org.junit.Test)

Example 19 with BasePanel

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();
}
Also used : BasePanel(org.jabref.gui.BasePanel) Keyword(org.jabref.model.entry.Keyword) NamedCompound(org.jabref.gui.undo.NamedCompound) KeywordList(org.jabref.model.entry.KeywordList)

Example 20 with BasePanel

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);
}
Also used : BasePanel(org.jabref.gui.BasePanel) AuxParser(org.jabref.logic.auxparser.AuxParser) AuxParserResult(org.jabref.logic.auxparser.AuxParserResult) BibDatabase(org.jabref.model.database.BibDatabase)

Aggregations

BasePanel (org.jabref.gui.BasePanel)31 BibEntry (org.jabref.model.entry.BibEntry)14 Path (java.nio.file.Path)4 NamedCompound (org.jabref.gui.undo.NamedCompound)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 JabRefFrame (org.jabref.gui.JabRefFrame)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 List (java.util.List)2 Map (java.util.Map)2 TimeUnit (java.util.concurrent.TimeUnit)2 BorderFactory (javax.swing.BorderFactory)2 JFrame (javax.swing.JFrame)2 JList (javax.swing.JList)2 JOptionPane (javax.swing.JOptionPane)2 ListSelectionModel (javax.swing.ListSelectionModel)2 ComponentFinder (org.assertj.swing.core.ComponentFinder)2 FailOnThreadViolationRepaintManager (org.assertj.swing.edt.FailOnThreadViolationRepaintManager)2 WindowFinder (org.assertj.swing.finder.WindowFinder)2