Hi Greg,

                Sorry for my English, and yes it's a common use case in our
app and other several apps when text is used more than images/checkboxs/etc,
currently we have a renderer to do that(I'll try to share it, but I need to
check some internal policies first ;) ), we use it as follows:

 

Renderers.json

"renderers:"{

    "list":{

        "bill":"{amount} {currency}"

    }

}

Renderers_es.json

"renderers:"{

    "list":{

        "bill":"{currency} {amount}"

    }

}

 

<ListView textRenderer="%renderers.list.bill"/>

 

And we have results like this:

 

(Default locale)                $us. 123.00

 (ES locale)                         123.00 $us

 

Regards,

A

 

From: Greg Brown [mailto:[email protected]] 
Sent: lunes, 02 de agosto de 2010 02:13 p.m.
To: [email protected]
Subject: Re: ListButton - Is it the correct way?

 

Oh, I think I understand what you are asking now. No, we probably won't add
support for templates like this. Writing a custom renderer is already pretty
easy (especially if you use BXML), and it is much more flexible than a
string-based templating solution. However, if you find that this is a common
use case within your app, you could easily write your own renderer that
supports templates. If you do try this, I'd be curious to see what it looks
like.

 

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:[email protected]] 
Sent: lunes, 02 de agosto de 2010 12:47 p.m.
To: [email protected]
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:[email protected]] 
Sent: lunes, 02 de agosto de 2010 11:20 a.m.
To: [email protected]
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)
 
************************************************************************

 

Reply via email to