Search in sources :

Example 36 with BibEntry

use of org.jabref.model.entry.BibEntry in project jabref by JabRef.

the class ArgumentProcessor method fetch.

/**
     * Run an entry fetcher from the command line.
     * <p>
     * Note that this only works headlessly if the EntryFetcher does not show any GUI.
     *
     * @param fetchCommand A string containing both the fetcher to use (id of EntryFetcherExtension minus Fetcher) and
     *                     the search query, separated by a :
     * @return A parser result containing the entries fetched or null if an error occurred.
     */
private Optional<ParserResult> fetch(String fetchCommand) {
    if ((fetchCommand == null) || !fetchCommand.contains(":") || (fetchCommand.split(":").length != 2)) {
        System.out.println(Localization.lang("Expected syntax for --fetch='<name of fetcher>:<query>'"));
        System.out.println(Localization.lang("The following fetchers are available:"));
        return Optional.empty();
    }
    String[] split = fetchCommand.split(":");
    String engine = split[0];
    EntryFetchers fetchers = new EntryFetchers(Globals.journalAbbreviationLoader);
    EntryFetcher fetcher = null;
    for (EntryFetcher e : fetchers.getEntryFetchers()) {
        if (engine.equalsIgnoreCase(e.getClass().getSimpleName().replace("Fetcher", ""))) {
            fetcher = e;
        }
    }
    if (fetcher == null) {
        System.out.println(Localization.lang("Could not find fetcher '%0'", engine));
        System.out.println(Localization.lang("The following fetchers are available:"));
        for (EntryFetcher e : fetchers.getEntryFetchers()) {
            System.out.println("  " + e.getClass().getSimpleName().replace("Fetcher", "").toLowerCase(Locale.ENGLISH));
        }
        return Optional.empty();
    }
    String query = split[1];
    System.out.println(Localization.lang("Running query '%0' with fetcher '%1'.", query, engine) + " " + Localization.lang("Please wait..."));
    Collection<BibEntry> result = new ImportInspectionCommandLine().query(query, fetcher);
    if (result.isEmpty()) {
        System.out.println(Localization.lang("Query '%0' with fetcher '%1' did not return any results.", query, engine));
        return Optional.empty();
    }
    return Optional.of(new ParserResult(result));
}
Also used : EntryFetcher(org.jabref.gui.importer.fetcher.EntryFetcher) BibEntry(org.jabref.model.entry.BibEntry) ParserResult(org.jabref.logic.importer.ParserResult) EntryFetchers(org.jabref.gui.importer.fetcher.EntryFetchers)

Example 37 with BibEntry

use of org.jabref.model.entry.BibEntry in project jabref by JabRef.

the class BasePanel method copy.

private void copy() {
    List<BibEntry> bes = mainTable.getSelectedEntries();
    if (bes.isEmpty()) {
        // The user maybe selected a single cell.
        // TODO: Check if this can actually happen
        int[] rows = mainTable.getSelectedRows();
        int[] cols = mainTable.getSelectedColumns();
        if ((cols.length == 1) && (rows.length == 1)) {
            // Copy single value.
            Object o = mainTable.getValueAt(rows[0], cols[0]);
            if (o != null) {
                StringSelection ss = new StringSelection(o.toString());
                Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, BasePanel.this);
                output(Localization.lang("Copied cell contents") + '.');
            }
        }
    } else {
        TransferableBibtexEntry trbe = new TransferableBibtexEntry(bes);
        // ! look at ClipBoardManager
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(trbe, BasePanel.this);
        output(formatOutputMessage(Localization.lang("Copied"), bes.size()));
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) StringSelection(java.awt.datatransfer.StringSelection)

Example 38 with BibEntry

use of org.jabref.model.entry.BibEntry in project jabref by JabRef.

the class BasePanel method delete.

/**
     * Removes the selected entries from the database
     * @param cut If false the user will get asked if he really wants to delete the entries, and it will be localized
     *            as "deleted".
     *            If true the action will be localized as "cut"
     */
private void delete(boolean cut) {
    List<BibEntry> entries = mainTable.getSelectedEntries();
    if (entries.isEmpty()) {
        return;
    }
    if (!cut && !showDeleteConfirmationDialog(entries.size())) {
        return;
    }
    // select the next entry to stay at the same place as before (or the previous if we're already at the end)
    if (mainTable.getSelectedRow() != (mainTable.getRowCount() - 1)) {
        selectNextEntry();
    } else {
        selectPreviousEntry();
    }
    NamedCompound compound;
    if (cut) {
        compound = new NamedCompound((entries.size() > 1 ? Localization.lang("cut entries") : Localization.lang("cut entry")));
    } else {
        compound = new NamedCompound((entries.size() > 1 ? Localization.lang("delete entries") : Localization.lang("delete entry")));
    }
    for (BibEntry entry : entries) {
        compound.addEdit(new UndoableRemoveEntry(bibDatabaseContext.getDatabase(), entry, BasePanel.this));
        bibDatabaseContext.getDatabase().removeEntry(entry);
        ensureNotShowingBottomPanel(entry);
    }
    compound.end();
    getUndoManager().addEdit(compound);
    markBaseChanged();
    frame.output(formatOutputMessage(cut ? Localization.lang("Cut") : Localization.lang("Deleted"), entries.size()));
    // prevent the main table from loosing focus
    mainTable.requestFocus();
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) NamedCompound(org.jabref.gui.undo.NamedCompound) UndoableRemoveEntry(org.jabref.gui.undo.UndoableRemoveEntry)

Example 39 with BibEntry

use of org.jabref.model.entry.BibEntry in project jabref by JabRef.

the class BasePanel method editEntryByIdAndFocusField.

public void editEntryByIdAndFocusField(final String entryId, final String fieldName) {
    final Optional<BibEntry> entry = bibDatabaseContext.getDatabase().getEntryById(entryId);
    entry.ifPresent(e -> {
        mainTable.setSelected(mainTable.findEntry(e));
        selectionListener.editSignalled();
        final EntryEditor editor = getEntryEditor(e);
        editor.setFocusToField(fieldName);
        this.showEntryEditor(editor);
        editor.requestFocus();
    });
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) EntryEditor(org.jabref.gui.entryeditor.EntryEditor)

Example 40 with BibEntry

use of org.jabref.model.entry.BibEntry in project jabref by JabRef.

the class CleanupAction method run.

@Override
public void run() {
    if (canceled) {
        return;
    }
    CleanupPresetPanel presetPanel = new CleanupPresetPanel(panel.getBibDatabaseContext(), CleanupPreset.loadFromPreferences(preferences));
    int choice = showDialog(presetPanel);
    if (choice != JOptionPane.OK_OPTION) {
        canceled = true;
        return;
    }
    CleanupPreset cleanupPreset = presetPanel.getCleanupPreset();
    cleanupPreset.storeInPreferences(preferences);
    if (cleanupPreset.isRenamePDF() && Globals.prefs.getBoolean(JabRefPreferences.ASK_AUTO_NAMING_PDFS_AGAIN)) {
        CheckBoxMessage cbm = new CheckBoxMessage(Localization.lang("Auto-generating PDF-Names does not support undo. Continue?"), Localization.lang("Disable this confirmation dialog"), false);
        int answer = JOptionPane.showConfirmDialog(frame, cbm, Localization.lang("Autogenerate PDF Names"), JOptionPane.YES_NO_OPTION);
        if (cbm.isSelected()) {
            Globals.prefs.putBoolean(JabRefPreferences.ASK_AUTO_NAMING_PDFS_AGAIN, false);
        }
        if (answer == JOptionPane.NO_OPTION) {
            canceled = true;
            return;
        }
    }
    for (BibEntry entry : panel.getSelectedEntries()) {
        // undo granularity is on entry level
        NamedCompound ce = new NamedCompound(Localization.lang("Cleanup entry"));
        doCleanup(cleanupPreset, entry, ce);
        ce.end();
        if (ce.hasEdits()) {
            modifiedEntriesCount++;
            panel.getUndoManager().addEdit(ce);
        }
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) NamedCompound(org.jabref.gui.undo.NamedCompound) CheckBoxMessage(org.jabref.gui.util.component.CheckBoxMessage) CleanupPreset(org.jabref.logic.cleanup.CleanupPreset) CleanupPresetPanel(org.jabref.gui.cleanup.CleanupPresetPanel)

Aggregations

BibEntry (org.jabref.model.entry.BibEntry)716 Test (org.junit.Test)466 ParserResult (org.jabref.logic.importer.ParserResult)131 StringReader (java.io.StringReader)107 ArrayList (java.util.ArrayList)75 BibDatabase (org.jabref.model.database.BibDatabase)63 Path (java.nio.file.Path)52 IOException (java.io.IOException)43 HashMap (java.util.HashMap)37 Before (org.junit.Before)36 NamedCompound (org.jabref.gui.undo.NamedCompound)30 BibtexParser (org.jabref.logic.importer.fileformat.BibtexParser)28 BibtexString (org.jabref.model.entry.BibtexString)28 List (java.util.List)23 File (java.io.File)21 StringWriter (java.io.StringWriter)19 Optional (java.util.Optional)19 BasePanel (org.jabref.gui.BasePanel)19 FieldChange (org.jabref.model.FieldChange)18 InputStream (java.io.InputStream)16