如何为 GWT DecoratedTabPanel 实现复合视图/演示器?
我是 GWT 的新手,我一直在审查使用 rpcService 和 eventBus 的 MVP 实现。我想知道如何实现选项卡面板,以便每个选项卡都有自己的子视图。我一直在制作一个从面板派生的自定义小部件,或者弄清楚如何让一个演示者使用另一个演示者,或者创建一个为我处理这一切的复合演示者类之间犹豫不决。
有没有人对如何分离每个选项卡的功能而不是将实现保留在一个视图/演示者对中提出建议?
I'm new to GWT, and I've been reviewing the MVP implementation which uses the rpcService and the eventBus. I was wondering how a tab panel can be implemented such that each tab has its own sub-view. I have been waffling between making a custom widget that derives from a panel, or to figuring out how to make a presenter use another presenter, or to make a compound presenter class which handles it all for me.
Does anyone have advice on how to separate the functionality for each tab as opposed to keeping the implementation within one view/presenter pair?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同样的情况,但决定更改我的实现以模拟 TabPanel。如果您的视图和演示者不需要彼此交互(例如将某些内容从一个选项卡拖动到另一个选项卡),那么我认为通过将视图加载到共享的 SimplePanel 中来分离功能会更容易。您可以使用一个小部件来模拟 TabPanel 的选项卡部分,该小部件侦听 PlaceChangeEvents(以更改突出显示的选项卡)并将 goTo 命令发送到您的应用程序正在使用的 PlaceController(以处理不同标题上的点击)。
实现这个花了几个小时,并且生成的代码更加干净。我最初的尝试涉及监听 PlaceChangeEvents,然后调用适当的 tabPanel.selectTab() 函数,但试图弄清楚如何启动和停止不同选项卡的演示者太混乱了 - 就像您所建议的那样,您必须实现您自己的复合视图模型。
I was in the same situation, but decided to change my implementation to simulate a TabPanel. If your views and presenters don't need to interact with each other (e.g. dragging something from one tab to another) then I think it'll be easier to separate functionality by loading your View into a shared SimplePanel. You can simulate the tabbed portion of the TabPanel with a widget that listens for PlaceChangeEvents (to change the highlighted tab) and sends goTo commands to the PlaceController your app is using (to handle clicks on the different headers).
It took a couple of hours to implement this, and the resulting code is much cleaner. My initial attempt involved listening for PlaceChangeEvents and then calling the appropriate tabPanel.selectTab() function, but trying to figure out how to start and stop the presenters for the different tabs was too jumbled up - like you suggest, you'd have to implement your own compound view model.
我解决了这个问题,没有伪造主选项卡,而是使用 GWT 基本 SDK 提供的选项卡。我这样做的方法是:
这一切都像魅力一样。 MainTabPresenter 非常薄,并且允许将 View/Presenters 的完整实现写入到它们自己的文件中。
I solved this without faking a main tab, but using the one provided with GWT's basic SDK. I did this by:
It all works like a charm. The MainTabPresenter so very thin, and allows for complete implementations of View/Presenters to be written into their own files.