public class PersonListEditor extends Composite implements IsEditor<ListEditor<Person, PersonListItemWidget>> { private static PersonListEditorUiBinder uiBinder = GWT.create(PersonListEditorUiBinder.class); interface PersonListEditorUiBinder extends UiBinder<Widget, PersonListEditor> {} private class Source extends EditorSource<PersonListItemWidget> { @Override public PersonListItemWidget create(int index) { PersonListItemWidget widget = new PersonListItemWidget(); panel.insert(widget, index); return widget; } } @UiField VerticalPanel panel; private ListEditor<Person, PersonListItemWidget> editor = ListEditor.of(new Source()); public PersonListEditor() { initWidget(uiBinder.createAndBindUi(this)); } @Override public ListEditor<Person, PersonListItemWidget> asEditor() { return editor; } }
PersonListItemWidget has a delete button, and when this button is clicked, I need to remove the related item from the list.
I can give the PersonListEditor notifications about widgets of elements (for example, "my delete button is pressed"), but in this case I will only have a link to the widget, and not to the real Person object that I really need. I can also add some logic to get the associated widget index from the list of panel items, and then get the Person object at that index, but it looks awful.
I can do PersonListItemWidget PersonListItemWidget ValueAwareEditor , so every widget will know its Person , but the whole idea of ValueAwareEditor looks like an MVP violation for me, since Google says that the layer view should not know the model, and it should only be “buttons” and “labels” "
What is the right approach here?
java mvp gwt gwt-editors
Andrey Agibalov
source share