pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "aappddeevv" <aappdde...@verizon.net>
Subject RE: Can I use the serializer to initialize my component subclass versus reading a sub-object
Date Wed, 16 Jun 2010 23:23:51 GMT
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.

 

 

 

 


Mime
View raw message