-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Please Create JavaFX property annotation #521
Comments
👤 [email protected] 🕗 Feb 14, 2013 at 03:20 UTC Please create @ FXProperty annotation that generates the JavaFX property methods: e.g. @ FXProperty to Generatepublic Customer getCustomer() { public void setCustomer(Customer c) { public ObjectProperty<Customer> customerProperty() { http://docs.oracle.com/javafx/2/binding/jfxpub-binding.htm Thank you for Lombok project, I really appreaciate it. |
👤 [email protected] 🕗 Feb 27, 2013 at 14:50 UTC A good reference that describes possible implementations can be found at: https://wikis.oracle.com/display/OpenJDK/JavaFX+Property+Architecture See section "JavaFX Property Cook Book" According to this document (see near the end of the introduction) Oracle used Lombok during initial JavaFX 2 development. Probably that code is still somewhere around and can be open-sourced? |
👤 francescov235 🕗 Oct 29, 2013 at 05:50 UTC javafx properties are really verbose |
👤 [email protected] 🕗 Oct 29, 2013 at 06:06 UTC Yes, Once you are used to lombok, they do make the code very verbose |
👤 [email protected] 🕗 Jun 27, 2015 at 22:26 UTC I guess not many people are interested in this feature but if you guys could point me in the right direction I would gladly implement it and share the outcome. |
End of migration |
this would be really cool. |
Duplicate of #1222. |
Here the working link to JavaFX Property Architecture document with the Java Property Cook Book chapter inside: https://wiki.openjdk.java.net/display/OpenJFX/JavaFX+Property+Architecture |
IntelliJ IDEA had implemented this... This would be really cool in Lombok. |
@marlontrujillo1080 I couldn't find it in IDEA. Could you provide more info about this feature? |
Is not an annotations, it is a refactor. You just create the property, e.g.:
and go to > refactor > create Getters and Setters... IDEA detects the property and create the getters and setters properly... |
See the duplicate issue. I have a mostly-working implementation for Eclipse, but until I see PR requests having more discussion I don't want to waste my time. |
Hello, I would be pleased, if you could make this feature ready :-) Here is one example for a Property and the three posible outcomes. One: @getter @Setter @FxBean Would become: public final LongProperty idProperty() { Two: @getter @FxBean Would become: public final ReadOnlyLongProperty idProperty() { Three: @Setter @FxBean Would become: public final WritableLongValue idProperty() { This three cases have to be implemented for the folowing Property-Types: BooleanProperty For more information about FX-Properties you could read this: |
any news on this one? |
@chrismaster |
I would also like to have this feature in Lombok. Getters and setters clutter code a lot. |
This would be very useful and totally in the spirit of Lombok. |
It's a shame this issue hasn't seen more support. GUIs in JavaFX have tons of properties, and getters and setters clutter up a lot of the screen. It's a perfect place to use lombok. |
I like this idea and think it also fulfils the lombok feature requirements. There are no new or special things required to implement this one, should be quite easy. Question: The linked JavaFx documentation does not mention |
Yes it does...There's a whole paragraphe named "Properties Can Be Read-Only":
Property is writeable by default so there is no Writeable*Property. |
@ogerardin Yeah, missed that small section and I obviously meant |
Here's a few ideas.
So I would be in favor of a unique annotation Example 1: @FxProperty
private ObjectProperty<U> thing = new SimpleObjectProperty<>();
// Generates
public ObjectProperty<U> thingProperty() {
return thing;
}
public final U getThing() {
return thing.get();
}
public final void setThing(U thing) {
this.thing.set(thing);
} Example 2: @FXProperty(readOnly = true)
private ObjectProperty<U> thing = new SimpleObjectProperty<>();
// Generates
public ReadOnlyObjectProperty<U> thingProperty() {
return thing;
}
public final U getThing() {
return thing.get();
}
private final void setThing(U thing) {
this.thing.set(thing);
} As outlined by @matthias24 , all JavaFX native property types types should be handled, not just ObjectProperty. And of course if one of the methods to generate already exists, Lombok should silently ignore it, as it usually does. |
we need this |
I still have no idea how to handle custom implementations, |
Nothing really different from other property types. Getter/setter should return/take |
Here a more convenience example of a read only property. Without possibility for cast to writeable property. private ReadOnlyStringWrapper text = new ReadOnlyStringWrapper();
public ReadOnlyStringProperty textProperty() { return text.getReadOnlyProperty(); }
public String getText() { return text.get(); }
public void setText(String text) { this.text.set(text); } |
The actual type of the property is an implementation decision, so I don't think Lombok should be concerned about that. To quote the reference document "While the implementation can take pains to ensure that the ReadOnlyProperty returned from the property getter is actually a different object from the property object used for storage, this is an implementation decision and not required by the pattern." |
In theory it is possible but it is usually not worth the effort and very error prone. Basically lombok can only work with the code in a single file. It should work if you assign your own property to a field that uses a predefined JavaFx type e.g. |
Fair enough! |
Wow, any more progress on this? This would save me soooooo much time. |
@Rawi01 what's the status on this ? |
@bigjane have you tried my branch/version? Is there anything that you miss? |
@Rawi01 I think he's waiting for the functionality to be merged into the main project. |
@Rawi01 Did you create a PR for this? I couldn't find any. |
@Rawi01 will this be merged in anytime soon? |
I am waiting still for this feature. Would be awesome. |
@Rawi01 Your branch is not compatible with master anymore. Can you update and create a PR, please. |
@rzwitserloot suggested to use normal java types instead of the JavaFX specific types for the fields (e.g. |
@Rawi01 If I have to decide between the two options, the |
What if we just accept either? If you write To cater to the 'custom property' case as @falkoschumann mentioned (comment above this one), you'd have to just assign the custom property straight to the field. This doesn't seem like a big deal: The CheckBox code as linked is 'lazy-capable', in that you don't get an actual property until you either ask for the property, or call the setter. Just invoking the getters returns That part seems well beyond what lombok should try to do here, but if you accept letting the lazy-init part go, the feature as @Rawi01 built it would give you the room to hand-write it. NB: We could let you write the xProperty() method yourself, but then you really also have to write the getter yourself to provide the lazy aspect, at which point you've... pretty much written it all by hand already. |
@rzwitserloot @Rawi01 |
I'd like to clarify the property specs, conventions, and usage in JavaFX to help tailor the Lombok solution. A regular JavaFX property, with its methods, is usually defined in the following way, using private final IntegerProperty amount = new SimpleIntegerProperty();
public final IntegerProperty amount() { return amount; }
public final int getAmount() { return amount.get(); }
public final void setAmount(int value) { amount.set(value); } However, There are quite a few knobs that can be turned here. Eventually it depends on how much configuration Lombok wants to allow. One of the problems with a single VisibilityUsually the field itself is FinalityThe property itself tends to be final like any initialized field, however, in many cases it is initialized lazily (see the Lazyness section below). LazynessAs linked above for the private IntegerProperty amount;
public final IntegerProperty amount() {
if (amount == null) {
amount = new SimpleIntegerProperty();
}
return amount;
}
public final int getAmount() { return amount().get(); }
public final void setAmount(int value) { amount().set(value); } Notice that here the getter and setter call the public final int getAmount() {
return amount == null ? 2 : amount.get();
} where ReadOnlyA private final ReadOnlyIntegerWrapper amount = new ReadOnlyIntegerWrapper();
public final ReadOnlyIntegerProperty amount() { return amount.getReadOnlyProperty(); } // special method of the read only wrapper
public final int getAmount() { return amount.get(); }
final void setAmount(int value) { amount.set(value); } But because in the initial example I used private final IntegerProperty amount = new SimpleIntegerProperty();
public final ReadOnlyIntegerProperty amount() { return amount; } // return the property as read-only
public final int getAmount() { return amount.get(); }
final void setAmount(int value) { amount.set(value); } The implementation updates it with the non-public ( Anonymous subclassingAs in the linked private final IntegerProperty amount = new SimpleIntegerProperty() {
@Override
protected void invalidated() {
// ...
}
} where the implementation is an anonymous subclass of whatever base class was chosen. This can applied to read-only properties too. Lazy initialization is, again, orthogonal. ConclusionsOverall, there is a lot of play here because 1 property plays the role of @FXProperty
IntegerProperty amount; // will generate a SimpleIntegerProperty()
@FXProperty
ReadOnlyIntegerWrapper amount; // will generate a ReadOnlyIntegerWrapper()
@FXProperty
ObjectProperty<Integer> amount // will generate a SimpleObjectProperty<Integer>() and if the user want a custom subtype to override In my opinion, the visibility and finality of the field should be handled by Lazyness can be configured with a boolean Read-only can also be done with a boolean parameter. It will return a I don't know how to support the There are still the collections properties, but let's advance here first. |
@nlisker thanks much for that rundown! Unfortunately I now see no way forward. If laziness is somehow a virtue (which really strikes me as very odd. "To save memory"? What?? We're talking about... the equivalent of peeing in the atlantic. Yeah, the water level will go up. But not by an amount that you'll ever notice, worrying about that is utterly off the walls nuts. Right? Am I missing something?) If it's a mass delusion by the javafx community then that means that part of 'selling' this lombok feature involves telling people they've been doing it all wrong for all these years. We're not going to do that, so that would prevent this feature from happening. If there's a good reason then we definitely also need to do it, but the lazy nature of getter cannot be applied here - the code we generate for that is very complicated. Your code snippets flat out fail here - they are not at all multicore capable. If you start invoking
A subclass of a thing named Excuse me while I go gather up the pieces, my brain just exploded. It's clear I have absolutely no idea whatsoever how this stuff even works. I therefore would not be able to maintain this feature, which would mean I can't accept this feature. I need to 'grok' this stuff first, and between this and the lazy stuff, it's clear that I don't. I'm not sure how I can fix that. I'm not so sure this feature has a path forward. However, given that @Rawi01 already invested quite a bit of time into it, if you think this should be in lombok and you see a way forward that will be relatively easily understood by your average javafx programmer, I'm willing to give it a place in the |
The lazy pattern is used throughout the JavaFX codebase. Whether users use it themselves or not, I don't know, so I can't tell you if that's a selling point. I personally don't bother because I don't have a lot of properties in my classes. In JavaFX there can be hundreds of thousands of objects with dozens of properties each ("everything is a About the multicore, I think it's irrelevant. JavaFX is a GUI library, and GUI's are single threaded. JavaFX provides special tools for doing tasks such as background loading while updating the relevant properties. There has been no issue with lazy properties initialization and these multithread tools (like
Yes, does it matter for the implementation of this issue?
Well, I'm just looking at the votes on this issue and its dupes, so it looks like, in general, people want this in Lombok. What is "easily understood" by the average developer depends on the complexity of the feature. If we add 10 configuration parameters it will be understood by less developers, if we add just 2, it will be understood by more, so it's a balance. In terms of the code I wrote, it's rather standard. Maybe what's not fair here is that we are cramming 3 annotations into 1 and then saying "it's too complicated". If we go with the path of 1 annotation then we need to accept that complexity. At the minimum, those 2 configuration parameters that I mentioned are: 1 parameter that sets the visibility for all the methods, and 1 that set the finality for all of them. You can claim that the rest is "nice to have" but not needed and anyone that needs it will write their own code. I don't have statistics to show how many people use lazy initialization or read-only properties, or need different visibilities or finalities. Again, these are possible knobs. My writeup was to explain the scope and moving parts in JavaFX properties. It shows what's the maximum and minimum this feature can support, and how the features interact with each other. I saw that you wrote
and that's just wrong, the finality of the field does not affect the read-only-ness of the property. This is the kind of thing I wanted to explain, because if that gets in then it will not be understood by JavaFX developers, average or not. |
I still stand by my proposal #521 (comment) Also everyone please read JavaFX Property architecture before assuming things, it should be our reference here. |
It's a good read, but it's doesn't always reflect the real usage, and it's not an official documentation or specification.
It's definitely valid. You chose the knob for read-only-ness (and disregard the wrapper property approach), and if someone wants a different visibility, finality, or lazyness then they should write it by themselves. It's one option. |
If I do not understand the underlying idea and design of the thing we're solving boilerplate problems for, I can't support it. The contract that would be required for me to trust you'll ensure it'll be supported for the next 12 years instead seems beyond reasonable. So, yes. It matters a lot. @Rawi01 has earned their plaudits on Project Lombok, so he gets the benefit of the doubt, if he's willing to get pulled into every issue that mentions this for the foreseeable future. Every comment makes me more lost, not less. Not your fault, @nlisker, @ogerardin and other contributors. I think they are just confusing. |
I can understand that, I get lost myself sometimes. If only Java had builtin property support with observability! Anyway, I think I made a perfectly reasonable, minimalistic and yet generic proposal in #521 (comment) and #521 (comment) If the goal of Lombok is to avoid typing boilerplate code, there you have it. |
According to the other commenters in this thread, they weren't. I have to maintain this stuff, so I need to grok it. I don't, so, this isn't happening. Sorry. JavaFX doesn't have anywhere near enough clout to make me try to scratch an itch I don't have. If another lombok maintainer wants to stand a post for this one I'll accept it (as I totally get the upside here, the only problem is - it turns out it's too confusing for me to understand it, so I cannot promise to support it, and we don't stick features into lombok that no core maintainers can support, for rather obvious reasons!) Given that @Rawi01 made an initial PR for this, that's currently the clearest route to getting this feature into lombok. I'll re-open and look at the PR if further feedback indicates it is needed. |
Would it be possible, to implement this as a Plugin? If so, rzwitserloot would not need to maintain it, as it could not break the main project. JavaFX is a optional library anyway. |
I don't mind writing and maintaining it myself, but last time I tried to build Lombok in Eclipse it didn't work and the mailing list didn't help resolve the issue. I can try again, but someone will have to write the non-Eclipse version too. |
At the time I had tested it and it worked fine except it did not support subclasses of native JavaFX types. |
Perhaps I was not clear: Any PRs would not be accepted, and lombok cannot be extended; you will have to fork it. So, if you're interested in writing this feature, the only way you can deliver it, is by forking lombok and maintaining the fork. That, or convince @Rawi01 or another maintainer who has earned enough credits to make a plausible promise of maintaining the feature to vouch for it. |
Hello, any updates on this? |
Well I think @rzwitserloot pretty much closed the door to it... |
Migrated from Google Code (issue 448)
The text was updated successfully, but these errors were encountered: