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