简体   繁体   English

Java SWT设计模式

[英]Java SWT design patterns

What are some good design patterns for creating a form in java? 在java中创建表单有哪些好的设计模式?

I have an app that has 6 tabs with a different form in each. 我有一个应用程序有6个选项卡,每个选项卡都有不同的表单。 How does the typical java programmer go about making these items accessible? 典型的java程序员如何使这些项目可访问?

For example as a wpf programmer I might databind all these controls to underlying objects. 例如,作为一个wpf程序员,我可能会将所有这些控件数据绑定到底层对象。

What do java programmers like to do? java程序员喜欢做什么?

I don't know what programmers like to do, but you should listen to what MVC patterns tells. 我不知道程序员喜欢做什么,但你应该听听MVC模式所说的内容。

And it tells you that each view should have its controller. 它告诉你每个视图应该有它的控制器。 Your view has obviously subviews. 您的观点显然有子视图。 So the design in this case would obviously be following: 所以这种情况下的设计显然会遵循:

MainView
    Label1
    Text1
    Tab1Subview
        Label1
        Text1
    Tab2Subview
        Label1
        Text1


MainViewController
   Tab1SubviewController
   Tab2SubviewController

And controllers will define the binding for each particular view. 控制器将为每个特定视图定义绑定。 You can also use one single controller for all subviews and bind it inside. 您还可以为所有子视图使用一个控制器并将其绑定在内部。 Your main controller could have a link to main root model object eg Forms. 您的主控制器可以链接到主根模型对象,例如表单。 And particular controller could bind subobjects. 特定的控制器可以绑定子对象。 As I already said again - you can go with one big controller and bind it all in one place. 正如我已经说过的那样 - 你可以使用一个大控制器并将它们绑定在一个地方。

This is for what MVC was created. 这是为了创建MVC。

Tools 工具

If you are looking for SWT graphical designer, then the Window Builder Pro (Eclipse Plugin) - is definitely is the choice (not perfect although, but the better of all available). 如果您正在寻找SWT图形设计器,那么Window Builder Pro(Eclipse插件) - 肯定是选择(虽然不是很完美,但是可用性更好)。

Things like EMF is quite complicated. 像EMF这样的事情非常复杂。 You can start with a mix of Window Builder Pro and coding and as mentioned above JFace Binding API will be an option - but it's not necessary - depend on model you can use either JFace Binding or do it yourself in the code. 您可以从混合使用Window Builder Pro和编码开始,如上所述,JFace Binding API将是一个选项 - 但这不是必需的 - 依赖于模型,您可以使用JFace Binding或在代码中自己完成。

For saving simple form all you have to do is write something like save method, eg: 为了保存简单的表单,您只需编写类似save方法的内容,例如:

person.setName(view.getFullNameTextField().getText());

this is not much worse than using advanced binding features, especially if you don't won't dependance on extra libraries like JFace. 这并不比使用高级绑定功能差很多,特别是如果你不依赖于像JFace这样的额外库。

If you are using Eclipse, you can try EMF, an amazing framework helps you to design your model, generate Java code, and provides a pretty cool model editor in minutes. 如果您正在使用Eclipse,您可以尝试EMF,一个惊人的框架可以帮助您设计模型,生成Java代码,并在几分钟内提供一个非常酷的模型编辑器。

EMF provides data binding between the UI widget and the model, you can read the generated code to see how it works. EMF提供UI小部件和模型之间的数据绑定,您可以读取生成的代码以查看其工作原理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM