use of org.jabref.gui.externalfiletype.ExternalFileMenuItem in project jabref by JabRef.
the class BasePanel method openExternalFile.
private void openExternalFile() {
JabRefExecutorService.INSTANCE.execute(() -> {
final List<BibEntry> bes = mainTable.getSelectedEntries();
if (bes.size() != 1) {
output(Localization.lang("This operation requires exactly one item to be selected."));
return;
}
final BibEntry entry = bes.get(0);
if (!entry.hasField(FieldName.FILE)) {
// no bibtex field
new SearchAndOpenFile(entry, BasePanel.this).searchAndOpen();
return;
}
FileListTableModel fileListTableModel = new FileListTableModel();
entry.getField(FieldName.FILE).ifPresent(fileListTableModel::setContent);
if (fileListTableModel.getRowCount() == 0) {
// content in BibTeX field is not readable
new SearchAndOpenFile(entry, BasePanel.this).searchAndOpen();
return;
}
FileListEntry flEntry = fileListTableModel.getEntry(0);
ExternalFileMenuItem item = new ExternalFileMenuItem(frame(), entry, "", flEntry.getLink(), flEntry.getType().get().getIcon(), bibDatabaseContext, flEntry.getType());
item.doClick();
});
}
use of org.jabref.gui.externalfiletype.ExternalFileMenuItem 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());
}
}
}
use of org.jabref.gui.externalfiletype.ExternalFileMenuItem in project jabref by JabRef.
the class MainTableSelectionListener method mouseClicked.
@Override
public void mouseClicked(MouseEvent e) {
// First find the column on which the user has clicked.
final int row = table.rowAtPoint(e.getPoint());
// A double click on an entry should open the entry's editor.
if (e.getClickCount() == 2) {
BibEntry toShow = tableRows.get(row);
editSignalled(toShow);
return;
}
final int col = table.columnAtPoint(e.getPoint());
// get the MainTableColumn which is currently visible at col
int modelIndex = table.getColumnModel().getColumn(col).getModelIndex();
MainTableColumn modelColumn = table.getMainTableColumn(modelIndex);
// action will be taken when the button is released:
if (OS.WINDOWS && (modelColumn.isIconColumn()) && (e.getButton() != MouseEvent.BUTTON1)) {
return;
}
// Check if the clicked colum is a specialfield column
if (modelColumn.isIconColumn() && (SpecialField.isSpecialField(modelColumn.getColumnName()))) {
// handle specialfield
handleSpecialFieldLeftClick(e, modelColumn.getColumnName());
} else if (modelColumn.isIconColumn()) {
// left click on icon field
Object value = table.getValueAt(row, col);
if (value == null) {
// No icon here, so we do nothing.
return;
}
final BibEntry entry = tableRows.get(row);
final List<String> fieldNames = modelColumn.getBibtexFields();
// Open it now. We do this in a thread, so the program won't freeze during the wait.
JabRefExecutorService.INSTANCE.execute(() -> {
panel.output(Localization.lang("External viewer called") + '.');
// (is relevant for combinations such as "url/doi")
for (String fieldName : fieldNames) {
// Check if field is present, if not skip this field
if (entry.hasField(fieldName)) {
String link = entry.getField(fieldName).get();
// field that can specify a list of links:
if (fieldName.equals(FieldName.FILE)) {
// We use a FileListTableModel to parse the field content:
FileListTableModel fileList = new FileListTableModel();
fileList.setContent(link);
FileListEntry flEntry = null;
// If there are one or more links of the correct type, open the first one:
if (modelColumn.isFileFilter()) {
for (int i = 0; i < fileList.getRowCount(); i++) {
if (fileList.getEntry(i).getType().toString().equals(modelColumn.getColumnName())) {
flEntry = fileList.getEntry(i);
break;
}
}
} else if (fileList.getRowCount() > 0) {
//If there are no file types specified open the first file
flEntry = fileList.getEntry(0);
}
if (flEntry != null) {
ExternalFileMenuItem item = new ExternalFileMenuItem(panel.frame(), entry, "", flEntry.getLink(), flEntry.getType().map(ExternalFileType::getIcon).orElse(null), panel.getBibDatabaseContext(), flEntry.getType());
item.doClick();
}
} else {
try {
JabRefDesktop.openExternalViewer(panel.getBibDatabaseContext(), link, fieldName);
} catch (IOException ex) {
panel.output(Localization.lang("Unable to open link."));
LOGGER.info("Unable to open link", ex);
}
}
// only open the first link
break;
}
}
});
} else if (modelColumn.getBibtexFields().contains(FieldName.CROSSREF)) {
// Clicking on crossref column
tableRows.get(row).getField(FieldName.CROSSREF).ifPresent(crossref -> panel.getDatabase().getEntryByKey(crossref).ifPresent(entry -> panel.highlightEntry(entry)));
}
panel.frame().updateEnabledState();
}
Aggregations