pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Brown <gkbr...@mac.com>
Subject Re: ListButton - Is it the correct way?
Date Mon, 02 Aug 2010 18:07:51 GMT
Hi Alejandro, 

I don't fully understand the question. ListButton doesn't currently have a "render" property
- what would this property do?

Note that you can instantiate your renderer in a define block and then refer to it elsewhere.
This may help reduce the verbosity of your markup:

<bxml:define>
    <renderers:CustomItemRenderer bxml:id="customItemRenderer"/>
</bxml:define>

...

<ListButton itemRenderer="$customItemRenderer"/>

Note that this is also supported in WTKX in Pivot 1.5 - you don't need to wait for 2.0 to
do this.

Hope this helps.

Greg


On Aug 2, 2010, at 1:10 PM, Alejandro Vilar wrote:

> Hi again,
> Related to all renderers in pivot bxml files, it will possible to use a some kind of
reflection to render some data? (specially with text type data)
>  
> For example:
>  
> <ListButton render="${name} - ${address}"/>
>  
> And use reflection to get fields inside curly brackets, also it will be helpful with
resources files to customize rendered data by a custom localization:
>  
> <ListButton render="%renderers.customer"/>
>  
> In my current project we have about 15 POJOs with list, data and table renderers each
one.
>  
> <ListButton>
> <dataRenderer>
> <renderers:CustomerButtonRenderer/>
> </dataRenderer>
> <itemRenderer>
> < renderers:CustomerItemRenderer/>
> </itemRenderer>
> </ListButton>
>  
> It’s a little verbose…
>  
>  
> Regards,
> Alejandro
>  
> From: Alejandro Vilar [mailto:alejandro.vilar@synacom.com.bo] 
> Sent: lunes, 02 de agosto de 2010 12:47 p.m.
> To: user@pivot.apache.org
> Subject: RE: ListButton - Is it the correct way?
>  
> Hi Stefano,
>  
> Your approach works well because "toString" method  only be called when a customer is
painted, but it doesn’t avoids some possible side effects in the rest of your code(i.e.
logging). Another way is to use renderers as follows:
>  
> import org.apache.pivot.wtk.Button;
> import org.apache.pivot.wtk.content.ButtonDataRenderer;
>  
> public class CustomerDataRenderer extends ButtonDataRenderer {
> @Override
> public void render(Object data, Button button, boolean highlighted) {
> super.render(data, button, highlighted);
> if (data instanceof lbtCustomer) {
> lbtCustomer customer = (lbtCustomer) data;
> super.label.setText(customer.getName() + "-" + customer.getAddress());
> }
> }
> }
>  
> Also you can keep the computed name inside a variable in your lbtCustomer instance to
compute it  just once. To setup this renderer in your ListButton:
>  
>  
> ListButton listButton = new ListButton(customers);
> listButton.setDataRenderer(new CustomerDataRenderer());
> listButton.setItemRenderer(new CustomerItemRenderer());  //<-- same as data renderer,
but extending from ListViewItemRenderer
>  
> If you want get the chosen record:
>  
>                 lbtCutomer selectedCustomer = (lbtCutomer)listButton.getSelectedItem();
>  
> I’ll suggest override equals method in your lbtCustomer class, some list abilities
are based on it.
>  
> Hope this helps,
>  
> Alejandro
>  
>  
> From: Dr. Stefano Sancese [mailto:stefano@sancese.com] 
> Sent: lunes, 02 de agosto de 2010 11:20 a.m.
> To: user@pivot.apache.org
> Subject: ListButton - Is it the correct way?
>  
> Hi to all,
> 
> in a form, I have a ListButton that I need to populate with 1000 customers data (Id,
Name, Address).
> 
> I wrote this class:
> 
>     class lbtCustomer {
>             private String id;
>             private String name;
>             private String address;
> 
>             lbtCustomer(String c1, String c2, String c3) {
>                 id = c1;
>                 name = c2;
>                 address = c3;
>             }
> 
>             public String getKey() {
>                 return id;
>             }
> 
>             @Override
>             public String toString() {
>                return name + " - " + address;
>             }
>         }
> 
> and I populated the ArrayList of the ListButton with:
> 
>     ArrayList lbtValues = new ArrayList();
> 
>     lbtCustomer r1 = new lbtCustomer("1","John Doe","New York");;
>     lbtCustomer r2 = new lbtCustomer("8","Charlie Brown","Los Angeles");
>     lbtCustomer r3 = new lbtCustomer("2","Donald Duck","Orlando");
>     lbtCustomer r4 = new lbtCustomer("9","Snoopy","Los Angeles");
> 
>     lbtValues.add(r1);
>     lbtValues.add(r2);
>     lbtValues.add(r3);
>     lbtValues.add(r4);
> 
>     listButtonTest.setListData(lbtValues);
> 
> With the toString method I can format the information showed to the user and with the
getKey method I can retrieve the Id of the chosen record.
> 
> The test case works, but I wonder if there is a better way.
> 
> I'm concerned about the cost (CPU and memory) associated with the instantiation of the
1000 objects that I need for the real case.
> 
> Perhaps two array lists: one with the data to show to the user and the other to store
the id of the corresponding Customer?
> 
> 
> Ciao 
> 
> Stefano
> 
> 
> P.s. I'm realy green to java and - YES - I'm Reading the F...... Manuals. There are simply
too many of them ;-)
> 
> -- 
> Dr. Stefano Sancese
>  
> WatchGuard Certified System Professional - http://www.watchguard.com
> Socio Clusit - Associazione Italiana per la Sicurezza Informatica
>  
> ************************************************************************
>  
> In God we trust, all others we monitor (National Security Agency)
>  
> ************************************************************************


Mime
View raw message