You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Cuong Diep <cu...@fortresshill.co.uk> on 2010/01/29 18:10:06 UTC

Components made up of Java class and WTKX markup

Hi there,

First off, I'd says thanks to the devs.  I've never got round to learning
Swing and Pivot seems so much easier!

But to my question:

Let's say I have the class AboutPane [extends BoxPane] and I have the markup
file AboutPane.wtkx which has the content

<mycorp:AboutPane ...>
    <Label wtkx:id="version" text="Version 1.0" />
</mycorp>

That is, AboutPane always has a Label to display a 'version' value.

To include in my app, I do a '<wtkx:include src="AboutPane.wtkx />' in my
main markup file, but within AboutPane.java, how do I reference the
'version' property from within, say, AboutPane's constructor?

Inversely, I can do a '<mycorp:AboutPane />' in my main markup file, but how
do tell Pivot to parse and render AboutPane.wtkx (as it automagically
includes the version Label)?


I don't know if you guys have looked at Apache Wicket, but they have the
principle of a component (which may contain child components) being
implicitly linked to a markup file.  So, in theory, I can reuse and
distribute that component.  What is Pivot's guide for this can of usecase?

Thanks,

Cuong.

Re: Components made up of Java class and WTKX markup

Posted by Greg Brown <gk...@mac.com>.
You could do this using the approach I outlined below. You could also define a custom "composite" component. This would be a class that extends Container and installs a skin that manages the various subcomponents.

If the component is only going to be used within a single application, the first approach is probably a better choice since it will be easier to implement. If you plan to use it across multiple applications, you may want to consider the second approach.

Greg


On Feb 1, 2010, at 10:44 AM, Cuong Diep wrote:

> Hi,
> 
> Sorry I did't make myself a bit clearer.
> 
> I suppose what I'm trying to work out is how to create a 'black-box component' that consists of many widgets.  For example, a 'paging table' component that consists of a TableView but also Labels to show total number of items, starting item number, end item number, LinkButtons for next and previous page, etc. etc.
> 
> I'd like to be reuse the above component but may want to change the position or alignment of the labels or link buttons or hide them completely.
> 
> What would be the best way to do this?
> 
> 
> 
> ---------- Forwarded message ----------
> From: Greg Brown <gk...@mac.com>
> To: user@pivot.apache.org
> Date: Fri, 29 Jan 2010 12:45:27 -0500
> Subject: Re: Components made up of Java class and WTKX markup
> Hi Cuong,
> 
> > Let's say I have the class AboutPane [extends BoxPane] and I have the markup file AboutPane.wtkx which has the content
> >
> > <mycorp:AboutPane ...>
> >     <Label wtkx:id="version" text="Version 1.0" />
> > </mycorp>
> >
> > That is, AboutPane always has a Label to display a 'version' value.
> >
> > To include in my app, I do a '<wtkx:include src="AboutPane.wtkx />' in my main markup file, but within AboutPane.java, how do I reference the 'version' property from within, say, AboutPane's constructor?
> 
> If AboutPane implements org.apache.pivot.wtkx.Bindable and declares a Label member as follows, you can get access to the label in the initialize() method:
> 
> @WTKX private Label version;
> 
> (the annotation is also defined in org.apache.pivot.wtkx)
> 
> > Inversely, I can do a '<mycorp:AboutPane />' in my main markup file, but how do tell Pivot to parse and render AboutPane.wtkx (as it automagically includes the version Label)?
> 
> Not entirely sure what you are looking for, but perhaps you want to use an include?
> 
> <wtkx:include src="AboutPane.wtkx"/>
> 
> Hope this helps,
> Greg


Re: Components made up of Java class and WTKX markup

Posted by Cuong Diep <cu...@fortresshill.co.uk>.
Hi,

Sorry I did't make myself a bit clearer.

I suppose what I'm trying to work out is how to create a 'black-box
component' that consists of many widgets.  For example, a 'paging table'
component that consists of a TableView but also Labels to show total number
of items, starting item number, end item number, LinkButtons for next and
previous page, etc. etc.

I'd like to be reuse the above component but may want to change the position
or alignment of the labels or link buttons or hide them completely.

What would be the best way to do this?



---------- Forwarded message ----------
From: Greg Brown <gk...@mac.com>
To: user@pivot.apache.org
Date: Fri, 29 Jan 2010 12:45:27 -0500
Subject: Re: Components made up of Java class and WTKX markup
Hi Cuong,

> Let's say I have the class AboutPane [extends BoxPane] and I have the
markup file AboutPane.wtkx which has the content
>
> <mycorp:AboutPane ...>
>     <Label wtkx:id="version" text="Version 1.0" />
> </mycorp>
>
> That is, AboutPane always has a Label to display a 'version' value.
>
> To include in my app, I do a '<wtkx:include src="AboutPane.wtkx />' in my
main markup file, but within AboutPane.java, how do I reference the
'version' property from within, say, AboutPane's constructor?

If AboutPane implements org.apache.pivot.wtkx.Bindable and declares a Label
member as follows, you can get access to the label in the initialize()
method:

@WTKX private Label version;

(the annotation is also defined in org.apache.pivot.wtkx)

> Inversely, I can do a '<mycorp:AboutPane />' in my main markup file, but
how do tell Pivot to parse and render AboutPane.wtkx (as it automagically
includes the version Label)?

Not entirely sure what you are looking for, but perhaps you want to use an
include?

<wtkx:include src="AboutPane.wtkx"/>

Hope this helps,
Greg

Re: Components made up of Java class and WTKX markup

Posted by Greg Brown <gk...@mac.com>.
Hi Cuong,

> Let's say I have the class AboutPane [extends BoxPane] and I have the markup file AboutPane.wtkx which has the content
> 
> <mycorp:AboutPane ...>
>     <Label wtkx:id="version" text="Version 1.0" />
> </mycorp>
> 
> That is, AboutPane always has a Label to display a 'version' value.
> 
> To include in my app, I do a '<wtkx:include src="AboutPane.wtkx />' in my main markup file, but within AboutPane.java, how do I reference the 'version' property from within, say, AboutPane's constructor?

If AboutPane implements org.apache.pivot.wtkx.Bindable and declares a Label member as follows, you can get access to the label in the initialize() method:

@WTKX private Label version;

(the annotation is also defined in org.apache.pivot.wtkx)

> Inversely, I can do a '<mycorp:AboutPane />' in my main markup file, but how do tell Pivot to parse and render AboutPane.wtkx (as it automagically includes the version Label)?

Not entirely sure what you are looking for, but perhaps you want to use an include?

<wtkx:include src="AboutPane.wtkx"/>

Hope this helps,
Greg