Search in sources :

Example 11 with FileListTableModel

use of org.jabref.gui.filelist.FileListTableModel in project jabref by JabRef.

the class SpecialMainTableColumnsBuilder method buildFileColumn.

MainTableColumn buildFileColumn() {
    return new MainTableColumn(FieldName.FILE, Collections.singletonList(FieldName.FILE), new JLabel(IconTheme.JabRefIcon.FILE.getSmallIcon())) {

        @Override
        public Object getColumnValue(BibEntry entry) {
            // We use a FileListTableModel to parse the field content:
            FileListTableModel fileList = new FileListTableModel();
            entry.getField(FieldName.FILE).ifPresent(fileList::setContent);
            if (fileList.getRowCount() > 1) {
                return new JLabel(IconTheme.JabRefIcon.FILE_MULTIPLE.getSmallIcon());
            } else if (fileList.getRowCount() == 1) {
                Optional<ExternalFileType> type = fileList.getEntry(0).getType();
                if (type.isPresent()) {
                    return type.get().getIconLabel();
                } else {
                    return new JLabel(IconTheme.JabRefIcon.FILE.getSmallIcon());
                }
            }
            return null;
        }
    };
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) FileListTableModel(org.jabref.gui.filelist.FileListTableModel) Optional(java.util.Optional) JLabel(javax.swing.JLabel)

Example 12 with FileListTableModel

use of org.jabref.gui.filelist.FileListTableModel in project jabref by JabRef.

the class SpecialMainTableColumnsBuilder method createFileIconColumn.

/**
     * create a MainTableColumn for specific file types.
     * <p>
     * Shows the icon for the given type (or the FILE_MULTIPLE icon)
     *
     * @param externalFileTypeName the name of the externalFileType
     * @return the created MainTableColumn
     */
MainTableColumn createFileIconColumn(String externalFileTypeName) {
    return new MainTableColumn(externalFileTypeName, Collections.singletonList(FieldName.FILE), new JLabel()) {

        @Override
        public boolean isFileFilter() {
            return true;
        }

        @Override
        public String getDisplayName() {
            return externalFileTypeName;
        }

        @Override
        public Object getColumnValue(BibEntry entry) {
            boolean iconFound = false;
            JLabel iconLabel = null;
            FileListTableModel fileList = new FileListTableModel();
            entry.getField(FieldName.FILE).ifPresent(fileList::setContent);
            for (int i = 0; i < fileList.getRowCount(); i++) {
                if ((fileList.getEntry(i).getType().isPresent()) && externalFileTypeName.equalsIgnoreCase(fileList.getEntry(i).getType().get().getName())) {
                    if (iconFound) {
                        // already found another file of the desired type - show FILE_MULTIPLE Icon
                        return new JLabel(IconTheme.JabRefIcon.FILE_MULTIPLE.getSmallIcon());
                    } else {
                        iconLabel = fileList.getEntry(i).getType().get().getIconLabel();
                        iconFound = true;
                    }
                }
            }
            return iconLabel;
        }
    };
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) FileListTableModel(org.jabref.gui.filelist.FileListTableModel) JLabel(javax.swing.JLabel)

Aggregations

FileListTableModel (org.jabref.gui.filelist.FileListTableModel)12 FileListEntry (org.jabref.gui.filelist.FileListEntry)9 BibEntry (org.jabref.model.entry.BibEntry)9 Optional (java.util.Optional)5 JLabel (javax.swing.JLabel)5 ExternalFileType (org.jabref.gui.externalfiletype.ExternalFileType)5 UndoableFieldChange (org.jabref.gui.undo.UndoableFieldChange)5 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)4 List (java.util.List)3 ExternalFileMenuItem (org.jabref.gui.externalfiletype.ExternalFileMenuItem)3 UnknownExternalFileType (org.jabref.gui.externalfiletype.UnknownExternalFileType)3 IOException (java.io.IOException)2 Icon (javax.swing.Icon)2 JPopupMenu (javax.swing.JPopupMenu)2 CopyDoiUrlAction (org.jabref.gui.actions.CopyDoiUrlAction)2 ExternalFileTypeEntryEditor (org.jabref.gui.externalfiletype.ExternalFileTypeEntryEditor)2 FileListEntryEditor (org.jabref.gui.filelist.FileListEntryEditor)2 EventList (ca.odell.glazedlists.EventList)1 ListEvent (ca.odell.glazedlists.event.ListEvent)1