-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed some EDT issues #1725
Fixed some EDT issues #1725
Conversation
@@ -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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not related to EDT, but still solves a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably better to initialize in the constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it needs to be reset. If not, if you run it once and then try to run it with multiple entries selected, update will still be called and then result is not empty.
@@ -64,7 +64,7 @@ public boolean accept(File f) { | |||
PdfImporter pi = new PdfImporter(JabRefGUI.getMainFrame(), JabRefGUI.getMainFrame().getCurrentBasePanel(), JabRefGUI.getMainFrame().getCurrentBasePanel().getMainTable(), -1); | |||
ImportPdfFilesResult res = pi.importPdfFiles(Collections.singletonList(pdfFile.toString())); | |||
if (res.getEntries().size() == 1) { | |||
return Optional.of(res.getEntries().get(0)); | |||
return Optional.ofNullable(res.getEntries().get(0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug fix so that one can click "Cancel" instead of selecting an entry type and still not get an NPE.
@@ -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"))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NPE when no cite key is set...
@@ -532,10 +533,12 @@ private void startSearch() { | |||
@Override | |||
public void stateChanged(ChangeEvent e) { | |||
counter++; | |||
progressBarSearching.setString(counter + " files found"); | |||
SwingUtilities.invokeLater(() -> progressBarSearching |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is hard to read. Maybe determine the localized string before calling SwingUtil.invokeLater()
A few remarks, but in general looks good to me. But I have no experience with this swing threading stuff, so it would be good if somebody else also has a look at the code. |
@@ -947,7 +947,11 @@ public void updateAllContentSelectors() { | |||
@Subscribe | |||
public void listen(FieldChangedEvent fieldChangedEvent) { | |||
String newValue = fieldChangedEvent.getNewValue() == null ? "" : fieldChangedEvent.getNewValue(); | |||
setField(fieldChangedEvent.getFieldName(), newValue); | |||
if (SwingUtilities.isEventDispatchThread()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that this if
statement is necessary and one cannot just call invokeLater()
?
3a70e0b
to
3f37fc9
Compare
For a hack, this is ok. I would prefer that a SwingWorker is used which can send updates of its progress. The AbstractWorker with its init/run/update methods is somewhat legacy which will not work with JavaFX at all. But the SwingWorker can be easily ported to the JavaFX equivalent, the stuff behind the AbstractWorker which is based on the spin library cannot. So I would recommend to invest the effort in slowly migrating to SwingWorker and then to JavaFx. |
Thanks for looking at it @simonharrer. I take it as merge (subject to the comments) and look at SwingWorker eventually. Much more work to restructure all AbstractWorker but still worth getting rid of the issues fixed here. I'll have a look at the other comments later tonight. |
@@ -64,7 +64,7 @@ public boolean accept(File f) { | |||
PdfImporter pi = new PdfImporter(JabRefGUI.getMainFrame(), JabRefGUI.getMainFrame().getCurrentBasePanel(), JabRefGUI.getMainFrame().getCurrentBasePanel().getMainTable(), -1); | |||
ImportPdfFilesResult res = pi.importPdfFiles(Collections.singletonList(pdfFile.toString())); | |||
if (res.getEntries().size() == 1) { | |||
return Optional.of(res.getEntries().get(0)); | |||
return Optional.ofNullable(res.getEntries().get(0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got an NPE here at least. I do not remember the details (I think pressing cancel when asked about entry type) and I think I tested it after changing it. although I'm hindsight it looks more likely that the list is null than the list entry and that fixing it at the source may be better. emptyList() will break it as a null is better than index out of bounds. I'll have a new look later tonight.
15f99b6
to
61020da
Compare
OK, I changed some things based on the comments and improved the code in a few places. |
I merge this in based on the previous reviews, so we have some time to find any unexpected consequences before release. |
* master: Made output of MetaData.getEncoding() Optional (JabRef#1790) Some improvements to LayoutFormatterPreferences (JabRef#1793) Updated WireMock to 2.1.10 (JabRef#1792) Fixed some EDT issues (JabRef#1725) Remove commented InternalBibtexFields.getPreferredFieldLength() Readd package comments as class comments Remove GPL headers Moved preference constants to JabRefPreferences and renamed (JabRef#1786) Fix arxiv fetcher not working correctly (JabRef#1780)
* 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
I looked into EDT bugs and found a few. Quite often they related to
AbstractWorker
it turned out.If someone wants to find out more, add the following first in
main
orstart
inJabRefMain
:then it is just to work with JabRef until an exception happens.
The most prominent issue solved was on saving where the UI is frozen during save, but not from the EDT. It is possible that some of the
AbstractWorker
issues are better to solve by running the completerun
in the EDT thread, but somehow I guess one wants to avoid arbitrary processing there and this at least solves the problems.