Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add(Widget) to buffer rather than directly to a Smart ui parent node #2

Open
GoogleCodeExporter opened this issue Dec 23, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant