Search in sources :

Example 1 with CopyDoiUrlAction

use of org.jabref.gui.actions.CopyDoiUrlAction in project jabref by JabRef.

the class EditorMenus method getDOIMenu.

public static List<MenuItem> getDOIMenu(TextArea textArea) {
    AbstractAction copyDoiUrlAction = new CopyDoiUrlAction(textArea);
    MenuItem copyDoiUrlMenuItem = new MenuItem((String) copyDoiUrlAction.getValue(Action.NAME));
    copyDoiUrlMenuItem.setOnAction(event -> copyDoiUrlAction.actionPerformed(null));
    List<MenuItem> menuItems = new ArrayList<>();
    menuItems.add(copyDoiUrlMenuItem);
    menuItems.add(new SeparatorMenuItem());
    return menuItems;
}
Also used : ArrayList(java.util.ArrayList) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) AbstractAction(javax.swing.AbstractAction) CopyDoiUrlAction(org.jabref.gui.actions.CopyDoiUrlAction)

Example 2 with CopyDoiUrlAction

use of org.jabref.gui.actions.CopyDoiUrlAction 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)

Aggregations

CopyDoiUrlAction (org.jabref.gui.actions.CopyDoiUrlAction)2 ArrayList (java.util.ArrayList)1 MenuItem (javafx.scene.control.MenuItem)1 SeparatorMenuItem (javafx.scene.control.SeparatorMenuItem)1 AbstractAction (javax.swing.AbstractAction)1 Icon (javax.swing.Icon)1 JLabel (javax.swing.JLabel)1 JPopupMenu (javax.swing.JPopupMenu)1 ExternalFileMenuItem (org.jabref.gui.externalfiletype.ExternalFileMenuItem)1 FileListEntry (org.jabref.gui.filelist.FileListEntry)1 FileListTableModel (org.jabref.gui.filelist.FileListTableModel)1 BibEntry (org.jabref.model.entry.BibEntry)1