Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swing with Guice

I'm already using Guice for the data model of my app, and so far I'm quite happy with it. However, the GUI part is about to become a Big Ball of Mud. I find it hard to use Guice here, because Swing components and models are tightly coupled, and often force a certain initialization order.

My application consists basically of a header with a lot of filters, a central and quite complex JTree component, and a lot of actions (e.g. from a JPopup), menus, dialogs, wizards etc. The main problem is that I have a lot of coupling between the components and actions (e.g. complicated validations, tree updates...). Could you give me some advice how to structure that GUI with Guice?

I'm aware of libs like GUTS, but the documentation is really thin, I'd rather avoid to add another dependency to my project and to learn another API (e.g. I don't know the Swing Application Framework).

like image 254
Landei Avatar asked Feb 28 '11 15:02

Landei


2 Answers

I'd rather suggest a proper MVC, even better Presentation Model - View - Controller. Separate your code properly and Guice will fit in naturally. For example:

View classes should have a building part which draws the static content (labels, the tree, buttons, etc) and updating code which reacts to changes in the Presentation Model. All the action listeners should invoke some code on the controller. Both the Presentation Model and the controller should be injected by Guice, like all the other dependencies.

This organization would allow for easy testing with replacing the View with some testing code which will listen to changes in the Presentation Model and invoke actions on the controller.

like image 95
Boris Pavlović Avatar answered Oct 04 '22 11:10

Boris Pavlović


I would advise to look at Guts-GUI. It is a Swing UI framework based on Guice dependency injection model.

like image 24
Eugene Ryzhikov Avatar answered Oct 04 '22 12:10

Eugene Ryzhikov