You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am advocating the following strategy
<zs:UIListGrid showResizeBar='true' width='100px'>
<zs:UIListGridFieldArray>
<zs:UITreeGridField>Personal Info</zs:UITreeGridField>
<zs:UITreeGridField>Avatar</zs:UITreeGridField>
<zs:UITreeGridField>Address</zs:UITreeGridField>
<zs:UITreeGridField>Email</zs:UITreeGridField>
</zs:UIListGridFieldArray>
</zs:UIListGrid>
rather than,
<zs:UIListGrid showResizeBar='true' width='100px'>
<zs:UITreeGridField>Personal Info</zs:UITreeGridField>
<zs:UITreeGridField>Avatar</zs:UITreeGridField>
<zs:UITreeGridField>Address</zs:UITreeGridField>
<zs:UITreeGridField>Email</zs:UITreeGridField>
</zs:UIListGrid>
The reason being -
Smart widgets do not have add(field) methods.
Rather they have setField(Widget[] ) methods. So we have to construct an
add(Widget) from setField(Widget[] ) method.
For example,
public void add(Widget widget) {
if (widget instanceof UIFormItem){
FormItem[] fields = getFields();
FormItem[] newFields = new FormItem[fields.length+1];
for (int i = 0; i < fields.length; i++) {
newFields[i] = fields[i];
}
newFields[fields.length] = ((UIFormItem)widget).getFormItem();
setFields(newFields);
}
}
This is not optimal because if we had to add 20 widgets to a parent node, the
array would have to be reconstructed 20 times.
However I am constructing uibinderable ArrayList buffers, on which we would
perform the individual add(Widget) operations. So that uibinder would add the
ArrayList buffer node to a parent node.
A uibinder buffer node would look like this:
public class UIListGridFieldArray
extends UIMasqueradedWidgetArray<UIListGridField, ListGridField>{
@Override
public void add(Widget widget) {
if (widget instanceof UIListGridField){
addMasqueradedWidget((UIListGridField)widget);
}
}
@Override
public boolean remove(Widget widget) {
if (widget instanceof UIListGridField){
return removeMasqueradedWidget((UIListGridField)widget);
}
return false;
}
public ListGridField[] toArray(){
ListGridField[] a = new ListGridField[smartObjects.size()];
smartObjects.toArray(a);
return a;
}
}
So that the add(Widget) of a parent node would give a choice to either add the
ui buffer or the child widgets directly:
public void add(Widget widget) {
if (widget instanceof UIListGridField){
// the usual way
}
else if (widget instanceof UIListGridFieldArray){
ListGridField[] newFields = ((UIListGridFieldArray)widget).toArray();
setFields(newFields);
}
}
Original issue reported on code.google.com by BlessedGeek on 12 Jul 2010 at 8:32
The text was updated successfully, but these errors were encountered:
Original issue reported on code.google.com by
BlessedGeek
on 12 Jul 2010 at 8:32The text was updated successfully, but these errors were encountered: