GWT Editors Frame - ListEditor, Removing Items, MVP Violation

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?

+4
java mvp gwt gwt-editors
source share
1 answer

Any approach is great.

MVP is not installed in stone (it is not even defined, it was coined by Martin Fowler, but he deleted the term in favor of two more specific patterns), so you break only the rules that you gave yourself. In other words, the framework of the editor as a whole can be regarded as a violation of MVP: each editor knows the model, not necessarily the exact instance that he is editing (as with ValueAwareEditor or LeafValue ), but at least such objects are an editor.

FYI, we do this using indexes. The fact is that it is guaranteed to work than the fact that it "looks good" (although it is clearly better if it also looks good).

+2
source share

All Articles