-
Notifications
You must be signed in to change notification settings - Fork 6.1k
JDK-8353755 : Add a helper method to Util - findComponent() #27944
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
base: master
Are you sure you want to change the base?
Conversation
|
👋 Welcome back honkar! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
|
@honkar-jdk The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
| /** | ||
| * Find a component based on predicate. | ||
| * Always run this method on the EDT thread | ||
| */ |
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 documentation could then explain the parameters, don't you think?
Always run this method on the EDT thread
The utility method could ensure this automatically. This public method will be a wrapper around a private implementation, the implementation will run directly or on EDT using invokeOnEDT which already exists in the Util class.
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.
There are some tests where EDT calls are interleaved between calls to robot (non-EDT) (e.g bug4759934.java - findCancelButton()) and few other tests (e.g FileSizeCheck.java - findDetailsButton() and findTable() that are within upper level method which is called on EDT). Is it better to leave it as-is for flexibility rather than add a wrapper?
If a wrapper is added we might need to check if it is already on EDT thread or not as below:
if (isEventDispatchThread()) {
return _findComponent(container, predicate);
} else {
return Util.invokeOnEDT(() -> _findComponent(container, predicate));
}
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.
If a wrapper is added we might need to check if it is already on EDT thread or not as below:
This is what I said: “the implementation will run directly or on EDT.” So if it's already on EDT, call directly; it it's not, use invokeOnEDT.
The utility method can then be used in all the contexts without thinking. (The implementation, if you choose this way, should rather be findComponentImpl rather than prefixed with an underscore.)
Likely, one still needs to call findComponent on EDT because any other operations on the component need to be on EDT. In this case, findComponent could throw an exception if it's called not on EDT.
These things will ensure the method can work correctly.
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.
Existing
Util.findSubComponent()finds component by class name
To eliminate code duplication, the existing findSubComponent should use the new findComponent which is more flexible. Just pass parent.getClass().getName().contains(className) as the predicate to the new method.
| JButton cancel = Util.invokeOnEDT(() -> findCancelButton(jfc)); | ||
| cancel.doClick(); |
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.
doClick should also be called on EDT.
| private static AbstractButton findDetailsButton(final Container container) { | ||
| Component result = findComponent(container, | ||
| c -> c instanceof JToggleButton button | ||
| && "Details".equals(button.getToolTipText())); | ||
| Component result = Util.findComponent(container, | ||
| c -> c instanceof JToggleButton button | ||
| && "Details".equals(button.getToolTipText())); | ||
| return (AbstractButton) result; | ||
| } |
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.
In this case, I would leave the wrapped predicate parameter as is; otherwise, the lines become too long. This is why I chose to use the 8-column indentation for the second parameter rather than aligning it with the opening parenthesis.
findComponent(final Container container, final Predicate<Component> predicate)is a useful utility method and thus added tojavax/swing/regtesthelpers/Util.javainstead of having redundant code in tests. It can be used to find a component by label name.PS: Existing
Util.findSubComponent()finds component by class name butfindComponent()can be used to search for a particular component by label name/title when there are multiple subcomponents of same type by applying a predicate logic.Progress
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/27944/head:pull/27944$ git checkout pull/27944Update a local copy of the PR:
$ git checkout pull/27944$ git pull https://git.openjdk.org/jdk.git pull/27944/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 27944View PR using the GUI difftool:
$ git pr show -t 27944Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/27944.diff
Using Webrev
Link to Webrev Comment