开发者

Java SWT design patterns

What are some good design patterns for creating a form in java?

I have an app that has 6 tabs with a different form in each. How does the typical java programmer go about making these items accessible?

For example as a wpf programmer I might databind all these controls to underlying 开发者_如何学Pythonobjects.

What do java programmers like to do?


I don't know what programmers like to do, but you should listen to what MVC patterns tells.

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 e.g. 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.

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).

Things like EMF is quite complicated. 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.

For saving simple form all you have to do is write something like save method, e.g.:

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.


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.

EMF provides data binding between the UI widget and the model, you can read the generated code to see how it works.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜