Skip to content

Commit

Permalink
Fixed some EDT issues (#1725)
Browse files Browse the repository at this point in the history
* Fixed some EDT issues

* More EDT issues solved, an odd bug and a few translations added

* Rebased, added CHANGELOG, and a few Swedish translations

* Fixed the comments and improved the code a bit

* Fixed one more NPE

* One more EDT issue
  • Loading branch information
oscargus authored Aug 20, 2016
1 parent a2d047e commit 61d4bd3
Show file tree
Hide file tree
Showing 34 changed files with 336 additions and 101 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Fixed NullPointerException when clicking OK without specifying a field name in set/clear/rename fields
- Fixed IndexOutOfBoundsException when trying to download a full text document without selecting an entry
- Fixed NullPointerException when trying to set a special field or mark an entry through the menu without having an open database
- Fixed NullPointerException when trying to synchronize file field with an entry without BibTeX key
- Fixed NullPointerException when importing PDFs and pressing cancel when selecting entry type
- Fixed a number of issues related to accessing the GUI from outside the EDT
- Added a few missing translation strings
- Fixed NullPointerException when opening Customize entry type dialog without an open database
- Fixed [#1257](https://github.com/JabRef/jabref/issues/1324): Preferences for the BibTeX key generator set in a version prior to 3.2 are now migrated automatically to the new version
- Fixed [#1716](https://github.com/JabRef/jabref/issues/1716): `@`-Symbols stored in BibTeX fields no longer break the database
- Fixed [#1499](https://github.com/JabRef/jabref/issues/1499): {} braces are now treated correctly in in author/editor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class FindFullTextAction extends AbstractWorker {
private BibEntry entry;
private Optional<URL> result;


public FindFullTextAction(BasePanel basePanel) {
this.basePanel = basePanel;
}
Expand All @@ -59,6 +58,7 @@ public void init() throws Throwable {
public void run() {
if (basePanel.getSelectedEntries().size() != 1) {
basePanel.output(Localization.lang("This operation requires exactly one item to be selected."));
result = Optional.empty();
} else {
entry = basePanel.getSelectedEntries().get(0);
FulltextFetchers fft = new FulltextFetchers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ public void run() {
} else {
answer = JOptionPane.showOptionDialog(panel.frame(),
Localization.lang("<HTML>Could not find file '%0'<BR>linked from entry '%1'</HTML>",
flEntry.link, aSel.getCiteKey()),
flEntry.link,
aSel.getCiteKeyOptional().orElse(Localization.lang("undefined"))),
Localization.lang("Broken link"),
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE, null, brokenLinkOptions, brokenLinkOptions[0]
Expand Down
35 changes: 22 additions & 13 deletions src/main/java/net/sf/jabref/external/WriteXMPAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;

import net.sf.jabref.Globals;
import net.sf.jabref.gui.BasePanel;
Expand Down Expand Up @@ -151,44 +152,52 @@ public void run() {
}
}

optDiag.getProgressArea().append(entry.getCiteKey() + "\n");
SwingUtilities.invokeLater(() -> optDiag.getProgressArea().append(entry.getCiteKey() + "\n"));

if (files.isEmpty()) {
skipped++;
optDiag.getProgressArea().append(" " + Localization.lang("Skipped - No PDF linked") + ".\n");
SwingUtilities.invokeLater(() -> optDiag.getProgressArea()
.append(" " + Localization.lang("Skipped - No PDF linked") + ".\n"));
} else {
for (File file : files) {
if (file.exists()) {
try {
XMPUtil.writeXMP(file, entry, database, XMPPreferences.fromPreferences(Globals.prefs));
optDiag.getProgressArea().append(" " + Localization.lang("OK") + ".\n");
SwingUtilities.invokeLater(
() -> optDiag.getProgressArea().append(" " + Localization.lang("OK") + ".\n"));
entriesChanged++;
} catch (Exception e) {
optDiag.getProgressArea().append(
" " + Localization.lang("Error while writing") + " '" + file.getPath() + "':\n");
optDiag.getProgressArea().append(" " + e.getLocalizedMessage() + "\n");
SwingUtilities.invokeLater(() -> {
optDiag.getProgressArea().append(" " + Localization.lang("Error while writing") + " '"
+ file.getPath() + "':\n");
optDiag.getProgressArea().append(" " + e.getLocalizedMessage() + "\n");
});
errors++;
}
} else {
skipped++;
optDiag.getProgressArea()
.append(" " + Localization.lang("Skipped - PDF does not exist") + ":\n");
optDiag.getProgressArea().append(" " + file.getPath() + "\n");
SwingUtilities.invokeLater(() -> {
optDiag.getProgressArea()
.append(" " + Localization.lang("Skipped - PDF does not exist") + ":\n");
optDiag.getProgressArea().append(" " + file.getPath() + "\n");
});
}
}
}

if (optDiag.isCanceled()) {
optDiag.getProgressArea().append("\n"
+ Localization.lang("Operation canceled.") +"\n");
SwingUtilities.invokeLater(
() -> optDiag.getProgressArea().append("\n" + Localization.lang("Operation canceled.") + "\n"));
break;
}
}
optDiag.getProgressArea()
SwingUtilities.invokeLater(() -> {
optDiag.getProgressArea()
.append("\n"
+ Localization.lang("Finished writing XMP for %0 file (%1 skipped, %2 errors).", String
.valueOf(entriesChanged), String.valueOf(skipped), String.valueOf(errors)));
optDiag.done();
optDiag.done();
});
}

@Override
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.nio.file.Path;
Expand Down Expand Up @@ -1804,6 +1805,19 @@ public void rebuildAllEntryEditors() {
public void markBaseChanged() {
baseChanged = true;

if (SwingUtilities.isEventDispatchThread()) {
markBasedChangedInternal();
} else {
try {
SwingUtilities.invokeAndWait(() -> markBasedChangedInternal());
} catch (InvocationTargetException | InterruptedException e) {
LOGGER.info("Problem marking database as changed", e);
}
}

}

private void markBasedChangedInternal() {
// Put an asterisk behind the filename to indicate the database has changed.
frame.setWindowTitle();
frame.updateAllTabTitles();
Expand All @@ -1813,7 +1827,6 @@ public void markBaseChanged() {
if (frame.getStatusLineText().startsWith(Localization.lang("Saved database"))) {
frame.output(" ");
}

}

public void markNonUndoableBaseChanged() {
Expand Down
34 changes: 19 additions & 15 deletions src/main/java/net/sf/jabref/gui/EntryCustomizationDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import net.sf.jabref.BibDatabaseContext;
import net.sf.jabref.Globals;
import net.sf.jabref.gui.keyboard.KeyBinding;
import net.sf.jabref.gui.util.FocusRequester;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.EntryTypes;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.CustomEntryType;
import net.sf.jabref.model.entry.EntryType;
Expand Down Expand Up @@ -84,7 +84,7 @@ public class EntryCustomizationDialog extends JDialog implements ListSelectionLi
private final Set<String> changed = new HashSet<>();

private boolean biblatexMode;
private BibDatabaseContext bibDatabaseContext;
private BibDatabaseMode bibDatabaseMode;

/**
* Creates a new instance of EntryCustomizationDialog
Expand All @@ -100,8 +100,12 @@ private void initGui() {
Container pane = getContentPane();
pane.setLayout(new BorderLayout());

bibDatabaseContext = frame.getCurrentBasePanel().getBibDatabaseContext();
biblatexMode = bibDatabaseContext.isBiblatexMode();
if (frame.getCurrentBasePanel() == null) {
bibDatabaseMode = Globals.prefs.getDefaultBibDatabaseMode();
} else {
bibDatabaseMode = frame.getCurrentBasePanel().getBibDatabaseContext().getMode();
}
biblatexMode = BibDatabaseMode.BIBLATEX.equals(bibDatabaseMode);

JPanel main = new JPanel();
JPanel buttons = new JPanel();
Expand All @@ -110,11 +114,11 @@ private void initGui() {
right.setLayout(new GridLayout(biblatexMode ? 2 : 1, 2));

List<String> entryTypes = new ArrayList<>();
for (String s : EntryTypes.getAllTypes(bibDatabaseContext.getMode())) {
for (String s : EntryTypes.getAllTypes(bibDatabaseMode)) {
entryTypes.add(s);
}

typeComp = new EntryTypeList(entryTypes, bibDatabaseContext.getMode());
typeComp = new EntryTypeList(entryTypes, bibDatabaseMode);
typeComp.addListSelectionListener(this);
typeComp.addAdditionActionListener(this);
typeComp.addDefaultActionListener(new DefaultListener());
Expand Down Expand Up @@ -204,7 +208,7 @@ public void valueChanged(ListSelectionEvent e) {
}
List<String> rl = reqLists.get(s);
if (rl == null) {
Optional<EntryType> type = EntryTypes.getType(s, bibDatabaseContext.getMode());
Optional<EntryType> type = EntryTypes.getType(s, bibDatabaseMode);
if (type.isPresent()) {
List<String> req = type.get().getRequiredFields();

Expand Down Expand Up @@ -272,13 +276,13 @@ private void applyChanges() {
if (defaulted.contains(stringListEntry.getKey())) {
// This type should be reverted to its default setup.
String nm = EntryUtil.capitalizeFirst(stringListEntry.getKey());
EntryTypes.removeType(nm, bibDatabaseContext.getMode());
EntryTypes.removeType(nm, bibDatabaseMode);

updateTypesForEntries(nm);
continue;
}

Optional<EntryType> oldType = EntryTypes.getType(stringListEntry.getKey(), bibDatabaseContext.getMode());
Optional<EntryType> oldType = EntryTypes.getType(stringListEntry.getKey(), bibDatabaseMode);
if (oldType.isPresent()) {
List<String> oldReq = oldType.get().getRequiredFieldsFlat();
List<String> oldOpt = oldType.get().getOptionalFields();
Expand All @@ -305,7 +309,7 @@ private void applyChanges() {
}

Set<Object> toRemove = new HashSet<>();
for (String o : EntryTypes.getAllTypes(bibDatabaseContext.getMode())) {
for (String o : EntryTypes.getAllTypes(bibDatabaseMode)) {
if (!types.contains(o)) {
toRemove.add(o);
}
Expand All @@ -322,10 +326,10 @@ private void applyChanges() {
}

private void typeDeletion(String name) {
Optional<EntryType> type = EntryTypes.getType(name, bibDatabaseContext.getMode());
Optional<EntryType> type = EntryTypes.getType(name, bibDatabaseMode);

if (type.isPresent() && (type.get() instanceof CustomEntryType)) {
if (! EntryTypes.getStandardType(name, bibDatabaseContext.getMode()).isPresent()) {
if (!EntryTypes.getStandardType(name, bibDatabaseMode).isPresent()) {
int reply = JOptionPane.showConfirmDialog
(frame, Localization.lang("All entries of this "
+ "type will be declared "
Expand All @@ -337,7 +341,7 @@ private void typeDeletion(String name) {
return;
}
}
EntryTypes.removeType(name, bibDatabaseContext.getMode());
EntryTypes.removeType(name, bibDatabaseMode);
updateTypesForEntries(EntryUtil.capitalizeFirst(name));
changed.remove(name);
reqLists.remove(name);
Expand Down Expand Up @@ -395,7 +399,7 @@ private void updateTypesForEntries(String typeName) {
bp.getEntryEditors().remove(typeName);

for (BibEntry entry : bp.getDatabase().getEntries()) {
EntryTypes.getType(entry.getType(), bibDatabaseContext.getMode()).ifPresent(entry::setType);
EntryTypes.getType(entry.getType(), bibDatabaseMode).ifPresent(entry::setType);
}
}

Expand All @@ -419,7 +423,7 @@ public void actionPerformed(ActionEvent e) {
}
defaulted.add(lastSelected);

Optional<EntryType> type = EntryTypes.getStandardType(lastSelected, bibDatabaseContext.getMode());
Optional<EntryType> type = EntryTypes.getStandardType(lastSelected, bibDatabaseMode);
if (type.isPresent()) {
List<String> of = type.get().getOptionalFields();
List<String> req = type.get().getRequiredFields();
Expand Down
33 changes: 23 additions & 10 deletions src/main/java/net/sf/jabref/gui/FindUnlinkedFilesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
Expand Down Expand Up @@ -533,10 +534,16 @@ private void startSearch() {
@Override
public void stateChanged(ChangeEvent e) {
counter++;
progressBarSearching.setString(counter + " files found");
String message;
if (counter == 1) {
message = Localization.lang("One file found");
} else {
message = Localization.lang("%0 files found", Integer.toString(counter));
}
SwingUtilities.invokeLater(() -> progressBarSearching.setString(message));
}
});
searchFinishedHandler(rootNode);
SwingUtilities.invokeLater(() -> searchFinishedHandler(rootNode));
});

}
Expand Down Expand Up @@ -590,15 +597,17 @@ entryType, checkBoxWhyIsThereNoGetSelectedStupidSwing, new ChangeListener() {

int counter;


@Override
public void stateChanged(ChangeEvent e) {
counter++;
progressBarImporting.setValue(counter);
progressBarImporting.setString(counter + " of " + progressBarImporting.getMaximum());
SwingUtilities.invokeLater(() -> {
progressBarImporting.setValue(counter);
progressBarImporting.setString(Localization.lang("%0 of %1", Integer.toString(counter),
Integer.toString(progressBarImporting.getMaximum())));
});
}
}, errors);
importFinishedHandler(errors);
SwingUtilities.invokeLater(() -> importFinishedHandler(errors));
});
}

Expand All @@ -609,11 +618,15 @@ public void stateChanged(ChangeEvent e) {
private void importFinishedHandler(List<String> errors) {

if ((errors != null) && !errors.isEmpty()) {

String message;
if (errors.size() == 1) {
message = Localization.lang("There was one file that could not be imported.");
} else {
message = Localization.lang("There were %0 files which could not be imported.",
Integer.toString(errors.size()));
}
JOptionPane.showMessageDialog(this,
"The import finished with warnings:\n" + "There " + (errors.size() > 1 ? "were " : "was ")
+ errors.size() + (errors.size() > 1 ? " files" : " file")
+ (errors.size() > 1 ? " which" : " that") + " could not be imported.",
Localization.lang("The import finished with warnings:") + "\n" + message,
Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/gui/GUIGlobals.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class GUIGlobals {
static final Color INACTIVE_TABBED_COLOR = Color.black; // inactive Database
public static Color editorTextColor;
public static Color validFieldBackgroundColor;
public static Color activeBackground;
public static Color activeBackgroundColor;
public static Color invalidFieldBackgroundColor;
public static final Color NULL_FIELD_COLOR = new Color(75, 130, 95); // Valid field, green.
public static final Color ACTIVE_EDITOR_COLOR = new Color(230, 230, 255);
Expand All @@ -79,7 +79,7 @@ public static JLabel getTableIcon(String fieldType) {
}

public static void updateEntryEditorColors() {
GUIGlobals.activeBackground = JabRefPreferences.getInstance().getColor(JabRefPreferences.ACTIVE_FIELD_EDITOR_BACKGROUND_COLOR);
GUIGlobals.activeBackgroundColor = JabRefPreferences.getInstance().getColor(JabRefPreferences.ACTIVE_FIELD_EDITOR_BACKGROUND_COLOR);
GUIGlobals.validFieldBackgroundColor = JabRefPreferences.getInstance().getColor(JabRefPreferences.VALID_FIELD_BACKGROUND_COLOR);
GUIGlobals.invalidFieldBackgroundColor = JabRefPreferences.getInstance().getColor(JabRefPreferences.INVALID_FIELD_BACKGROUND_COLOR);
GUIGlobals.editorTextColor = JabRefPreferences.getInstance().getColor(JabRefPreferences.FIELD_EDITOR_TEXT_COLOR);
Expand Down
Loading

0 comments on commit 61d4bd3

Please sign in to comment.