GWT 中的 MVP。复杂的观点
有一个关于在复杂视图上使用 mvp 的问题。 假设,我们有一些采用样板设计的小部件(ListWidget),如下所示:
控制按钮提供在 ContentPanel(只是带有数据的常规 CellTable)和 DetailsPanel(在这里我们可以编辑特定条目)之间切换的功能,这不是模态对话框)
DetailsPanel 又具有此结构
Button1、Button2、Button3 应该只处理 DetailsPanel 并更改 ActionPanel (ActionPanel 是某种向导,因此其内容应该单击 Button1、Button2 或 Button3 后会完全更改),但“保存”和“取消”按钮应该将我们带回 ListWidget。
- 我应该使用什么方法来实现所描述的功能?
- 我是否应该使用 2 个不同的 ActivityManager,其中之一在主上下文中?
- 如何管理和广播消息到ListWidget上的依赖面板? (是否可以将处理程序放入视图中,然后在某些操作上将事件推送到内部事件总线中? 例如,当我在DetailsPanel中保存项目时,PreviewPanel应该发生变化,并且该项目应该集中在CellTable中;等)
- 如果我应该将模式与两个不同的 ActivityManager 一起使用,我应该如何处理活动更改行为?
谢谢,希望有人帮助我。
Have a question about using mvp on complicated views.
Suppose, we have some widget with boilerplate design (ListWidget) like this:
Control buttons provide functionality for switching between ContentPanel (just regular CellTable with data) and DetailsPanel (here we can edit particular entry, this is not Modal Dialog)
DetailsPanel, in turn, have this structure
Button1, Button2, Button3 should deal only with DetailsPanel and change ActionPanel (ActionPanel some kind of wizard, so its content should be tottaly changed after Button1, Button2 or Button3 clicked), but Buttons Save and Cancel should navigate us back onto ListWidget.
- What approach should I use to implement described functionality?
- Should I use 2 different ActivityManagers with one of them in master context or not?
- How to manage and broadcast messages to dependant panels on ListWidget? (Is it ok to put Handlers in Views and just push event into inner eventBus on some actions?
For instance, when I save item in DetailsPanel, PreviewPanel should change and this item should be focused in CellTable; etc) - If I should use pattern with two different ActivityManagers, how exactly should I handle activity change behavior?
Thanks, hope somebody helps me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我先回答你的问题,先做一个简短的解释,然后逐条回答你的问题。
在框架级别,您可以有一个实现
ValueChangeHandler
的类,并使用History.addValueChangeHandler(controller);
在历史记录上设置它,假设控制器正在实现值更改处理程序您的任何 newItem将使用
History.newItem("NameOfAction")
放入历史记录中,将调用ValueChangeHandler
的实现,在本例中将是controller
现在,在
ValueChangeHandler
的实现中,您可以现在让我们讨论框架的第二部分,演示者和视图实现。我假设 RootPanel 是所有 UI 小部件的容器。您可以为每个操作创建单独的演示者
presenter = new ActionPresenter(rpc, eventbus, new ActionView())
请注意,我正在创建一个视图并传递给演示者,演示者获取数据并构建视图与数据。您稍后可以将容器传递给演示者以在 UI 上显示整个内容。
现在,关于您的具体问题,
希望这有帮助!
I am answering your question, first with a brief explanation and then point by point taking your questions.
At framework level, you could have a class which implements
ValueChangeHandler
and set that on History usingHistory.addValueChangeHandler(controller);
assuming controller is implementing the value change handlerAny newItem you would put in history with
History.newItem("NameOfAction")
would invoke implementation ofValueChangeHandler
which in this case would becontroller
Now within implementation of
ValueChangeHandler
you canNow let's talk about the second part of framework, presenter and view implementation. I am assuming that RootPanel is the container of all your UI Widgets. You can create individual presenters for each action
presenter = new ActionPresenter(rpc, eventbus, new ActionView())
Notice that I am creating a view and passing on to the presenter, presenter gets data and build the view with data. You could later pass on the container to the presenter to show the whole thing on UI.
Now about your specific questions
Hope this helps!