You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Greg Brown <gk...@mac.com> on 2010/06/16 14:45:59 UTC

Re: Can I use the serializer to initialize my component subclass versus reading a sub-object

You can initialize any class in BXML. If you want to initialize instances of a component subclass, just use an element representing that class instead of the base component class; e.g.:

<foo:MyPushButton buttonData="My Button">

vs.

<MyPushButton buttonData="Button"/>

Note that, in this example, foo refers your custom component's package, e.g. com.foo.


On Jun 16, 2010, at 10:15 AM, aappddeevv wrote:

>  
> Is it possible to initialize my component subclass using bxml or can I only read objects from bxml as if they were subobjects?
>  
> My use case is where I want to push as much “static” configuration into bxml as possible for my component and greatly reduce the need for me to bind or wire children myself in my subclass. Clients of my component would be completely unaware of how I initialize my object behind the scenes. I was authoring a few components and found that I was writing a bunch of component initialization code that look the same each time.
>  
> I think the answer is no but I wanted to check the group.


Re: Can I use the serializer to initialize my component subclass versus reading a sub-object

Posted by Greg Brown <gk...@mac.com>.
> I do need to look at skins if I ever want to do some custom layout or painting (which I actually would like to avoid).

Like writing a skin, I would suggest that custom layout or painting is also not something to be afraid of. It's certainly not as easy as simply using the framework, but we have tried really hard not to make it a challenge.

> Take at look at the patch when it comes your way.

I will do so. Thanks.

G



RE: Can I use the serializer to initialize my component subclass versus reading a sub-object

Posted by aappddeevv <aa...@verizon.net>.
I did not interpret it that way. And I do need to look at skins if I ever
want to do some custom layout or painting (which I actually would like to
avoid J).

 

Take at look at the patch when it comes your way. I think its more natural
than an include and no skins are needed.  In fact it took me awhile to
understand that I could not subclass directly from Component and use that in
my program-pivot kept looking for a skin. I agree as well that an include is
a natural way to contribute.

 

I think it is important that multiple ways are available and I can see the
influence of web-based programming models in pivot e.g. scripting on a
"serializer page," includes, and other constructs. 

 

 

 

From: Greg Brown [mailto:gkbrown@mac.com] 
Sent: Wednesday, June 16, 2010 7:11 PM
To: user@pivot.apache.org
Subject: Re: Can I use the serializer to initialize my component subclass
versus reading a sub-object

 

I'll take a look at skins. Most people are probably not going to write skins
would be my guess though.

 

Exactly - a typical app developer will use the include model, because it is
intuitive and easy to work with. 

 

That probably came across a bit more pompously than I intended it to. I
don't mean to imply that this is the best approach and that others are not
worth considering. However, from personal experience writing a non-trivial
application, I can say that the include model maps very well to the use case
of modularizing an application's sub-components. As you can imagine, it is
considerably easier to understand and work with than writing a custom skin,
and so will probably appeal much more so to a typical app developer. 

 

However, based on what you have said, you are not a typical app developer -
you are attempting to create reusable components that can be shared using a
model similar to the framework components themselves. To me, that represents
a strong use case for writing a custom skin.

 

Please note that writing a skin is not something to be afraid of. It is
nowhere near as complex as you might think, especially if you are extending
an existing concrete class. Also, there are plenty of examples to draw from.

 

G

 


Re: Can I use the serializer to initialize my component subclass versus reading a sub-object

Posted by Greg Brown <gk...@mac.com>.
>> I’ll take a look at skins. Most people are probably not going to write skins would be my guess though.
> 
> Exactly - a typical app developer will use the include model, because it is intuitive and easy to work with. 

That probably came across a bit more pompously than I intended it to. I don't mean to imply that this is the best approach and that others are not worth considering. However, from personal experience writing a non-trivial application, I can say that the include model maps very well to the use case of modularizing an application's sub-components. As you can imagine, it is considerably easier to understand and work with than writing a custom skin, and so will probably appeal much more so to a typical app developer. 

However, based on what you have said, you are not a typical app developer - you are attempting to create reusable components that can be shared using a model similar to the framework components themselves. To me, that represents a strong use case for writing a custom skin.

Please note that writing a skin is not something to be afraid of. It is nowhere near as complex as you might think, especially if you are extending an existing concrete class. Also, there are plenty of examples to draw from.

G


Re: Can I use the serializer to initialize my component subclass versus reading a sub-object

Posted by Greg Brown <gk...@mac.com>.
> I’ll take a look at skins. Most people are probably not going to write skins would be my guess though.

Exactly - a typical app developer will use the include model, because it is intuitive and easy to work with. However, your use case seems to call for a custom component, and hence a custom skin should be associated with that.


RE: Can I use the serializer to initialize my component subclass versus reading a sub-object

Posted by aappddeevv <aa...@verizon.net>.
I'll take a look at skins. Most people are probably not going to write skins
would be my guess though.

 

I'll submit a JIRA maybe this weekend and you can take a look. It's a subtle
but I think highly useful thing. 

 

If its at the skin level and was useful, think about it at my level
(beginner) of programming, and its also very useful.

 

 

 

From: Greg Brown [mailto:gkbrown@mac.com] 
Sent: Wednesday, June 16, 2010 4:50 PM
To: user@pivot.apache.org
Subject: Re: Can I use the serializer to initialize my component subclass
versus reading a sub-object

 

I just re-read your earlier email. I had missed the part about hiding the
existence of the BXML from callers. Includes are a completely valid way to
create custom components and tend to work well for modularizing the various
subcomponents of an application. However, what you are describing sounds
like it might be better implemented via a custom skin class. Take a look at
the code for TerraAlertSkin or TerraPromptSkin, which load their content
from BXML and bind() to it in install().

 

 

On Jun 16, 2010, at 3:47 PM, aappddeevv wrote:





I found it easier to create components with at least conceptually even
though it is a small change in viewpoint.

 

The reason its not production ready is because it should check that the
component being initialized is compatible with the same type of the
component at the root of the wtkx file.

 

I'll post the patch after a day of using it to help me with solve my
component layout problems.

 

 

From: Greg Brown [mailto:gkbrown@mac.com] 
Sent: Wednesday, June 16, 2010 1:14 PM
To: user@pivot.apache.org
Subject: Re: Can I use the serializer to initialize my component subclass
versus reading a sub-object

 

That's good. However (though I'd obviously have to see the patch to say for
sure), what you described sounds like it is probably outside the scope of
the intended behavior for BXMLSerializer.

 

On Jun 16, 2010, at 12:42 PM, aappddeevv wrote:






k...I did create a patch though and it seems to work. About 10 lines long
mostly defining a new initialize method.  Not claiming its production ready
though.

 

From: Greg Brown [mailto:gkbrown@mac.com] 
Sent: Wednesday, June 16, 2010 9:22 AM
To: user@pivot.apache.org
Subject: Re: Can I use the serializer to initialize my component subclass
versus reading a sub-object

 

You are correct - that is not supported. BXMLSerializer will always create
and initialize the root element.

 

The recommended approach is to define a .bxml file containing your custom
class as a root element and provide this to your callers to use as an
include. Your class should probably implement Bindable such that you can
perform your initialization when the serializer is done loading the class.

 

On Jun 16, 2010, at 11:13 AM, aappddeevv wrote:







Not quite the use case though. In other words, when I create a component,
MyPushButton, I of course want clients to use my component in their bxml.
This is not the case of me writing bxml using my component.

 

I want to use bxml is used as initialization for MyPushButton that is
completely hidden from my clients. For push buttons, this is trivial, but I
have several children in a component I am writing. I find xbml very
convenient to use. So I want to push everything into it that is possible,
user data, decorators, children, etc. However, there is code I need to write
as well in java. I also don't want to ask clients to do a bxml include, but
just use my component like any other class in THEIR bxml. This allows me to
provide components in a library but use bxml for convenient initialization.

 

It's a subtle difference in the use of bxml but I found I was writing the
same "initialize my class with things loaded from bxml" code over and over
again (which means more than twice). I realized that the Wtkid and Bindable
mechanism were really most driven by "initialize my component" use cases but
an alternate approach can co-exist that is significantly easier.

 

I think by your answer, the answer is probably not. Here's the code example:

 

So instead of this:

 

Class MyClass extends ScrollPane.

public MyClass() {

                . serializer = new WTXSerializer("mycomponent.wtkx");

serializer.bind(this);

add(a whole bunch of objects injected with WTKID);

// Copy user data over, decorators, styles, handlers, etc. from bxml

// or manually code in the initialization. Wait, it's a bit harder

// to create my left and right children in bxml! I could change

// my superclass or stick children in a fake boxpane and pull them out

// to add them into me.

}

 

I would do:

 

Class MyClass extends ScrollPane.

Public MyClass() {
                . serializer = new WTKXSerializer("mycomponent.wtkx");

serializer.initialize(this);

// Hey! Everything including user data, decorators and children are loaded
into MyClass automatically.

// My client just thinks I am a scrollpane!

}

 

This is safe to do because the innards of my class initialization are under
my control. Essentially, its about NOT having the bxml serializer
instantiate the root object. Looks I could rummage up a patch. Give me a few
minute.

 

 

 

From: Greg Brown [mailto:gkbrown@mac.com] 
Sent: Wednesday, June 16, 2010 8:46 AM
To: user@pivot.apache.org
Subject: Re: Can I use the serializer to initialize my component subclass
versus reading a sub-object

 

You can initialize any class in BXML. If you want to initialize instances of
a component subclass, just use an element representing that class instead of
the base component class; e.g.:

 

<foo:MyPushButton buttonData="My Button">

 

vs.

 

<MyPushButton buttonData="Button"/>

 

Note that, in this example, foo refers your custom component's package, e.g.
com.foo.

 

 

On Jun 16, 2010, at 10:15 AM, aappddeevv wrote:








 

Is it possible to initialize my component subclass using bxml or can I only
read objects from bxml as if they were subobjects?

 

My use case is where I want to push as much "static" configuration into bxml
as possible for my component and greatly reduce the need for me to bind or
wire children myself in my subclass. Clients of my component would be
completely unaware of how I initialize my object behind the scenes. I was
authoring a few components and found that I was writing a bunch of component
initialization code that look the same each time.

 

I think the answer is no but I wanted to check the group.

 

 

 

 


Re: Can I use the serializer to initialize my component subclass versus reading a sub-object

Posted by Greg Brown <gk...@mac.com>.
I just re-read your earlier email. I had missed the part about hiding the existence of the BXML from callers. Includes are a completely valid way to create custom components and tend to work well for modularizing the various subcomponents of an application. However, what you are describing sounds like it might be better implemented via a custom skin class. Take a look at the code for TerraAlertSkin or TerraPromptSkin, which load their content from BXML and bind() to it in install().


On Jun 16, 2010, at 3:47 PM, aappddeevv wrote:

> I found it easier to create components with at least conceptually even though it is a small change in viewpoint.
>  
> The reason its not production ready is because it should check that the component being initialized is compatible with the same type of the component at the root of the wtkx file.
>  
> I’ll post the patch after a day of using it to help me with solve my component layout problems.
>  
>  
> From: Greg Brown [mailto:gkbrown@mac.com] 
> Sent: Wednesday, June 16, 2010 1:14 PM
> To: user@pivot.apache.org
> Subject: Re: Can I use the serializer to initialize my component subclass versus reading a sub-object
>  
> That's good. However (though I'd obviously have to see the patch to say for sure), what you described sounds like it is probably outside the scope of the intended behavior for BXMLSerializer.
>  
> On Jun 16, 2010, at 12:42 PM, aappddeevv wrote:
> 
> 
> k...I did create a patch though and it seems to work. About 10 lines long mostly defining a new initialize method.  Not claiming its production ready though.
>  
> From: Greg Brown [mailto:gkbrown@mac.com] 
> Sent: Wednesday, June 16, 2010 9:22 AM
> To: user@pivot.apache.org
> Subject: Re: Can I use the serializer to initialize my component subclass versus reading a sub-object
>  
> You are correct - that is not supported. BXMLSerializer will always create and initialize the root element.
>  
> The recommended approach is to define a .bxml file containing your custom class as a root element and provide this to your callers to use as an include. Your class should probably implement Bindable such that you can perform your initialization when the serializer is done loading the class.
>  
> On Jun 16, 2010, at 11:13 AM, aappddeevv wrote:
> 
> 
> 
> Not quite the use case though. In other words, when I create a component, MyPushButton, I of course want clients to use my component in their bxml. This is not the case of me writing bxml using my component.
>  
> I want to use bxml is used as initialization for MyPushButton that is completely hidden from my clients. For push buttons, this is trivial, but I have several children in a component I am writing. I find xbml very convenient to use. So I want to push everything into it that is possible, user data, decorators, children, etc. However, there is code I need to write as well in java. I also don’t want to ask clients to do a bxml include, but just use my component like any other class in THEIR bxml. This allows me to provide components in a library but use bxml for convenient initialization.
>  
> It’s a subtle difference in the use of bxml but I found I was writing the same “initialize my class with things loaded from bxml” code over and over again (which means more than twice). I realized that the Wtkid and Bindable mechanism were really most driven by “initialize my component” use cases but an alternate approach can co-exist that is significantly easier.
>  
> I think by your answer, the answer is probably not. Here’s the code example:
>  
> So instead of this:
>  
> Class MyClass extends ScrollPane…
> public MyClass() {
>                 … serializer = new WTXSerializer(“mycomponent.wtkx”);
> serializer.bind(this);
> add(a whole bunch of objects injected with WTKID);
> // Copy user data over, decorators, styles, handlers, etc. from bxml
> // or manually code in the initialization. Wait, it’s a bit harder
> // to create my left and right children in bxml! I could change
> // my superclass or stick children in a fake boxpane and pull them out
> // to add them into me.
> }
>  
> I would do:
>  
> Class MyClass extends ScrollPane…
> Public MyClass() {
>                 … serializer = new WTKXSerializer(“mycomponent.wtkx”);
> serializer.initialize(this);
> // Hey! Everything including user data, decorators and children are loaded into MyClass automatically.
> // My client just thinks I am a scrollpane!
> }
>  
> This is safe to do because the innards of my class initialization are under my control. Essentially, its about NOT having the bxml serializer instantiate the root object. Looks I could rummage up a patch. Give me a few minute…
>  
>  
>  
> From: Greg Brown [mailto:gkbrown@mac.com] 
> Sent: Wednesday, June 16, 2010 8:46 AM
> To: user@pivot.apache.org
> Subject: Re: Can I use the serializer to initialize my component subclass versus reading a sub-object
>  
> You can initialize any class in BXML. If you want to initialize instances of a component subclass, just use an element representing that class instead of the base component class; e.g.:
>  
> <foo:MyPushButton buttonData="My Button">
>  
> vs.
>  
> <MyPushButton buttonData="Button"/>
>  
> Note that, in this example, foo refers your custom component's package, e.g. com.foo.
>  
>  
> On Jun 16, 2010, at 10:15 AM, aappddeevv wrote:
> 
> 
> 
> 
>  
> Is it possible to initialize my component subclass using bxml or can I only read objects from bxml as if they were subobjects?
>  
> My use case is where I want to push as much “static” configuration into bxml as possible for my component and greatly reduce the need for me to bind or wire children myself in my subclass. Clients of my component would be completely unaware of how I initialize my object behind the scenes. I was authoring a few components and found that I was writing a bunch of component initialization code that look the same each time.
>  
> I think the answer is no but I wanted to check the group.
>  
>  
>  


RE: Can I use the serializer to initialize my component subclass versus reading a sub-object

Posted by aappddeevv <aa...@verizon.net>.
I found it easier to create components with at least conceptually even
though it is a small change in viewpoint. 

 

The reason its not production ready is because it should check that the
component being initialized is compatible with the same type of the
component at the root of the wtkx file.

 

I'll post the patch after a day of using it to help me with solve my
component layout problems.

 

 

From: Greg Brown [mailto:gkbrown@mac.com] 
Sent: Wednesday, June 16, 2010 1:14 PM
To: user@pivot.apache.org
Subject: Re: Can I use the serializer to initialize my component subclass
versus reading a sub-object

 

That's good. However (though I'd obviously have to see the patch to say for
sure), what you described sounds like it is probably outside the scope of
the intended behavior for BXMLSerializer.

 

On Jun 16, 2010, at 12:42 PM, aappddeevv wrote:





k...I did create a patch though and it seems to work. About 10 lines long
mostly defining a new initialize method.  Not claiming its production ready
though.

 

From: Greg Brown [mailto:gkbrown@mac.com] 
Sent: Wednesday, June 16, 2010 9:22 AM
To: user@pivot.apache.org
Subject: Re: Can I use the serializer to initialize my component subclass
versus reading a sub-object

 

You are correct - that is not supported. BXMLSerializer will always create
and initialize the root element.

 

The recommended approach is to define a .bxml file containing your custom
class as a root element and provide this to your callers to use as an
include. Your class should probably implement Bindable such that you can
perform your initialization when the serializer is done loading the class.

 

On Jun 16, 2010, at 11:13 AM, aappddeevv wrote:






Not quite the use case though. In other words, when I create a component,
MyPushButton, I of course want clients to use my component in their bxml.
This is not the case of me writing bxml using my component.

 

I want to use bxml is used as initialization for MyPushButton that is
completely hidden from my clients. For push buttons, this is trivial, but I
have several children in a component I am writing. I find xbml very
convenient to use. So I want to push everything into it that is possible,
user data, decorators, children, etc. However, there is code I need to write
as well in java. I also don't want to ask clients to do a bxml include, but
just use my component like any other class in THEIR bxml. This allows me to
provide components in a library but use bxml for convenient initialization.

 

It's a subtle difference in the use of bxml but I found I was writing the
same "initialize my class with things loaded from bxml" code over and over
again (which means more than twice). I realized that the Wtkid and Bindable
mechanism were really most driven by "initialize my component" use cases but
an alternate approach can co-exist that is significantly easier.

 

I think by your answer, the answer is probably not. Here's the code example:

 

So instead of this:

 

Class MyClass extends ScrollPane.

public MyClass() {

                . serializer = new WTXSerializer("mycomponent.wtkx");

serializer.bind(this);

add(a whole bunch of objects injected with WTKID);

// Copy user data over, decorators, styles, handlers, etc. from bxml

// or manually code in the initialization. Wait, it's a bit harder

// to create my left and right children in bxml! I could change

// my superclass or stick children in a fake boxpane and pull them out

// to add them into me.

}

 

I would do:

 

Class MyClass extends ScrollPane.

Public MyClass() {
                . serializer = new WTKXSerializer("mycomponent.wtkx");

serializer.initialize(this);

// Hey! Everything including user data, decorators and children are loaded
into MyClass automatically.

// My client just thinks I am a scrollpane!

}

 

This is safe to do because the innards of my class initialization are under
my control. Essentially, its about NOT having the bxml serializer
instantiate the root object. Looks I could rummage up a patch. Give me a few
minute.

 

 

 

From: Greg Brown [mailto:gkbrown@mac.com] 
Sent: Wednesday, June 16, 2010 8:46 AM
To: user@pivot.apache.org
Subject: Re: Can I use the serializer to initialize my component subclass
versus reading a sub-object

 

You can initialize any class in BXML. If you want to initialize instances of
a component subclass, just use an element representing that class instead of
the base component class; e.g.:

 

<foo:MyPushButton buttonData="My Button">

 

vs.

 

<MyPushButton buttonData="Button"/>

 

Note that, in this example, foo refers your custom component's package, e.g.
com.foo.

 

 

On Jun 16, 2010, at 10:15 AM, aappddeevv wrote:







 

Is it possible to initialize my component subclass using bxml or can I only
read objects from bxml as if they were subobjects?

 

My use case is where I want to push as much "static" configuration into bxml
as possible for my component and greatly reduce the need for me to bind or
wire children myself in my subclass. Clients of my component would be
completely unaware of how I initialize my object behind the scenes. I was
authoring a few components and found that I was writing a bunch of component
initialization code that look the same each time.

 

I think the answer is no but I wanted to check the group.

 

 

 


Re: Can I use the serializer to initialize my component subclass versus reading a sub-object

Posted by Greg Brown <gk...@mac.com>.
That's good. However (though I'd obviously have to see the patch to say for sure), what you described sounds like it is probably outside the scope of the intended behavior for BXMLSerializer.

On Jun 16, 2010, at 12:42 PM, aappddeevv wrote:

> k...I did create a patch though and it seems to work. About 10 lines long mostly defining a new initialize method.  Not claiming its production ready though.
>  
> From: Greg Brown [mailto:gkbrown@mac.com] 
> Sent: Wednesday, June 16, 2010 9:22 AM
> To: user@pivot.apache.org
> Subject: Re: Can I use the serializer to initialize my component subclass versus reading a sub-object
>  
> You are correct - that is not supported. BXMLSerializer will always create and initialize the root element.
>  
> The recommended approach is to define a .bxml file containing your custom class as a root element and provide this to your callers to use as an include. Your class should probably implement Bindable such that you can perform your initialization when the serializer is done loading the class.
>  
> On Jun 16, 2010, at 11:13 AM, aappddeevv wrote:
> 
> 
> Not quite the use case though. In other words, when I create a component, MyPushButton, I of course want clients to use my component in their bxml. This is not the case of me writing bxml using my component.
>  
> I want to use bxml is used as initialization for MyPushButton that is completely hidden from my clients. For push buttons, this is trivial, but I have several children in a component I am writing. I find xbml very convenient to use. So I want to push everything into it that is possible, user data, decorators, children, etc. However, there is code I need to write as well in java. I also don’t want to ask clients to do a bxml include, but just use my component like any other class in THEIR bxml. This allows me to provide components in a library but use bxml for convenient initialization.
>  
> It’s a subtle difference in the use of bxml but I found I was writing the same “initialize my class with things loaded from bxml” code over and over again (which means more than twice). I realized that the Wtkid and Bindable mechanism were really most driven by “initialize my component” use cases but an alternate approach can co-exist that is significantly easier.
>  
> I think by your answer, the answer is probably not. Here’s the code example:
>  
> So instead of this:
>  
> Class MyClass extends ScrollPane…
> public MyClass() {
>                 … serializer = new WTXSerializer(“mycomponent.wtkx”);
> serializer.bind(this);
> add(a whole bunch of objects injected with WTKID);
> // Copy user data over, decorators, styles, handlers, etc. from bxml
> // or manually code in the initialization. Wait, it’s a bit harder
> // to create my left and right children in bxml! I could change
> // my superclass or stick children in a fake boxpane and pull them out
> // to add them into me.
> }
>  
> I would do:
>  
> Class MyClass extends ScrollPane…
> Public MyClass() {
>                 … serializer = new WTKXSerializer(“mycomponent.wtkx”);
> serializer.initialize(this);
> // Hey! Everything including user data, decorators and children are loaded into MyClass automatically.
> // My client just thinks I am a scrollpane!
> }
>  
> This is safe to do because the innards of my class initialization are under my control. Essentially, its about NOT having the bxml serializer instantiate the root object. Looks I could rummage up a patch. Give me a few minute…
>  
>  
>  
> From: Greg Brown [mailto:gkbrown@mac.com] 
> Sent: Wednesday, June 16, 2010 8:46 AM
> To: user@pivot.apache.org
> Subject: Re: Can I use the serializer to initialize my component subclass versus reading a sub-object
>  
> You can initialize any class in BXML. If you want to initialize instances of a component subclass, just use an element representing that class instead of the base component class; e.g.:
>  
> <foo:MyPushButton buttonData="My Button">
>  
> vs.
>  
> <MyPushButton buttonData="Button"/>
>  
> Note that, in this example, foo refers your custom component's package, e.g. com.foo.
>  
>  
> On Jun 16, 2010, at 10:15 AM, aappddeevv wrote:
> 
> 
> 
>  
> Is it possible to initialize my component subclass using bxml or can I only read objects from bxml as if they were subobjects?
>  
> My use case is where I want to push as much “static” configuration into bxml as possible for my component and greatly reduce the need for me to bind or wire children myself in my subclass. Clients of my component would be completely unaware of how I initialize my object behind the scenes. I was authoring a few components and found that I was writing a bunch of component initialization code that look the same each time.
>  
> I think the answer is no but I wanted to check the group.
>  
>  


RE: Can I use the serializer to initialize my component subclass versus reading a sub-object

Posted by aappddeevv <aa...@verizon.net>.
k...I did create a patch though and it seems to work. About 10 lines long
mostly defining a new initialize method.  Not claiming its production ready
though.

 

From: Greg Brown [mailto:gkbrown@mac.com] 
Sent: Wednesday, June 16, 2010 9:22 AM
To: user@pivot.apache.org
Subject: Re: Can I use the serializer to initialize my component subclass
versus reading a sub-object

 

You are correct - that is not supported. BXMLSerializer will always create
and initialize the root element.

 

The recommended approach is to define a .bxml file containing your custom
class as a root element and provide this to your callers to use as an
include. Your class should probably implement Bindable such that you can
perform your initialization when the serializer is done loading the class.

 

On Jun 16, 2010, at 11:13 AM, aappddeevv wrote:





Not quite the use case though. In other words, when I create a component,
MyPushButton, I of course want clients to use my component in their bxml.
This is not the case of me writing bxml using my component.

 

I want to use bxml is used as initialization for MyPushButton that is
completely hidden from my clients. For push buttons, this is trivial, but I
have several children in a component I am writing. I find xbml very
convenient to use. So I want to push everything into it that is possible,
user data, decorators, children, etc. However, there is code I need to write
as well in java. I also don't want to ask clients to do a bxml include, but
just use my component like any other class in THEIR bxml. This allows me to
provide components in a library but use bxml for convenient initialization.

 

It's a subtle difference in the use of bxml but I found I was writing the
same "initialize my class with things loaded from bxml" code over and over
again (which means more than twice). I realized that the Wtkid and Bindable
mechanism were really most driven by "initialize my component" use cases but
an alternate approach can co-exist that is significantly easier.

 

I think by your answer, the answer is probably not. Here's the code example:

 

So instead of this:

 

Class MyClass extends ScrollPane.

public MyClass() {

                . serializer = new WTXSerializer("mycomponent.wtkx");

serializer.bind(this);

add(a whole bunch of objects injected with WTKID);

// Copy user data over, decorators, styles, handlers, etc. from bxml

// or manually code in the initialization. Wait, it's a bit harder

// to create my left and right children in bxml! I could change

// my superclass or stick children in a fake boxpane and pull them out

// to add them into me.

}

 

I would do:

 

Class MyClass extends ScrollPane.

Public MyClass() {
                . serializer = new WTKXSerializer("mycomponent.wtkx");

serializer.initialize(this);

// Hey! Everything including user data, decorators and children are loaded
into MyClass automatically.

// My client just thinks I am a scrollpane!

}

 

This is safe to do because the innards of my class initialization are under
my control. Essentially, its about NOT having the bxml serializer
instantiate the root object. Looks I could rummage up a patch. Give me a few
minute.

 

 

 

From: Greg Brown [mailto:gkbrown@mac.com] 
Sent: Wednesday, June 16, 2010 8:46 AM
To: user@pivot.apache.org
Subject: Re: Can I use the serializer to initialize my component subclass
versus reading a sub-object

 

You can initialize any class in BXML. If you want to initialize instances of
a component subclass, just use an element representing that class instead of
the base component class; e.g.:

 

<foo:MyPushButton buttonData="My Button">

 

vs.

 

<MyPushButton buttonData="Button"/>

 

Note that, in this example, foo refers your custom component's package, e.g.
com.foo.

 

 

On Jun 16, 2010, at 10:15 AM, aappddeevv wrote:






 

Is it possible to initialize my component subclass using bxml or can I only
read objects from bxml as if they were subobjects?

 

My use case is where I want to push as much "static" configuration into bxml
as possible for my component and greatly reduce the need for me to bind or
wire children myself in my subclass. Clients of my component would be
completely unaware of how I initialize my object behind the scenes. I was
authoring a few components and found that I was writing a bunch of component
initialization code that look the same each time.

 

I think the answer is no but I wanted to check the group.

 

 


Re: Can I use the serializer to initialize my component subclass versus reading a sub-object

Posted by Greg Brown <gk...@mac.com>.
You are correct - that is not supported. BXMLSerializer will always create and initialize the root element.

The recommended approach is to define a .bxml file containing your custom class as a root element and provide this to your callers to use as an include. Your class should probably implement Bindable such that you can perform your initialization when the serializer is done loading the class.

On Jun 16, 2010, at 11:13 AM, aappddeevv wrote:

> Not quite the use case though. In other words, when I create a component, MyPushButton, I of course want clients to use my component in their bxml. This is not the case of me writing bxml using my component.
>  
> I want to use bxml is used as initialization for MyPushButton that is completely hidden from my clients. For push buttons, this is trivial, but I have several children in a component I am writing. I find xbml very convenient to use. So I want to push everything into it that is possible, user data, decorators, children, etc. However, there is code I need to write as well in java. I also don’t want to ask clients to do a bxml include, but just use my component like any other class in THEIR bxml. This allows me to provide components in a library but use bxml for convenient initialization.
>  
> It’s a subtle difference in the use of bxml but I found I was writing the same “initialize my class with things loaded from bxml” code over and over again (which means more than twice). I realized that the Wtkid and Bindable mechanism were really most driven by “initialize my component” use cases but an alternate approach can co-exist that is significantly easier.
>  
> I think by your answer, the answer is probably not. Here’s the code example:
>  
> So instead of this:
>  
> Class MyClass extends ScrollPane…
> public MyClass() {
>                 … serializer = new WTXSerializer(“mycomponent.wtkx”);
> serializer.bind(this);
> add(a whole bunch of objects injected with WTKID);
> // Copy user data over, decorators, styles, handlers, etc. from bxml
> // or manually code in the initialization. Wait, it’s a bit harder
> // to create my left and right children in bxml! I could change
> // my superclass or stick children in a fake boxpane and pull them out
> // to add them into me.
> }
>  
> I would do:
>  
> Class MyClass extends ScrollPane…
> Public MyClass() {
>                 … serializer = new WTKXSerializer(“mycomponent.wtkx”);
> serializer.initialize(this);
> // Hey! Everything including user data, decorators and children are loaded into MyClass automatically.
> // My client just thinks I am a scrollpane!
> }
>  
> This is safe to do because the innards of my class initialization are under my control. Essentially, its about NOT having the bxml serializer instantiate the root object. Looks I could rummage up a patch. Give me a few minute…
>  
>  
>  
> From: Greg Brown [mailto:gkbrown@mac.com] 
> Sent: Wednesday, June 16, 2010 8:46 AM
> To: user@pivot.apache.org
> Subject: Re: Can I use the serializer to initialize my component subclass versus reading a sub-object
>  
> You can initialize any class in BXML. If you want to initialize instances of a component subclass, just use an element representing that class instead of the base component class; e.g.:
>  
> <foo:MyPushButton buttonData="My Button">
>  
> vs.
>  
> <MyPushButton buttonData="Button"/>
>  
> Note that, in this example, foo refers your custom component's package, e.g. com.foo.
>  
>  
> On Jun 16, 2010, at 10:15 AM, aappddeevv wrote:
> 
> 
>  
> Is it possible to initialize my component subclass using bxml or can I only read objects from bxml as if they were subobjects?
>  
> My use case is where I want to push as much “static” configuration into bxml as possible for my component and greatly reduce the need for me to bind or wire children myself in my subclass. Clients of my component would be completely unaware of how I initialize my object behind the scenes. I was authoring a few components and found that I was writing a bunch of component initialization code that look the same each time.
>  
> I think the answer is no but I wanted to check the group.
>  


RE: Can I use the serializer to initialize my component subclass versus reading a sub-object

Posted by aappddeevv <aa...@verizon.net>.
Not quite the use case though. In other words, when I create a component,
MyPushButton, I of course want clients to use my component in their bxml.
This is not the case of me writing bxml using my component.

 

I want to use bxml is used as initialization for MyPushButton that is
completely hidden from my clients. For push buttons, this is trivial, but I
have several children in a component I am writing. I find xbml very
convenient to use. So I want to push everything into it that is possible,
user data, decorators, children, etc. However, there is code I need to write
as well in java. I also don't want to ask clients to do a bxml include, but
just use my component like any other class in THEIR bxml. This allows me to
provide components in a library but use bxml for convenient initialization. 

 

It's a subtle difference in the use of bxml but I found I was writing the
same "initialize my class with things loaded from bxml" code over and over
again (which means more than twice). I realized that the Wtkid and Bindable
mechanism were really most driven by "initialize my component" use cases but
an alternate approach can co-exist that is significantly easier.

 

I think by your answer, the answer is probably not. Here's the code example:

 

So instead of this:

 

Class MyClass extends ScrollPane.

public MyClass() {

                . serializer = new WTXSerializer("mycomponent.wtkx");

serializer.bind(this);

add(a whole bunch of objects injected with WTKID);

// Copy user data over, decorators, styles, handlers, etc. from bxml

// or manually code in the initialization. Wait, it's a bit harder

// to create my left and right children in bxml! I could change

// my superclass or stick children in a fake boxpane and pull them out

// to add them into me.

}

 

I would do:

 

Class MyClass extends ScrollPane.

Public MyClass() {
                . serializer = new WTKXSerializer("mycomponent.wtkx");

serializer.initialize(this);

// Hey! Everything including user data, decorators and children are loaded
into MyClass automatically.

// My client just thinks I am a scrollpane!

}

 

This is safe to do because the innards of my class initialization are under
my control. Essentially, its about NOT having the bxml serializer
instantiate the root object. Looks I could rummage up a patch. Give me a few
minute.

 

 

 

From: Greg Brown [mailto:gkbrown@mac.com] 
Sent: Wednesday, June 16, 2010 8:46 AM
To: user@pivot.apache.org
Subject: Re: Can I use the serializer to initialize my component subclass
versus reading a sub-object

 

You can initialize any class in BXML. If you want to initialize instances of
a component subclass, just use an element representing that class instead of
the base component class; e.g.:

 

<foo:MyPushButton buttonData="My Button">

 

vs.

 

<MyPushButton buttonData="Button"/>

 

Note that, in this example, foo refers your custom component's package, e.g.
com.foo.

 

 

On Jun 16, 2010, at 10:15 AM, aappddeevv wrote:





 

Is it possible to initialize my component subclass using bxml or can I only
read objects from bxml as if they were subobjects?

 

My use case is where I want to push as much "static" configuration into bxml
as possible for my component and greatly reduce the need for me to bind or
wire children myself in my subclass. Clients of my component would be
completely unaware of how I initialize my object behind the scenes. I was
authoring a few components and found that I was writing a bunch of component
initialization code that look the same each time.

 

I think the answer is no but I wanted to check the group.