Tuesday, July 22, 2014

How to use a ListEditor with a backing list

Hi all,

sorry for spamming this group a bit at the moment, but i am really stuck on several fronts.

I have a parent presenter which works fine. I stripped it down to a few lines to make it easier do discuss:
public class ContainerEditorDialogPresenterWidget extends PresenterWidget<ContainerEditorDialogPresenterWidget.MyView> implements
ContainerEditorDialogUiHandlers {
//Constructor, view interface removed ...
    private ContainerDto currentContainerDTO = null;
    
    private SimpleBeanEditorDriver<ContainerDto, ?> driver;


@Override
public void onReveal() {
   super.onReveal();
   driver.edit(currentContainerDTO); // this will populate your view with the data from your POJO
}
    @Override
    protected void onBind() {
    super.onBind();
      driver = getView().createEditorDriver();
    }
    
    @Override
    public void updateContainer() {
ContainerDto container = driver.flush();
//Here the groupList is null
eventBus.fireEvent(new ContainerUpdatedEvent(container));
}
    
}


I guess this is fine. I have a child-editor declared in the view:
@UiField GroupListEditor groupListEditor;

and it looks like this:
public class GroupListEditor extends Composite implements
IsEditor<ListEditor<String, GroupItemEditor>> {

private static StringListEditorUiBinder uiBinder = GWT
.create(StringListEditorUiBinder.class);

interface StringListEditorUiBinder extends
UiBinder<Widget, GroupListEditor> {
}

@UiField
FlowPanel pWidget;

@UiField
PushButton bAdd;

@UiField
FlowPanel pList;
ArrayList<String> backingList = new ArrayList<String>();


private class StringItemEditorSource extends EditorSource<GroupItemEditor> {
@Override
public GroupItemEditor create(final int index) {
GroupItemEditor subEditor = new GroupItemEditor();
pList.insert(subEditor, index);
subEditor
.addDeleteHandler(new EditorDeleteEvent.EditorDeleteHandler() {
public void onEditorDeleteEvent(EditorDeleteEvent event) {
remove(index);
}
});
return subEditor;
}

@Override
public void dispose(GroupItemEditor subEditor) {
subEditor.removeFromParent();
}

@Override
public void setIndex(GroupItemEditor editor, int index) {
pList.insert(editor, index);
}
}

private ListEditor<String, GroupItemEditor> editor = ListEditor
.of(new StringItemEditorSource());



public GroupListEditor() {
initWidget(uiBinder.createAndBindUi(this));
editor.setValue(this.backingList);
}


@UiHandler("bAdd")
void onBAddClick(ClickEvent event) {
Log.debug("Add button clicked");
add();
}

private void add() {
String s = "Stuff";

editor.setValue(this.backingList);
editor.getList().add(s);
}

@Override
public ListEditor<String, GroupItemEditor> asEditor() {
return editor;
}

private void remove(final int index) {
editor.getList().remove(index);
}

}


What i do not understand: How do i associate the backing list with this sub-editor? Convention says that by calling the Editor groupListEditor, it edits the groupList property of the ContainerDto. But the backing list is still empty. Then i tried to assign the backing list with a call to groutListEditor.asEditor() fromt the parent view, the list does still not get set. 
When i do it in the same method like in the add() above:
editor.setValue(this.backingList);
editor.getList().add(s);

I can add an item and get it displayed in the GUI. But when i flush the driver in the parent presenter, calling getGroupList() returns null.
What would be the right way to do it?

Thanks you very much!

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment