Monday, September 20, 2010

Re: MVP pattern and dynamic widgets

I think you need a TagPresenter.

public TagPresenter(Tag tag) {
// Set the name to the view (checkbox)
this.tag = tag;
}

// Capture click event {
tag.setChecked(false);
}

When you end editing your list will be updated, cause you are sharing
the Tag instance with the TagPresenters.

Best

On Mon, Sep 20, 2010 at 7:28 AM, daniel <d.brelovsky@googlemail.com> wrote:
> Maybe you can give the Tags (currentUser.getTags()) to the view, so
> that the view is responsible for creating checkboxes or whatever, so
> the presenter does not have to deal with widgets.
> the view can map each Tab to the created Checkbox (to avoid the for-
> loop) und call a method like tagChanged(Tag) in the presenter whenever
> a checkbox is clicked
>
> On 20 Sep., 03:18, Sydney <sydney.henr...@gmail.com> wrote:
>> My question is related to the MVP pattern. I have a VerticalPanel in
>> which I add several CheckBox. The UI is build on the fly since it
>> depends on the user settings. The user clicks some of the checkboxes
>> and in my presenter I would like to know which one are selected. What
>> should I put in my view interface of the presenter. My current
>> approach is the following:
>>
>> The presenter:
>>
>> public interface MyView {
>>   HasWidgets getTagsContainer();
>>   void showTagsContainer(); // Do a setVisible in the view
>>   HasValue<Boolean> getCheckBox(int i); // Return the ith checkbox
>>
>> }
>>
>> // Build the UI in the fly
>> HasWidgets tagsContainer = getView().getTagsContainer();
>> tagsContainer.clear();
>> for (Tag tag : currentUser.getTags()) {
>>   tagsContainer.add(new CheckBox(tag.getTagName()));}
>>
>> getView().showTagsContainer();
>>
>> The user clicks on some of the checkboxes
>>
>> // Find the one which are checked
>> int i=0;
>> for(Tag tag: currentUser.getTags()) {
>>   boolean checked = getView().getCheckBox(i).getValue();
>>   i++;
>>
>> }
>>
>> What do you think of my approach? Is there a better way to achieve it?
>> I am learning the MVP pattern, so I try to get the best practices.
>
> --
> You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
> To post to this group, send email to google-web-toolkit@googlegroups.com.
> To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
>
>

--
Guit: Elegant, beautiful, modular and *production ready* gwt applications.

http://code.google.com/p/guit/

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment