Skip to content
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

Merged
merged 6 commits into from
Aug 20, 2016
Merged

Fixed some EDT issues #1725

merged 6 commits into from
Aug 20, 2016

Conversation

oscargus
Copy link
Contributor

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 or start in JabRefMain:

RepaintManager.setCurrentManager(new CheckingRepaintManager());

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 complete run in the EDT thread, but somehow I guess one wants to avoid arbitrary processing there and this at least solves the problems.

  • Manually tested changed features in running JabRef
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)

@oscargus oscargus added bug Confirmed bugs or reports that are very likely to be bugs status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers type: code-quality Issues related to code or architecture decisions labels Aug 12, 2016
@@ -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();
Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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));
Copy link
Contributor Author

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.

@oscargus oscargus added this to the v3.6 milestone Aug 12, 2016
@@ -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"))),
Copy link
Contributor Author

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
Copy link
Member

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()

@tobiasdiez
Copy link
Member

tobiasdiez commented Aug 13, 2016

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()) {
Copy link
Member

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()?

@koppor koppor removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Aug 17, 2016
@oscargus oscargus force-pushed the edtissues branch 2 times, most recently from 3a70e0b to 3f37fc9 Compare August 17, 2016 09:40
@stefan-kolb stefan-kolb self-assigned this Aug 18, 2016
@simonharrer
Copy link
Contributor

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.

@stefan-kolb stefan-kolb removed their assignment Aug 18, 2016
@oscargus
Copy link
Contributor Author

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));
Copy link
Contributor Author

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.

@oscargus oscargus force-pushed the edtissues branch 2 times, most recently from 15f99b6 to 61020da Compare August 19, 2016 16:29
@oscargus
Copy link
Contributor Author

OK, I changed some things based on the comments and improved the code in a few places.

@oscargus oscargus added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Aug 19, 2016
@oscargus
Copy link
Contributor Author

I merge this in based on the previous reviews, so we have some time to find any unexpected consequences before release.

@oscargus oscargus merged commit 61d4bd3 into JabRef:master Aug 20, 2016
@oscargus oscargus deleted the edtissues branch August 20, 2016 09:09
Siedlerchr added a commit to Siedlerchr/jabref that referenced this pull request Aug 20, 2016
* 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)
ayanai1 pushed a commit to ayanai1/jabref that referenced this pull request Sep 5, 2016
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bugs or reports that are very likely to be bugs status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers type: code-quality Issues related to code or architecture decisions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants