> > Since these class info is used to initialize the internal attributes and 
> > elements of TableView instance, if this class info was set after the 
> > generic class instance is created, we need to call some initialization 
> > method at the timing.
> 
> Can you elaborate on your concern here?
> 
> My concern is rather purity of implementation. If we don't call 
> setBeanType(cls), the created object don't have any specific GUI info since 
> it has no info to create it.

It will still have a GUI - by default, TableView contains an empty column 
sequence, which is perfectly valid. Calling setColumns(Class<?>) would simply 
create a new (non-empty) sequence.

> So the initialization must be taken place at the setter setBeanType(cls), 
> for instance it will be :
> 
> void setBeanType(Class<?> cls) {
>     this.cls = cls;
>     initialize();
> }
> 
> void initialize() {
>     for (final Field field: cls.getFields()) {
>               final String fname = field.getName();
>               getColumns().add(new TableView.Column() {{
>                       setName(fname);
>                     setWidth(3, true);                            
>                     ....
> }

Why not just put the initialize() code in the setter? Nothing else needs to 
call it.

> If setter is invoked twice, i will initialize twice (although we can use some 
> flag to avoid this, but I think it is ugly)

Why would the setter be invoked twice?

> So conceptually, it is better to pass class object at the time of instance 
> creation.

That isn't supported in BXML. Anything instantiated in BXML needs a default 
no-arg constructor - all properties are specified via setters.

G


Reply via email to