-
Notifications
You must be signed in to change notification settings - Fork 437
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
Reflective enumeration of styleable properties #1299
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back mstrauss! A progress list of the required criteria for merging this PR into |
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 like the idea.
Could the amount of boilerplate code be reduced even further?
} | ||
|
||
private static final List<CssMetaData<? extends Styleable, ?>> classCssMetaData = CssMetaData.of(new Node() {}); |
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.
perhaps it should be <S extends Styleable> CssMetaData.of(Class<S>)
?
|
||
@Override | ||
public StyleableProperty<BlendMode> getStyleableProperty(Node node) { | ||
return (StyleableProperty<BlendMode>)node.blendModeProperty(); |
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.
these two methods can be implemented in the base class if we add a
setGetter(Function<S, StyleableProperty<V>> getter)
and also
setIsSettable(Predicate<S>)
?
This way we don't even need to declare a new class each time.
Just a thought.
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.
Yes, this can be further simplified.
private CssMetaDataCache() {} | ||
|
||
public synchronized static List<CssMetaData<? extends Styleable, ?>> getCssMetaData(Styleable node) { | ||
List<CssMetaData<? extends Styleable, ?>> list = cache.get(node.getClass()); |
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.
wouldn't this fail in the case of a skin change?
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.
Control/Skin metadata is also cached in the Control class. This particular method will only discover the styleable properties declared on the specified node, but not on its skin.
@@ -1364,7 +1364,30 @@ public final boolean isVisible() { | |||
public final BooleanProperty visibleProperty() { | |||
if (visible == null) { | |||
visible = new StyleableBooleanProperty(true) { | |||
static final CssMetaData<Node, Boolean> METADATA = new CssMetaData<>( |
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.
One problem: this idea requires creation of an instance, bc METADATA static objects get created when an instance is created.
I'd rather avoid this inversion...
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.
We're fully inflating a single instance of each particular class once to gather all metadata. After that, all further instances don't need to be fully inflated.
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.
what if this is an abstract custom Node/Control?
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.
We would never expect to encounter an instance of an abstract class. Generally, metadata reflection is done the first time we call getCssMetaData
for any particular class, which we can only do if we have an instance of that class.
The only exceptions to this are the preexisting static getClassCssMetaData
methods, which are initialized once with a throwaway instance of the class they are declared in, for example in the case of the Node
class:
private static final List<CssMetaData<? extends Styleable, ?>> classCssMetaData =
CssMetaData.of(new Node() {});
New classes should not copy this pattern of having a static getClassCssMetaData
method, so the problem shouldn't exist for these classes.
return node.nodeTransformation == null | ||
|| node.nodeTransformation.translateX == null | ||
|| node.nodeTransformation.canSetTranslateX(); | ||
} |
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 an example of a more complex isSettable()
logic.
@mstr2 This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
❗ This change is not yet ready to be integrated. |
@mstr2 This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
Progress
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1299/head:pull/1299
$ git checkout pull/1299
Update a local copy of the PR:
$ git checkout pull/1299
$ git pull https://git.openjdk.org/jfx.git pull/1299/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 1299
View PR using the GUI difftool:
$ git pr show -t 1299
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1299.diff