Search in sources :

Example 1 with BasePanelMode

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

the class MainTableSelectionListener method editSignalled.

public void editSignalled(BibEntry entry) {
    final BasePanelMode mode = panel.getMode();
    if (mode != BasePanelMode.SHOWING_EDITOR) {
        panel.showEntryEditor(panel.getEntryEditor(entry));
    }
    panel.getCurrentEditor().requestFocus();
}
Also used : BasePanelMode(org.jabref.gui.BasePanelMode)

Example 2 with BasePanelMode

use of org.jabref.gui.BasePanelMode 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 3 with BasePanelMode

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

the class MainTableSelectionListener method updatePreview.

private void updatePreview(final BibEntry toShow, final boolean changedPreview, int repeats) {
    if (workingOnPreview) {
        if (repeats > 0) {
            // We've already waited once. Give up on this selection.
            return;
        }
        Timer t = new Timer(50, actionEvent -> updatePreview(toShow, changedPreview, 1));
        t.setRepeats(false);
        t.start();
        return;
    }
    EventList<BibEntry> list = table.getSelected();
    // Check if the entry to preview is still selected:
    if ((list.size() != 1) || (list.get(0) != toShow)) {
        return;
    }
    final BasePanelMode mode = panel.getMode();
    workingOnPreview = true;
    SwingUtilities.invokeLater(() -> {
        preview.setEntry(toShow);
        // If nothing was already shown, set the preview and move the separator:
        if (changedPreview || (mode == BasePanelMode.SHOWING_NOTHING)) {
            panel.showPreview(preview);
            panel.adjustSplitter();
        }
        workingOnPreview = false;
    });
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) Timer(javax.swing.Timer) BasePanelMode(org.jabref.gui.BasePanelMode)

Aggregations

BasePanelMode (org.jabref.gui.BasePanelMode)3 BibEntry (org.jabref.model.entry.BibEntry)2 Timer (javax.swing.Timer)1 EntryEditor (org.jabref.gui.entryeditor.EntryEditor)1