Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT List editor binding

public interface Person {
    String getName();
    void setName(String name);
    List<PersonFriend> getFriends();
}

public interface PersonFriend {
    String getName();
}

I'm trying to implement a view-only editor for Person:

public class PersonViewEditor extends Composite implements Editor<Person> {
    private static PersonViewEditorUiBinder uiBinder = GWT.create(PersonViewEditorUiBinder.class);
    interface PersonViewEditorUiBinder extends UiBinder<Widget, PersonViewEditor> {}

    @UiField Label nameEditor;
    @UiField PersonFriendsViewEditor friendsEditor;

    @UiField FancyAnchor editAnchor;

    public PersonViewEditor(ClientFactory clientFactory) {
        initWidget(uiBinder.createAndBindUi(this));
        editAnchor.setPlace(
                clientFactory.getPlaceHistoryMapper(), 
                clientFactory.getPlaceController(), 
                new EditPersonPlace());
    }
}

public class PersonFriendsViewEditor extends Composite {
    private static PersonFriendsViewEditorUiBinder uiBinder = GWT.create(PersonFriendsViewEditorUiBinder.class);
    interface PersonFriendsViewEditorUiBinder extends UiBinder<Widget, PersonFriendsViewEditor> {}

    interface Driver extends SimpleBeanEditorDriver<List<PersonFriend>, ListEditor<PersonFriend, PersonFriendViewEditor>> {}

    private class PersonFriendViewEditorSource extends EditorSource<PersonFriendViewEditor> {
        @Override
        public PersonFriendViewEditor create(int index) {
            PersonFriendViewEditor friend = new PersonFriendViewEditor();
            containerPanel.insert(friend, index);       
            return friend;
        }       
    }

    @UiField HorizontalPanel containerPanel;

    public PersonFriendsViewEditor() {
        initWidget(uiBinder.createAndBindUi(this));     
        Driver driver = GWT.create(Driver.class);
        ListEditor<PersonFriend, PersonFriendViewEditor> editor = ListEditor.of(new PersonFriendViewEditorSource());
        driver.initialize(editor);  
    }
}

When I bind Person object to PersonViewEditor, friendsEditor is never bound to person's friends list. It looks like PersonFriendsViewEditor should implement some magic interface to allow GWT interact with it, but I can't find any related docs. There's dynatablerf example in GWT, but they bind their list editor explicitly and I'm curious about binding it as a part of "outer" object, so I just bind Person to PersonViewEditor and it has all the data/sets all the widgets.

Any thoughts?

like image 601
Andrey Agibalov Avatar asked Oct 22 '11 12:10

Andrey Agibalov


1 Answers

PersonFriendsViewEditor should implement IsEditor<ListEditor<PersonFriend, PersonFriendViewEditor>> - that resolved the issue.

like image 131
Andrey Agibalov Avatar answered Sep 23 '22 01:09

Andrey Agibalov