Search in sources :

Example 1 with EntryEditor

use of org.jabref.gui.entryeditor.EntryEditor in project jabref by JabRef.

the class BasePanel method newEntry.

/**
     * This method is called from JabRefFrame when the user wants to create a new entry. If the argument is null, the
     * user is prompted for an entry type.
     *
     * @param type The type of the entry to create.
     * @return The newly created BibEntry or null the operation was canceled by the user.
     */
public BibEntry newEntry(EntryType type) {
    EntryType actualType = type;
    if (actualType == null) {
        // Find out what type is wanted.
        final EntryTypeDialog etd = new EntryTypeDialog(frame);
        // We want to center the dialog, to make it look nicer.
        etd.setLocationRelativeTo(frame);
        etd.setVisible(true);
        actualType = etd.getChoice();
    }
    if (actualType != null) {
        // Only if the dialog was not canceled.
        final BibEntry be = new BibEntry(actualType.getName());
        try {
            bibDatabaseContext.getDatabase().insertEntry(be);
            // Set owner/timestamp if options are enabled:
            List<BibEntry> list = new ArrayList<>();
            list.add(be);
            UpdateField.setAutomaticFields(list, true, true, Globals.prefs.getUpdateFieldPreferences());
            // Create an UndoableInsertEntry object.
            getUndoManager().addEdit(new UndoableInsertEntry(bibDatabaseContext.getDatabase(), be, BasePanel.this));
            output(Localization.lang("Added new '%0' entry.", actualType.getName().toLowerCase(Locale.ROOT)));
            // and adjustment of the splitter.
            if (mode != BasePanelMode.SHOWING_EDITOR) {
                mode = BasePanelMode.WILL_SHOW_EDITOR;
            }
            highlightEntry(be);
            // The database just changed.
            markBaseChanged();
            final EntryEditor entryEditor = getEntryEditor(be);
            this.showEntryEditor(entryEditor);
            entryEditor.requestFocus();
            return be;
        } catch (KeyCollisionException ex) {
            LOGGER.info(ex.getMessage(), ex);
        }
    }
    return null;
}
Also used : KeyCollisionException(org.jabref.model.database.KeyCollisionException) BibEntry(org.jabref.model.entry.BibEntry) EntryEditor(org.jabref.gui.entryeditor.EntryEditor) EntryType(org.jabref.model.entry.EntryType) ArrayList(java.util.ArrayList) UndoableInsertEntry(org.jabref.gui.undo.UndoableInsertEntry)

Example 2 with EntryEditor

use of org.jabref.gui.entryeditor.EntryEditor in project jabref by JabRef.

the class BasePanel method storeCurrentEdit.

/**
     * If an entry editor is showing, make sure its currently focused field stores its changes, if any.
     */
public void storeCurrentEdit() {
    if (isShowingEditor()) {
        final EntryEditor editor = (EntryEditor) splitPane.getBottomComponent();
        editor.storeCurrentEdit();
    }
}
Also used : EntryEditor(org.jabref.gui.entryeditor.EntryEditor)

Example 3 with EntryEditor

use of org.jabref.gui.entryeditor.EntryEditor 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 4 with EntryEditor

use of org.jabref.gui.entryeditor.EntryEditor in project jabref by JabRef.

the class MainTableSelectionListener method listChanged.

@Override
public void listChanged(ListEvent<BibEntry> e) {
    if (!enabled) {
        return;
    }
    EventList<BibEntry> selected = e.getSourceList();
    if (selected.isEmpty()) {
        return;
    }
    final BibEntry newSelected = selected.get(0);
    if ((panel.getMode() == BasePanelMode.SHOWING_EDITOR || panel.getMode() == BasePanelMode.WILL_SHOW_EDITOR) && panel.getCurrentEditor() != null && newSelected == panel.getCurrentEditor().getEntry()) {
        // entry already selected and currently editing it, do not steal the focus from the selected textfield
        return;
    }
    if (newSelected != null) {
        // What is the panel already showing?
        final BasePanelMode mode = panel.getMode();
        if ((mode == BasePanelMode.WILL_SHOW_EDITOR) || (mode == BasePanelMode.SHOWING_EDITOR)) {
            // An entry is currently being edited.
            EntryEditor oldEditor = panel.getCurrentEditor();
            String visName = null;
            if (oldEditor != null) {
                visName = oldEditor.getVisiblePanelName();
            }
            // Get a new editor for the entry to edit:
            EntryEditor newEditor = panel.getEntryEditor(newSelected);
            // Show the new editor unless it was already visible:
            if (!Objects.equals(newEditor, oldEditor) || (mode != BasePanelMode.SHOWING_EDITOR)) {
                if (visName != null) {
                    newEditor.setVisiblePanel(visName);
                }
                panel.showEntryEditor(newEditor);
                SwingUtilities.invokeLater(() -> table.ensureVisible(table.getSelectedRow()));
            } else {
                // if not used destroy the EntryEditor
                newEditor.setMovingToDifferentEntry();
            }
        } else {
            // Either nothing or a preview was shown. Update the preview.
            if (previewActive) {
                updatePreview(newSelected, false);
            }
        }
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) EntryEditor(org.jabref.gui.entryeditor.EntryEditor) BasePanelMode(org.jabref.gui.BasePanelMode)

Example 5 with EntryEditor

use of org.jabref.gui.entryeditor.EntryEditor in project jabref by JabRef.

the class BasePanel method updateEntryEditorIfShowing.

public void updateEntryEditorIfShowing() {
    if (mode == BasePanelMode.SHOWING_EDITOR) {
        if (currentEditor.getDisplayedBibEntryType().equals(currentEditor.getEntry().getType())) {
            currentEditor.updateSource();
        } else {
            // The entry has changed type, so we must get a new editor.
            newEntryShowing(null);
            final EntryEditor newEditor = getEntryEditor(currentEditor.getEntry());
            showEntryEditor(newEditor);
        }
    }
}
Also used : EntryEditor(org.jabref.gui.entryeditor.EntryEditor)

Aggregations

EntryEditor (org.jabref.gui.entryeditor.EntryEditor)8 BibEntry (org.jabref.model.entry.BibEntry)4 Subscribe (com.google.common.eventbus.Subscribe)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 BasePanel (org.jabref.gui.BasePanel)1 BasePanelMode (org.jabref.gui.BasePanelMode)1 DroppedFileHandler (org.jabref.gui.externalfiles.DroppedFileHandler)1 UndoableInsertEntry (org.jabref.gui.undo.UndoableInsertEntry)1 UndoableRemoveEntry (org.jabref.gui.undo.UndoableRemoveEntry)1 ParserResult (org.jabref.logic.importer.ParserResult)1 PdfContentImporter (org.jabref.logic.importer.fileformat.PdfContentImporter)1 KeyCollisionException (org.jabref.model.database.KeyCollisionException)1 EntryType (org.jabref.model.entry.EntryType)1