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));
}
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()));
}
}
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();
}
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();
});
}
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);
}
}
}
Aggregations