-
Notifications
You must be signed in to change notification settings - Fork 1.7k
HelpWindow: May interfere with UI Components while active #727 #815
HelpWindow: May interfere with UI Components while active #727 #815
Conversation
v1@vivekscl submitted v1 for review. Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/815/1/head:BRANCHNAME where |
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.
The fix itself LGTM.
@Zhiyuan-Amos Do you think we should add a regression test for this?
I'm wondering though -- usually when the event loop is blocked (e.g. you put an infinite while loop into an event handler), the whole application would not respond at all. The situation here is more peculiar though, since the UI components do seem to respond to input. e.g. The command box actually does allow us to input commands, and in fact does run them. So, I'm wondering if there is a more in-depth explanation for these particularities. (As for why I am requesting this, to quote one of the TEAMMATES principles: "We know what we are doing: For us, it is not enough to know something is broken, we should also know why it is broken. It is not enough to get something working, we should know how we got it to work.") ;-) |
According to the JavaFX documentation on The current event in this case would be the command box area since that's where the event was called from, only that area is blocked while the other events work fine as the other events are in a nested event loop. While the command box is blocked, the commands run fine and UI changes accordingly everywhere except at the command box. On the other hand, the |
Yup. That's why it remains unchecked in #551. :p The commit message can be clearer. In the 2nd paragraph, you should state what you have mentioned above - Only when you type
Yup I think we can add a test in |
Hmm? According to my testing, other UI elements do not seem to update. e.g. try adding a person while the help window is opened. The status bar should update to reflect the fact that the address book was modified, but it does not (!?) |
Yup just tested too.
|
Hint: The use of What actually happens is the use of |
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'll be eagerly awaiting the results of your investigation in the commit message :-)
27a2e9d
to
89ad167
Compare
v2@vivekscl submitted v2 for review. (📚 Archive) (📈 Interdiff between v1 and v2) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/815/2/head:BRANCHNAME where |
@Zhiyuan-Amos Would it be better if the new test that was added was changed to a private method instead? |
@vivekscl yes, you should put it in a separate method. The test should have more rigorous checks though i.e. verify that other components are updated too. Also, take a look at your commit message on GitHub, there's some minor mistakes :P Lastly:
This part seems a bit confusing. >< |
@vivekscl From your commit message:
So, the nested event loop started by |
Yes, as @Zhiyuan-Amos mentioned, the commit message (2nd and 3rd paragraphs) contains implementation details which are not important at the level of abstraction that we are looking at this issue from, and thus could be made more succinct. Also, in the commit message:
!??? |
Only those with the events
Oh I thought that might be a useful reference if needed, but maybe it isn't since the implementation details are not that important 😅. |
Yes, that's the important point: We have two event systems in the code base -- the JavaFX event system, and the Guava EventBus system. So, your commit message will need to be very clear whether it is talking about EventBus events or JavaFX events. The second piece of the puzzle (Factor B) is that the default
No, the documentation linked is not Guava docs. I think you are looking for https://github.com/google/guava/blob/master/guava/src/com/google/common/eventbus/Dispatcher.java |
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.
Changes requested.
89ad167
to
a229cae
Compare
v3@vivekscl submitted v3 for review. (📚 Archive) (📈 Interdiff between v2 and v3) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/815/3/head:BRANCHNAME where |
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.
Changes requested
e887637
to
6e67aa8
Compare
v9@vivekscl submitted v9 for review. (📚 Archive) (📈 Interdiff between v8 and v9) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/815/9/head:BRANCHNAME where |
executeCommand(DeleteCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased()); | ||
assertFalse(getStatusBarFooter().getSyncStatus().equals(StatusBarFooter.SYNC_STATUS_INITIAL)); | ||
|
||
//TODO: More tests to be added. |
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 wonder what other meaningful tests can we write though... :X
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 we can still test with other commands. For instance, after exiting the AB4, the help window still remains open. We can still test for that case.
executeCommand(HelpCommand.COMMAND_WORD);
executeCommand(ExitCommand.COMMAND_WORD);
assertHelpWindowOpen();
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.
LOL that's an interesting interaction. This doesn't seem like what we want though. Can you raise an issue for it?
Edit: It doesn't work on my side; the help window closes. But yes, you are right that there are still additional tests to be written. Can you write this test after this PR? ^^
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.
LOL that's an interesting interaction
Hahaha, I thought the same too. Wasn't sure if it was intended or bug at the time though. But yes, I'll raise an issue for it:+1:.
Can you fix that after this PR? ^^
Fix the help window issue or the additional test cases? 😅
Can you write this test after this PR? ^^
Alright 👍
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.
Take note that I edited my comment; the help window closes actually :P Can you verify it again?
Fix the help window issue or the additional test cases?
I can't think of any other test cases now apart from the interaction with ExitCommand
. If you can think of others, then you can add them in as well.
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.
executeCommand(HelpCommand.COMMAND_WORD);
executeCommand(ExitCommand.COMMAND_WORD);
assertHelpWindowOpen();
I did verify it multiple times. Moreover, the test mentioned above actually passed in my case. So maybe its an operating system thing? I'm currently running Linux.
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.
Hmm yup perhaps. I'm on MacOS. :)
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.
So it does close but only when it is not in fullscreen mode. Since my default resolution was fullscreen I kept verifying that it didn't close. But once I changed the resolution to something smaller, the help window closes as expected. Maybe you can test it and see if it's the same for MacOS? I can update the issue I just raised if its verified 😄.
I did verify it multiple times. Moreover, the test mentioned above actually passed in my case. So maybe its an operating system thing? I'm currently running Linux.
So please do ignore my previous comment 😅.
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.
//TODO: More tests to be added.
As per discussion above we could create issues for it. The comment doesn't seem to be really informative otherwise :P (and I am of the view that TODOs comments should only exist in the repo if there's a serious flaw in the codebase).
6e67aa8
to
646a8fb
Compare
v10@vivekscl submitted v10 for review. (📚 Archive) (📈 Interdiff between v9 and v10) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/815/10/head:BRANCHNAME where |
@yamgent for your approval :) |
executeCommand(SelectCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased()); | ||
assertEquals("", getCommandBox().getInput()); | ||
assertCommandBoxShowsDefaultStyle(); | ||
assertNotEquals(getResultDisplay().getText(), HelpCommand.SHOWING_HELP_MESSAGE); |
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.
Should the first argument be HelpCommand.SHOWING_HELP_MESSAGE
instead, since getResultDisplay().getText()
is the "actual" value that we are testing?
assertEquals("", getCommandBox().getInput()); | ||
assertCommandBoxShowsDefaultStyle(); | ||
assertNotEquals(getResultDisplay().getText(), HelpCommand.SHOWING_HELP_MESSAGE); | ||
assertFalse(getBrowserPanel().getLoadedUrl().equals(BrowserPanel.DEFAULT_PAGE)); |
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.
Why not use assertNotEquals()
?
// assert that the status bar too is updated correctly while the help window is open | ||
// note: the select command tested above does not update the status bar | ||
executeCommand(DeleteCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased()); | ||
assertFalse(getStatusBarFooter().getSyncStatus().equals(StatusBarFooter.SYNC_STATUS_INITIAL)); |
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.
Why not use assertNotEquals()
?
opened by typing help in the command box. For instance, the command box does not display the result message of subsequent commands. However, this does not occur when opening the help window by pressing F1 or pressing help from the help menu. This occurs due to a combination of using the default Dispatcher used by the Guava EventBus system, Dispatcher#perThreadDispatchQueue(), along with calling Stage#showAndWait(). Calling Stage#showAndWait(), starts a nested event loop to handle subsequent JavaFX events. However, the default Dispatcher used by the EventBus does not allow nested callback invocations, and instead queues them to be invoked after the current invoked callback, the MainWindow#handleShowHelpEvent() completes. As such, EventBus events are queued up in the meantime resulting in the subscribers of these events having to wait until the nested event loop is terminated (i.e. when the callback completes, after the help window is closed.) And so, the UI components will only receive these events and therefore update after the help window is closed. However, in the case of pressing F1 or pressing help from the help menu, MainWindow#handleHelp() is called immediately without posting the MainWindow#handleShowHelpEvent(). Since this event never enters the EventBus's queue, the nested event loop started by Stage#showAndWait() does not block it and subsequent EventBus events get dispatched as usual. Let's replace Stage#showAndWait() with Stage#show(), so that there will be no entering of a nested loop and hence no blockage of the Guava EventBus system. Likewise, this could be fixed by using the Dispatcher#immediate() dispatcher instead of the default dispatcher used by the Guava EventBus system. However, replacing Stage#showAndWait() with Stage#show() is more suitable in this case as it is sufficient to show the help window instead of starting a nested event loop to handle subsequent JavaFX events while waiting for the help window to be closed. JavaFX documentation for Stage: https://docs.oracle.com/javase/8/javafx/api/javafx/stage/Stage.html Code and documentation for the Guava Dispatcher: https://github.com/google/guava/blob/master/guava/src/com/google/common/eventbus/Dispatcher.java More information on the Guava EventBus system: https://github.com/google/guava/wiki/EventBusExplained
646a8fb
to
073e935
Compare
v11@vivekscl submitted v11 for review. (📚 Archive) (📈 Interdiff between v10 and v11) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/815/11/head:BRANCHNAME where |
@Zhiyuan-Amos let's merge this as we have enough reviews and we need to release level 4 for this sem soon. |
Fixes #727
On a side note, should this TODO be converted into a separate issue or is it already covered by #551?