GWT MVP - 维护彼此独立的多个显示器 [英] GWT MVP - maintaining multiple displays that are separate of one another

查看:103
本文介绍了GWT MVP - 维护彼此独立的多个显示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的应用程序布局类似于



MENU |内容

菜单和内容显示会动态变化,其中一个会与另一个分开更改。我的意思是,当内容显示改变时,我不想更新菜单显示,反之亦然。这两个显示器都需要能够响应PlaceChangeEvents并在发生这些事件时自行更新。问题是每个显示器只应响应某些PlaceChangeEvent而更新,而忽略指向另一个显示器的PlaceChangeEvent。然而,这并不适用于'标准'GWT MVP模式,因为即使每个显示器都有它自己的ActivityManager,它们也会自动拾取所有PlaceChangeEvents,因为在单个EventBus上有一个单独的PlaceController监听。我能看到做到这一点的唯一方法是拥有两个EventBus和两个PlaceController - 一个用于菜单,另一个用于内容。所以我的问题是这是一个好的解决方案,还是有一个更简单/更好的方法,我失踪了?这个解决方案的一个问题是,PlaceHistoryHandler只能使用其中一个EventBus进行注册。

解决方案

ActivityMappers。他们得到一个地方并返回相应的活动。这是您控制Places如何映射到活动的位置:


  1. 您需要创建两个ActivityMappers(MenuActivityMapper,ContentActivityMapper),然后使用它自己的ActivityMappers实例化两个ActivityManagers。然后,对于每个ActivityManager,您可以调用 setDisplay(AcceptsOneWidget display),其中对于您在区域(显示)中传递的每个区域都会显示其内容。


  2. 对于菜单,您可能只使用一个活动,因为它在所有位置都可用。因此, MenuActivityMapper.getActivity()将始终返回MenuActivity的同一个实例。为了使MenuActivity能够根据地点变化调整它的外观,MenuActivity应该听取PlaceChangeEvents。



I have a GWT App and I am using GWT MVP with Places / Activities.

My application layout is something like

MENU | CONTENT

The Menu and the Content displays will change dynamically and one changes separately from the other. What I mean by this is that when the Content display changes I do not want to have to update the Menu display and vice versa. Both displays need to be able to respond to PlaceChangeEvents and update themselves when these occur. The problem is that each display should only update in response to certain PlaceChangeEvents, ignoring PlaceChangeEvents that are directed at the other display. However this does not work using the 'standard' GWT MVP pattern because even when each display has it's own ActivityManager they will automatically pick up ALL PlaceChangeEvents because there is a single PlaceController listening on a single EventBus. The only way I can see to do this is by having two EventBus's and two PlaceControllers - one for the Menu and one for the Content. So my question is whether this is a good solution or is there a simpler/better way that I am missing? One problem with this solution is that the PlaceHistoryHandler can only be registered with one of the EventBus's.

解决方案

Place changes are actually controlled by ActivityMappers. They get a Place and return the corresponding Activity. This is where you control how Places are mapped to Activities:

  1. You need to create two ActivityMappers (MenuActivityMapper, ContentActivityMapper) and then instantiate two ActivityManagers each with it's own ActivityMappers. Then for each ActivityManager you call setDisplay(AcceptsOneWidget display) where for each you pass in an area (display) where it will show it's content.

  2. For menu you will probably only use one Activity, since it's available in all Places. So MenuActivityMapper.getActivity() will always return the same instance of the MenuActivity. To enable MenuActivity to still adapt it's look based on place changes, MenuActivity should listen to PlaceChangeEvents.

这篇关于GWT MVP - 维护彼此独立的多个显示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆