Bug #3401
clarifications for windows related methods in Widget and GuiDriver classes
100%
History
#1 Updated by Ovidiu Maxiniuc over 6 years ago
Recently I used the window()
method to pass the window id of a EditorGuiImpl
in the GuiDriver
for accessing some method that required a window to be selected. This resulted in following exception to be thrown:
java.lang.IllegalStateException: Can not change window to <N> within the same thread, if a window is already selected! at com.goldencode.p2j.ui.client.gui.driver.AbstractGuiDriver.selectWindow(AbstractGuiDriver.java:2050) at com.goldencode.p2j.ui.client.gui.driver.GuiDriver.withSelectedWindow(GuiDriver.java:773) [...]
I was mislead by the fact that the GuiDriver
methods (selectWindow()
, releaseWindow()
) parameter is named and documented as "Window ID". The problem is that the GuiDriver
requires a TopLevelWindow
to be selected which can be a Window
object or other implementation like DialogBoxWindow
. Since the DialogBoxWindow
has a parent Window
, the window
call for all its children will return that Window
instead. Passing it to selectWindow()
will cause the wrong object to be selected in driver, with a lot of problems.
The proper way to do it is to use the parentOrSelf(TopLevelWindow.class)
to get the id
to be selected in GuiDriver
. Note that in AbstractWidget
there also a method topLevelWindow()
which returns the same result if available, but it cannot always be used because if the widget is not assigned to a parent, it will fail by throwing an exception.
Replacing the window
with parentOrSelf(TopLevelWindow.class)
fixed the issue. The problem is now to find other misuses of same method that have potential to break the UI by selecting the wrong top-level window resulting in draw-related operations to silently fail (maybe with a message in log) or to completely kill the client.
#2 Updated by Ovidiu Maxiniuc over 6 years ago
Patch committed to 3394a as revision 11221.
#3 Updated by Greg Shah over 6 years ago
- % Done changed from 0 to 100
- Assignee set to Ovidiu Maxiniuc
- Status changed from New to Closed
The changes are included in task branch 3394a which has been merged to trunk as revision 11214.