开发者

StackLayoutPanel and MVP

开发者 https://www.devze.com 2022-12-20 19:50 出处:网络
Think there might be something about this MVP approach I have completely misunderstood. Currently I am struggling to apply the MVP pattern to the part of my application consisting of a StackLayoutPan

Think there might be something about this MVP approach I have completely misunderstood.

Currently I am struggling to apply the MVP pattern to the part of my application consisting of a StackLayoutPanel (accordion). To me it se开发者_运维知识库ems natural to have a presenter and a view per stack... but how do I allow the different presenters to react when the user switch the state of the stack panel?

If someone could sketch an application of the MVP pattern in the case of an accordion application I would be really, really grateful! This is really getting on my nerves! ;D


Event bus might be way for you to pass the information between presenters - just be careful not to dump every possible event in the bus.

http://code.google.com/events/io/2009/sessions/GoogleWebToolkitBestPractices.html


The MVP-related classes provided by GWT have the limitation that basic application state is linked to places. Activities start and stop, and views are shown, depending on what place your are at, and that is linked to browser history/URL fragment identifiers.

With a stack panel, you're likely to switch between widgets in the stack without changing places. Nonetheless, it often makes sense to have separate activities and views for each widget in the panel.

The solution is to create a general activity and a general view for managing the stack panel, and then activities and views for each widget in the stack panel. Your general activity is a normal GWT activity but it acts as a small-scale activity manager for the embedded activities of the stack panel. The general activity will receive (via event bus and the general view) events about the activation or deactivation of widgets in the stack panel, will start and stop embedded activities as needed.

Tab panel presents a similar problem, in fact. You can check out how I implemented this for a tab panel by doing a quick git clone http://lais.mora.edu.mx/gitrepo/pescador.git and checking out java/webclient/src/main/java/mx/org/pescador/client/content/BodyContentActivityImpl.java and related code.

0

精彩评论

暂无评论...
验证码 换一张
取 消