Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into moveFileDir
Browse files Browse the repository at this point in the history
* upstream/master:
  Fix medline tests...again (#2492)
  Make sure that unregistered event sources do not stop JabRef from shu… (#2487)
  Fix #2481: ClassCastException because of wrong cast (#2490)
  Catch NumberFormatException if context can't be parsed in groups (#2488)
  Improve CHANGELOG formatting
  Update guava from 20.0 to 21.0 and mockito-core from 2.5.5 to 2.6.2
  Fix aux duplicates (#2480)
  add update from DOI to the entryeditor sidebar (#2476)
  Remove obsolete import
  Add CHANGELOG entry (and one more link)
  Resolves #2309 JabRef freezes when importing unlinked PDF files into Database
  Update CHANGELOG.md
  Fixed bug when assigning refs to groups.
  emove html code from ACM fetcher before calling parser to prevent junk in bib file (#2473)
  • Loading branch information
Siedlerchr committed Jan 26, 2017
2 parents ea5da33 + 8c5ed80 commit a6da958
Show file tree
Hide file tree
Showing 30 changed files with 289 additions and 259 deletions.
13 changes: 8 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
## [Unreleased]

### Changed
- Added the option to update bibliographic information from DOI to the sidebar of the entryeditor. Implements [#2432](https://github.com/JabRef/jabref/issues/2432).

### Fixed
- The formatter for normalizing pages now also can treat ACM pages such as `2:1--2:33`.
Expand All @@ -20,6 +21,13 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- When pressing <kbd>Ctrl</kbd> + <kbd>F</kbd> and the searchbar is already focused the text will be selected.
- LaTeX symbols are now displayed as Unicode for the author column in the main table. "'n" and "\'{n}" are parsed correctly. Fixes [#2458](https://github.com/JabRef/jabref/issues/2458).
- If one deleted the current query it was not saved (every basepanel can have it's own query). Fixes [#2468](https://github.com/JabRef/jabref/issues/2468).
- The [ACM fetcher](https://help.jabref.org/en/ACMPortal) does no longer add HTML code to the bib-file. Fixes [#2472](https://github.com/JabRef/jabref/issues/2472).
- When [finding unlinked files](https://help.jabref.org/en/FindUnlinkedFiles), JabRef does not freeze any more. Fixes [#2309]()https://github.com/JabRef/jabref/issues/2309).
- Collapse and expand all buttons in the group assignment dialog no longer lead to a crash of JabRef.
- The aux export command line function does no longer add duplicates of references that were resolved via `crossref`. Fixes [#2475](https://github.com/JabRef/jabref/issues/2475).
- When the database is changed external, JabRef is no longer prevented from an orderly shutdown. Fixes [#2486](https://github.com/JabRef/jabref/issues/2486).
- Parsing of damaged metadata is now more robust and reports a more detailed error message. Fixes [#2477](https://github.com/JabRef/jabref/issues/2477).
- Dynamic groups with regular expression can be edited again. Fixes [#2481](https://github.com/JabRef/jabref/issues/2481).

### Removed

Expand Down Expand Up @@ -62,11 +70,6 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#











Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ dependencies {
compile 'net.java.dev.glazedlists:glazedlists_java15:1.9.1'
compile fileTree(dir: 'lib', includes: ['*.jar'])

compile 'com.google.guava:guava:20.0'
compile 'com.google.guava:guava:21.0'

compile 'commons-logging:commons-logging:1.2'

Expand All @@ -131,7 +131,7 @@ dependencies {
compile 'com.github.lgooddatepicker:LGoodDatePicker:8.3.0'

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.5.5'
testCompile 'org.mockito:mockito-core:2.6.2'
testCompile 'com.github.tomakehurst:wiremock:2.5.0'
testCompile 'org.assertj:assertj-swing-junit:3.5.0'
testCompile 'org.reflections:reflections:0.9.10'
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private void openLastEditedDatabases() {
ParserResult parsedDatabase = OpenDatabase.loadDatabase(fileName,
Globals.prefs.getImportFormatPreferences());

if (parsedDatabase.isNullResult()) {
if (parsedDatabase.isEmpty()) {
LOGGER.error(Localization.lang("Error opening file") + " '" + dbFile.getPath() + "'");
} else {
bibDatabases.add(parsedDatabase);
Expand Down
168 changes: 80 additions & 88 deletions src/main/java/net/sf/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,89 @@
public class ArgumentProcessor {

private static final Log LOGGER = LogFactory.getLog(ArgumentProcessor.class);
private final JabRefCLI cli;
private final List<ParserResult> parserResults;
private final Mode startupMode;
private boolean noGUINeeded;

public ArgumentProcessor(String[] args, Mode startupMode) {
cli = new JabRefCLI(args);
this.startupMode = startupMode;
parserResults = processArguments();
}

public enum Mode {
INITIAL_START, REMOTE_START
/**
* Will open a file (like importFile), but will also request JabRef to focus on this database
*
* @param argument See importFile.
* @return ParserResult with setToOpenTab(true)
*/
private static Optional<ParserResult> importToOpenBase(String argument) {
Optional<ParserResult> result = importFile(argument);

result.ifPresent(ParserResult::setToOpenTab);

return result;
}

private static Optional<ParserResult> importFile(String argument) {
String[] data = argument.split(",");

private final JabRefCLI cli;
String address = data[0];
Path file;
if (address.startsWith("http://") || address.startsWith("https://") || address.startsWith("ftp://")) {
// Download web resource to temporary file
try {
file = new URLDownload(address).downloadToTemporaryFile();
} catch (IOException e) {
System.err.println(Localization.lang("Problem downloading from %1", address) + e.getLocalizedMessage());
return Optional.empty();
}
} else {
if (OS.WINDOWS) {
file = Paths.get(address);
} else {
file = Paths.get(address.replace("~", System.getProperty("user.home")));
}
}

private final List<ParserResult> parserResults;
String importFormat;
if (data.length > 1) {
importFormat = data[1];
} else {
importFormat = "*";
}

private final Mode startupMode;
Optional<ParserResult> importResult = importFile(file, importFormat);
importResult.ifPresent(result -> {
OutputPrinter printer = new SystemOutputPrinter();
if (result.hasWarnings()) {
printer.showMessage(result.getErrorMessage());
}
});
return importResult;
}

private boolean noGUINeeded;
private static Optional<ParserResult> importFile(Path file, String importFormat) {
try {
if (!"*".equals(importFormat)) {
System.out.println(Localization.lang("Importing") + ": " + file);
ParserResult result = Globals.IMPORT_FORMAT_READER.importFromFile(importFormat, file);
return Optional.of(result);
} else {
// * means "guess the format":
System.out.println(Localization.lang("Importing in unknown format") + ": " + file);

ImportFormatReader.UnknownFormatImport importResult = Globals.IMPORT_FORMAT_READER.importUnknownFormat(file);

public ArgumentProcessor(String[] args, Mode startupMode) {
cli = new JabRefCLI(args);
this.startupMode = startupMode;
parserResults = processArguments();
System.out.println(Localization.lang("Format used") + ": " + importResult.format);
return Optional.of(importResult.parserResult);
}
} catch (ImportException ex) {
System.err
.println(Localization.lang("Error opening file") + " '" + file + "': " + ex.getLocalizedMessage());
return Optional.empty();
}
}

public List<ParserResult> getParserResults() {
Expand Down Expand Up @@ -244,12 +307,12 @@ private List<ParserResult> importAndOpenFiles() {
// BIB files to open. Other files, and files that could not be opened
// as bib, we try to import instead.
boolean bibExtension = aLeftOver.toLowerCase(Locale.ENGLISH).endsWith("bib");
ParserResult pr = ParserResult.getNullResult();
ParserResult pr = new ParserResult();
if (bibExtension) {
pr = OpenDatabase.loadDatabase(aLeftOver, Globals.prefs.getImportFormatPreferences());
}

if (!bibExtension || (pr.isNullResult())) {
if (!bibExtension || (pr.isEmpty())) {
// We will try to import this file. Normally we
// will import it into a new tab, but if this import has
// been initiated by another instance through the remote
Expand All @@ -259,7 +322,7 @@ private List<ParserResult> importAndOpenFiles() {
if (startupMode == Mode.INITIAL_START) {
toImport.add(aLeftOver);
} else {
loaded.add(importToOpenBase(aLeftOver).orElse(ParserResult.getNullResult()));
loaded.add(importToOpenBase(aLeftOver).orElse(new ParserResult()));
}
} else {
loaded.add(pr);
Expand Down Expand Up @@ -518,83 +581,12 @@ public boolean isBlank() {
return cli.isBlank();
}

/**
* Will open a file (like importFile), but will also request JabRef to focus on this database
*
* @param argument See importFile.
* @return ParserResult with setToOpenTab(true)
*/
private static Optional<ParserResult> importToOpenBase(String argument) {
Optional<ParserResult> result = importFile(argument);

result.ifPresent(x -> x.setToOpenTab(true));

return result;
}

private static Optional<ParserResult> importFile(String argument) {
String[] data = argument.split(",");

String address = data[0];
Path file;
if (address.startsWith("http://") || address.startsWith("https://") || address.startsWith("ftp://")) {
// Download web resource to temporary file
try {
file = new URLDownload(address).downloadToTemporaryFile();
} catch (IOException e) {
System.err.println(Localization.lang("Problem downloading from %1", address) + e.getLocalizedMessage());
return Optional.empty();
}
} else {
if (OS.WINDOWS) {
file = Paths.get(address);
} else {
file = Paths.get(address.replace("~", System.getProperty("user.home")));
}
}

String importFormat;
if (data.length > 1) {
importFormat = data[1];
} else {
importFormat = "*";
}

Optional<ParserResult> importResult = importFile(file, importFormat);
importResult.ifPresent(result -> {
OutputPrinter printer = new SystemOutputPrinter();
if (result.hasWarnings()) {
printer.showMessage(result.getErrorMessage());
}
});
return importResult;
}

private static Optional<ParserResult> importFile(Path file, String importFormat) {
try {
if (!"*".equals(importFormat)) {
System.out.println(Localization.lang("Importing") + ": " + file);
ParserResult result = Globals.IMPORT_FORMAT_READER.importFromFile(importFormat, file);
return Optional.of(result);
} else {
// * means "guess the format":
System.out.println(Localization.lang("Importing in unknown format") + ": " + file);

ImportFormatReader.UnknownFormatImport importResult;
importResult = Globals.IMPORT_FORMAT_READER.importUnknownFormat(file);

System.out.println(Localization.lang("Format used") + ": " + importResult.format);
return Optional.of(importResult.parserResult);
}
} catch (ImportException ex) {
System.err
.println(Localization.lang("Error opening file") + " '" + file + "': " + ex.getLocalizedMessage());
return Optional.empty();
}
}

public boolean shouldShutDown() {
return cli.isDisableGui() || cli.isShowVersion() || noGUINeeded;
}

public enum Mode {
INITIAL_START, REMOTE_START
}

}
15 changes: 6 additions & 9 deletions src/main/java/net/sf/jabref/gui/FindUnlinkedFilesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import javax.swing.JTree;
import javax.swing.KeyStroke;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
Expand Down Expand Up @@ -472,10 +471,10 @@ public void stateChanged(ChangeEvent e) {
} else {
message = Localization.lang("%0 files found", Integer.toString(counter));
}
SwingUtilities.invokeLater(() -> progressBarSearching.setString(message));
progressBarSearching.setString(message);
}
});
SwingUtilities.invokeLater(() -> searchFinishedHandler(rootNode));
searchFinishedHandler(rootNode);
});

}
Expand Down Expand Up @@ -532,14 +531,12 @@ entryType, checkBoxWhyIsThereNoGetSelectedStupidSwing, new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
counter++;
SwingUtilities.invokeLater(() -> {
progressBarImporting.setValue(counter);
progressBarImporting.setString(Localization.lang("%0 of %1", Integer.toString(counter),
Integer.toString(progressBarImporting.getMaximum())));
});
progressBarImporting.setValue(counter);
progressBarImporting.setString(Localization.lang("%0 of %1", Integer.toString(counter),
Integer.toString(progressBarImporting.getMaximum())));
}
}, errors);
SwingUtilities.invokeLater(() -> importFinishedHandler(errors));
importFinishedHandler(errors);
});
}

Expand Down
25 changes: 13 additions & 12 deletions src/main/java/net/sf/jabref/gui/groups/GroupAddRemoveDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.util.Enumeration;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -136,31 +135,33 @@ public void actionPerformed(ActionEvent e) {

// If "expand" is true, all nodes in the tree area expanded
// otherwise all nodes in the tree are collapsed:
private void expandAll(final JTree tree, final boolean expand) {
private void expandAll(final JTree subtree, final boolean expand) {
SwingUtilities.invokeLater(() -> {
TreeNode root = ((TreeNode) tree.getModel().getRoot());
TreeNode root = ((TreeNode) subtree.getModel().getRoot());
// walk through the tree, beginning at the root:
expandAll(tree, new TreePath(((DefaultTreeModel) tree.getModel()).getPathToRoot(root)), expand);
expandAll(subtree, new TreePath(((DefaultTreeModel) subtree.getModel()).getPathToRoot(root)), expand);
tree.requestFocusInWindow();
});
}

private void expandAll(final JTree tree, final TreePath parent, final boolean expand) {
private void expandAll(final JTree subtree, final TreePath parent, final boolean expand) {
// walk through the children:
TreeNode node = (TreeNode) parent.getLastPathComponent();
if (node.getChildCount() >= 0) {
for (Enumeration<?> e = node.children(); e.hasMoreElements();) {
TreeNode n = (TreeNode) e.nextElement();
TreePath path = parent.pathByAddingChild(n);
expandAll(tree, path, expand);
int numChildren = node.getChildCount();
if (numChildren > 0) {
for (int i = 0; i < numChildren; i++) {
TreeNode child = node.getChildAt(i);
TreePath path = parent.pathByAddingChild(child);
expandAll(subtree, path, expand);
}

}
// "expand" / "collapse" occurs from bottom to top:
if (expand) {
tree.expandPath(parent);
} else {
tree.collapsePath(parent);
if (node.getParent() != null) {
tree.collapsePath(parent);
}
}
}

Expand Down
Loading

0 comments on commit a6da958

Please sign in to comment.