Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into saveFullTextFile
Browse files Browse the repository at this point in the history
* upstream/master:
  Imports
  Reuse extension util method
  Always display error message when file cannot be found
  Code Formatting
  • Loading branch information
Siedlerchr committed Mar 8, 2017
2 parents 753827c + 50f7e68 commit 960e2cd
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 170 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ private void openExternalFile() {
FileListEntry flEntry = fileListTableModel.getEntry(0);
ExternalFileMenuItem item = new ExternalFileMenuItem(frame(), entry, "", flEntry.getLink(),
flEntry.getType().get().getIcon(), bibDatabaseContext, flEntry.getType());
item.openLink();
item.doClick();
});
}

Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@
* update themselves if the change is made from somewhere else.
*/
public class EntryEditor extends JPanel implements EntryContainer {

private static final Log LOGGER = LogFactory.getLog(EntryEditor.class);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.Locale;
import java.util.Optional;

import javax.swing.Icon;
Expand All @@ -14,6 +12,7 @@
import org.jabref.gui.JabRefFrame;
import org.jabref.gui.desktop.JabRefDesktop;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;

Expand All @@ -26,7 +25,6 @@
* to process the request if the user clicks this menu item.
*/
public class ExternalFileMenuItem extends JMenuItem implements ActionListener {

private static final Log LOGGER = LogFactory.getLog(ExternalFileMenuItem.class);

private final BibEntry entry;
Expand Down Expand Up @@ -62,21 +60,16 @@ public void actionPerformed(ActionEvent e) {
}
}

public boolean openLink() {
private boolean openLink() {
frame.output(Localization.lang("External viewer called") + ".");
try {
Optional<ExternalFileType> type = fileType;
if (!this.fileType.isPresent()) {
if (this.fieldName == null) {
// We don't already know the file type, so we try to deduce it from the extension:
File file = new File(link);
// We try to check the extension for the file:
String name = file.getName();
int pos = name.indexOf('.');
String extension = (pos >= 0) && (pos < (name.length() - 1)) ? name.substring(pos + 1)
.trim().toLowerCase(Locale.ROOT) : null;
Optional<String> extension = FileUtil.getFileExtension(link);
// Now we know the extension, check if it is one we know about:
type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(extension);
type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(extension.orElse(null));
fileType = type;
} else {
JabRefDesktop.openExternalViewer(databaseContext, link, fieldName);
Expand All @@ -91,13 +84,13 @@ public boolean openLink() {
return JabRefDesktop.openExternalFileAnyFormat(databaseContext, link, type);
}

} catch (IOException e1) {
} catch (IOException ex) {
// See if we should show an error message concerning the application to open the
// link with. We check if the file type is set, and if the file type has a non-empty
// application link. If that link is referred by the error message, we can assume
// that the problem is in the open-with-application setting:
if ((fileType.isPresent()) && (!fileType.get().getOpenWithApplication().isEmpty())
&& e1.getMessage().contains(fileType.get().getOpenWithApplication())) {
&& ex.getMessage().contains(fileType.get().getOpenWithApplication())) {

JOptionPane.showMessageDialog(frame, Localization.lang("Unable to open link. "
+ "The application '%0' associated with the file type '%1' could not be called.",
Expand All @@ -106,7 +99,7 @@ public boolean openLink() {
return false;
}

LOGGER.warn("Unable to open link", e1);
LOGGER.warn("Unable to open link", ex);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
import org.apache.commons.logging.LogFactory;

public class FileListEditor extends JTable implements FieldEditor, DownloadExternalFile.DownloadCallback {

private static final Log LOGGER = LogFactory.getLog(FileListEditor.class);

private final FieldNameLabel label;
Expand Down
Loading

0 comments on commit 960e2cd

Please sign in to comment.