daniel.fuchs at oracle.com
Thu Nov 29 15:18:30 PST 2012
On 11/29/12 11:28 PM, Richard Bair wrote:
> I'm confused, don't we want scene builder / FXML to be able to use these new methods defined on builders as well? If they are used, then we have to use a builder instead of just configuring an object via reflection, or some such?
SceneBuilder is able to deal with Builders methods if there is a
corresponding getter on the object.
If there is no getter on the object, then SceneBuilder can't figure out
what the corresponding value should be - in which case there needs to be
specific code in SB to take advantage of said methods.
A good example is the faked 'url' attribute for Image, or the fake
'location' attribute added to WebViewBuilder.
In both cases - we had to add specific code in SB to handle these...
It's not because there's no value for an attribute in FXML that there's
no value for that attribute on the object itself.
Let's say you have something like:
which happens to return a WebView... What value for the location
attribute are you going to show in the Inspector? How is SceneBuilder
going to figure out that this location attribute should be read-only,
because it can only be supplied to the WebViewBuilder, and therefore
<WebView location="some:url"/> is valid whereas <fx:include
source="MyWebView.fxml" location="some:url"/> is not - because the
object returned by fx:include is already built?
Usually you will need to add specific code that knows about this - e.g -
that knows that you can get the value of the
location attribute by calling WebView.getEngine().location()...
So even if the FXML loader is able to use these methods SceneBuilder
might not - at least not out of the box...
> On Nov 28, 2012, at 7:27 AM, Eva Krejcirova<eva.krejcirova at oracle.com> wrote:
>> There will certainly be methods with one argument, so this means that there must be a way for SceneBuilder and FXML to tell these methods apart from the property methods.
>> We can annotate the convenience methods by special annotation (e.g. BuilderConvenienceMethod).
>> Or we could add an annotation (e.g. BuilderProperty) to the methods which correspond to properties (= the methods which are currently in the builders).
>> On 22.11.2012 16:01, Daniel Fuchs wrote:
>>> On 11/22/12 3:40 PM, Eva Krejcirova wrote:
>>>> There is one more thing which needs to be sorted out before adding new
>>>> methods to builders:
>>>> SceneBuilder and FXML use builders to find names of properties of a
>>>> class, so they need to have a way to differentiate between the new
>>>> convenience methods and the methods which correspond to properties of a
>>>> class. Daniel, is this still true?
>>>> Last time we discussed this, Daniel suggested to annotate these new
>>>> convenience methods. If we go this way, we need to create a new runtime
>>>> annotation (and find a name for it :-) )
>>> Hi Eva,
>>> Yes this is still true. Note that SceneBuilder actually uses
>>> builders only in special cases - for WebView - for instance -
>>> because of the fake location attribute available on WebViewBuilder
>>> only - and for any type which has no public constructors (e.g.: all charts, Insets, etc...)
>>> However - SceneBuilder discovers whether there are constructor properties by introspecting ClassX and ClassXBuilder and comparing
>>> the results: it takes the name of all the single parameter
>>> instance methods in ClassXBuilder which returns a builder,
>>> remove the names of all writable (getter+setter) properties
>>> found in ClassX, and what remain are assumed to be constructor properties.
>>> As long as the convenience methods have more than 1 parameter
>>> (varargs count for 1) then this logic should remain valid.
>>> The FXMLLoader's JavaFXBuilderFactory also introspects builders
>>> in order to find out writable properties and type of properties,
>>> so that's another place you will have to look at
>>> (class JavaFXBuilderFactory.JavaFXBuilder).
>>> best regards,
>>> -- daniel
More information about the openjfx-dev