Search in sources :

Example 51 with BibEntry

use of org.jabref.model.entry.BibEntry in project jabref by JabRef.

the class MainTableSelectionListener method showIconRightClickMenu.

/**
     * Process popup trigger events occurring on an icon cell in the table. Show a menu where the user can choose which
     * external resource to open for the entry. If no relevant external resources exist, let the normal popup trigger
     * handler do its thing instead.
     *
     * @param e The mouse event defining this popup trigger.
     * @param row The row where the event occurred.
     * @param column the MainTableColumn associated with this table cell.
     */
private void showIconRightClickMenu(MouseEvent e, int row, MainTableColumn column) {
    BibEntry entry = tableRows.get(row);
    JPopupMenu menu = new JPopupMenu();
    boolean showDefaultPopup = true;
    // field that can specify a list of links:
    if (!column.getBibtexFields().isEmpty()) {
        for (String field : column.getBibtexFields()) {
            if (FieldName.FILE.equals(field)) {
                // We use a FileListTableModel to parse the field content:
                FileListTableModel fileList = new FileListTableModel();
                entry.getField(field).ifPresent(fileList::setContent);
                for (int i = 0; i < fileList.getRowCount(); i++) {
                    FileListEntry flEntry = fileList.getEntry(i);
                    if (column.isFileFilter() && (!flEntry.getType().get().getName().equalsIgnoreCase(column.getColumnName()))) {
                        continue;
                    }
                    String description = flEntry.getDescription();
                    if ((description == null) || (description.trim().isEmpty())) {
                        description = flEntry.getLink();
                    }
                    menu.add(new ExternalFileMenuItem(panel.frame(), entry, description, flEntry.getLink(), flEntry.getType().get().getIcon(), panel.getBibDatabaseContext(), flEntry.getType()));
                    showDefaultPopup = false;
                }
            } else {
                if (SpecialField.isSpecialField(column.getColumnName())) {
                    // full pop should be shown as left click already shows short popup
                    showDefaultPopup = true;
                } else {
                    Optional<String> content = entry.getField(field);
                    if (content.isPresent()) {
                        Icon icon;
                        JLabel iconLabel = GUIGlobals.getTableIcon(field);
                        if (iconLabel == null) {
                            icon = IconTheme.JabRefIcon.FILE.getIcon();
                        } else {
                            icon = iconLabel.getIcon();
                        }
                        menu.add(new ExternalFileMenuItem(panel.frame(), entry, content.get(), content.get(), icon, panel.getBibDatabaseContext(), field));
                        if (field.equals(FieldName.DOI)) {
                            menu.add(new CopyDoiUrlAction(content.get()));
                        }
                        showDefaultPopup = false;
                    }
                }
            }
        }
        if (showDefaultPopup) {
            processPopupTrigger(e, row);
        } else {
            menu.show(table, e.getX(), e.getY());
        }
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) FileListTableModel(org.jabref.gui.filelist.FileListTableModel) ExternalFileMenuItem(org.jabref.gui.externalfiletype.ExternalFileMenuItem) FileListEntry(org.jabref.gui.filelist.FileListEntry) JLabel(javax.swing.JLabel) JPopupMenu(javax.swing.JPopupMenu) CopyDoiUrlAction(org.jabref.gui.actions.CopyDoiUrlAction) Icon(javax.swing.Icon)

Example 52 with BibEntry

use of org.jabref.model.entry.BibEntry in project jabref by JabRef.

the class MergeEntriesDialog method init.

/**
     * Sets up the dialog
     *
     * @param selected Selected BibtexEntries
     */
private void init(List<BibEntry> selected) {
    // Check if there are two entries selected
    if (selected.size() != 2) {
        // None selected. Inform the user to select entries first.
        JOptionPane.showMessageDialog(panel.frame(), Localization.lang("You have to choose exactly two entries to merge."), MERGE_ENTRIES, JOptionPane.INFORMATION_MESSAGE);
        this.dispose();
        return;
    }
    // Store the two entries
    BibEntry one = selected.get(0);
    BibEntry two = selected.get(1);
    MergeEntries mergeEntries = new MergeEntries(one, two, panel.getBibDatabaseContext().getMode());
    // Create undo-compound
    NamedCompound ce = new NamedCompound(MERGE_ENTRIES);
    FormLayout layout = new FormLayout("fill:700px:grow", "fill:400px:grow, 4px, p, 5px, p");
    this.setLayout(layout);
    this.add(mergeEntries.getMergeEntryPanel(), cc.xy(1, 1));
    this.add(new JSeparator(), cc.xy(1, 3));
    // Create buttons
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    JButton cancel = new JButton(Localization.lang("Cancel"));
    cancel.setActionCommand("cancel");
    cancel.addActionListener(e -> {
        panel.output(Localization.lang("Canceled merging entries"));
        dispose();
    });
    JButton replaceentries = new JButton(MERGE_ENTRIES);
    replaceentries.setActionCommand("replace");
    replaceentries.addActionListener(e -> {
        BibEntry mergedEntry = mergeEntries.getMergeEntry();
        panel.insertEntry(mergedEntry);
        ce.addEdit(new UndoableInsertEntry(panel.getDatabase(), mergedEntry, panel));
        ce.addEdit(new UndoableRemoveEntry(panel.getDatabase(), one, panel));
        panel.getDatabase().removeEntry(one);
        ce.addEdit(new UndoableRemoveEntry(panel.getDatabase(), two, panel));
        panel.getDatabase().removeEntry(two);
        ce.end();
        panel.getUndoManager().addEdit(ce);
        panel.output(Localization.lang("Merged entries"));
        dispose();
    });
    bb.addButton(new JButton[] { replaceentries, cancel });
    this.add(bb.getPanel(), cc.xy(1, 5));
    // Add some margin around the layout
    layout.appendRow(RowSpec.decode(MARGIN));
    layout.appendColumn(ColumnSpec.decode(MARGIN));
    layout.insertRow(1, RowSpec.decode(MARGIN));
    layout.insertColumn(1, ColumnSpec.decode(MARGIN));
    WindowLocation pw = new WindowLocation(this, JabRefPreferences.MERGEENTRIES_POS_X, JabRefPreferences.MERGEENTRIES_POS_Y, JabRefPreferences.MERGEENTRIES_SIZE_X, JabRefPreferences.MERGEENTRIES_SIZE_Y);
    pw.displayWindowAtStoredLocation();
    // Show what we've got
    setVisible(true);
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) BibEntry(org.jabref.model.entry.BibEntry) NamedCompound(org.jabref.gui.undo.NamedCompound) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) JButton(javax.swing.JButton) UndoableRemoveEntry(org.jabref.gui.undo.UndoableRemoveEntry) WindowLocation(org.jabref.gui.util.WindowLocation) JSeparator(javax.swing.JSeparator) UndoableInsertEntry(org.jabref.gui.undo.UndoableInsertEntry)

Example 53 with BibEntry

use of org.jabref.model.entry.BibEntry in project jabref by JabRef.

the class SpecialMainTableColumnsBuilder method createIconColumn.

/**
     * Creates a MainTableColumn which shows an icon instead textual content
     *
     * @param columnName the name of the column
     * @param fields     the entry fields which should be shown
     * @return the crated MainTableColumn
     */
MainTableColumn createIconColumn(String columnName, List<String> fields, JLabel iconLabel) {
    return new MainTableColumn(columnName, fields, iconLabel) {

        @Override
        public Object getColumnValue(BibEntry entry) {
            JLabel iconLabel = null;
            boolean iconFound = false;
            // check for each field whether content is available
            for (String field : fields) {
                if (entry.hasField(field)) {
                    if (iconFound) {
                        return new JLabel(IconTheme.JabRefIcon.FILE_MULTIPLE.getSmallIcon());
                    } else {
                        iconLabel = GUIGlobals.getTableIcon(field);
                        iconFound = true;
                    }
                }
            }
            return iconLabel;
        }
    };
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) JLabel(javax.swing.JLabel)

Example 54 with BibEntry

use of org.jabref.model.entry.BibEntry 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 55 with BibEntry

use of org.jabref.model.entry.BibEntry in project jabref by JabRef.

the class PushToApplicationAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    panel = frame.getCurrentBasePanel();
    // Check if a BasePanel exists:
    if (panel == null) {
        return;
    }
    // Check if any entries are selected:
    entries = panel.getSelectedEntries();
    if (entries.isEmpty()) {
        JOptionPane.showMessageDialog(frame, Localization.lang("This operation requires one or more entries to be selected."), (String) getValue(Action.NAME), JOptionPane.ERROR_MESSAGE);
        return;
    }
    // If required, check that all entries have BibTeX keys defined:
    if (operation.requiresBibtexKeys()) {
        for (BibEntry entry : entries) {
            if (!(entry.getCiteKeyOptional().isPresent()) || entry.getCiteKeyOptional().get().trim().isEmpty()) {
                JOptionPane.showMessageDialog(frame, Localization.lang("This operation requires all selected entries to have BibTeX keys defined."), (String) getValue(Action.NAME), JOptionPane.ERROR_MESSAGE);
                return;
            }
        }
    }
    // All set, call the operation in a new thread:
    JabRefExecutorService.INSTANCE.execute(this);
}
Also used : BibEntry(org.jabref.model.entry.BibEntry)

Aggregations

BibEntry (org.jabref.model.entry.BibEntry)716 Test (org.junit.Test)466 ParserResult (org.jabref.logic.importer.ParserResult)131 StringReader (java.io.StringReader)107 ArrayList (java.util.ArrayList)75 BibDatabase (org.jabref.model.database.BibDatabase)63 Path (java.nio.file.Path)52 IOException (java.io.IOException)43 HashMap (java.util.HashMap)37 Before (org.junit.Before)36 NamedCompound (org.jabref.gui.undo.NamedCompound)30 BibtexParser (org.jabref.logic.importer.fileformat.BibtexParser)28 BibtexString (org.jabref.model.entry.BibtexString)28 List (java.util.List)23 File (java.io.File)21 StringWriter (java.io.StringWriter)19 Optional (java.util.Optional)19 BasePanel (org.jabref.gui.BasePanel)19 FieldChange (org.jabref.model.FieldChange)18 InputStream (java.io.InputStream)16