Search in sources :

Example 1 with EntryTypeDialog

use of org.jabref.gui.EntryTypeDialog in project jabref by JabRef.

the class NewEntryAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    String thisType = type;
    if (thisType == null) {
        EntryTypeDialog etd = new EntryTypeDialog(jabRefFrame);
        etd.setLocationRelativeTo(jabRefFrame);
        etd.setVisible(true);
        EntryType tp = etd.getChoice();
        if (tp == null) {
            return;
        }
        thisType = tp.getName();
    }
    if (jabRefFrame.getBasePanelCount() > 0) {
        jabRefFrame.getCurrentBasePanel().newEntry(EntryTypes.getType(thisType, jabRefFrame.getCurrentBasePanel().getBibDatabaseContext().getMode()).get());
    } else {
        LOGGER.info("Action 'New entry' must be disabled when no database is open.");
    }
}
Also used : EntryType(org.jabref.model.entry.EntryType) EntryTypeDialog(org.jabref.gui.EntryTypeDialog)

Example 2 with EntryTypeDialog

use of org.jabref.gui.EntryTypeDialog in project jabref by JabRef.

the class PdfImporter method createNewEntry.

private Optional<BibEntry> createNewEntry() {
    // Find out what type is desired
    EntryTypeDialog etd = new EntryTypeDialog(frame);
    // We want to center the dialog, to make it look nicer.
    etd.setLocationRelativeTo(frame);
    etd.setVisible(true);
    EntryType type = etd.getChoice();
    if (type != null) {
        // Only if the dialog was not canceled.
        final BibEntry bibEntry = new BibEntry(type.getName());
        try {
            panel.getDatabase().insertEntry(bibEntry);
            // Set owner/timestamp if options are enabled:
            List<BibEntry> list = new ArrayList<>();
            list.add(bibEntry);
            UpdateField.setAutomaticFields(list, true, true, Globals.prefs.getUpdateFieldPreferences());
            // Create an UndoableInsertEntry object.
            panel.getUndoManager().addEdit(new UndoableInsertEntry(panel.getDatabase(), bibEntry, panel));
            panel.output(Localization.lang("Added new") + " '" + type.getName().toLowerCase(Locale.ROOT) + "' " + Localization.lang("entry") + ".");
            // and adjustment of the splitter.
            if (panel.getMode() != BasePanelMode.SHOWING_EDITOR) {
                panel.setMode(BasePanelMode.WILL_SHOW_EDITOR);
            }
            SwingUtilities.invokeLater(() -> panel.showEntry(bibEntry));
            // The database just changed.
            panel.markBaseChanged();
            return Optional.of(bibEntry);
        } catch (KeyCollisionException ex) {
            LOGGER.info("Key collision occurred", ex);
        }
    }
    return Optional.empty();
}
Also used : KeyCollisionException(org.jabref.model.database.KeyCollisionException) BibEntry(org.jabref.model.entry.BibEntry) EntryType(org.jabref.model.entry.EntryType) EntryTypeDialog(org.jabref.gui.EntryTypeDialog) ArrayList(java.util.ArrayList) UndoableInsertEntry(org.jabref.gui.undo.UndoableInsertEntry)

Aggregations

EntryTypeDialog (org.jabref.gui.EntryTypeDialog)2 EntryType (org.jabref.model.entry.EntryType)2 ArrayList (java.util.ArrayList)1 UndoableInsertEntry (org.jabref.gui.undo.UndoableInsertEntry)1 KeyCollisionException (org.jabref.model.database.KeyCollisionException)1 BibEntry (org.jabref.model.entry.BibEntry)1