Organizing source code

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Organizing source code

Postby cochand » Wed Jul 13, 2005 11:45 am

As I continue to build my first SWT Designer UI, I am wondering how best to modularize the application in terms of .java files, classes, and methods.

I am starting with an SWT Application, as part of a Designer SWT/JFace Java Project. The left hand side of the app is a SWT Control Tree sitting inside a Composite. The right hand side is a Composite with a StackLayout.

There will be 20 to 30 leaf nodes in the left hand side tree. Clicking on any one of these leaf nodes will display a different "stack" in the right hand side. So, I'll have 20+ stacks that will be displayed in the right hand side. Some nodes will by dynamically added to the tree, based on the business logic.

By default, the entire UI gets dumped into the createContents() method. I have started to hand edit the main .java file that was created when I created a new SWT Application. I have started to break createContents() this into multiple private methods, many associated with each individual stack.

This would appear to work just fine, but I'm looking for any tips and advice. My .java file, and this class, is going to get huge. I don't have a major problem with this, as long as it is a sensible approach. I'm wondering if instead I should somehow be creating multiple java classes for the UI? Or should I leave the entire UI in this one .java file?

Eventually, I'll be adding business logic. I assume I'll create these in separate .java files. How does SWT Designer accomodate that?

Feel free to point me to other Instantiations or other newsgroup posts, eclipse help, or whatever else you recommend. I'm simply trying to use the "right" SWT-Designer/Eclipse/Java approach from the beginning.

Posts: 17
Joined: Wed Jul 06, 2005 1:20 pm

Re: Organizing source code

Postby Eric Clayberg » Wed Jul 13, 2005 12:22 pm

cochand wrote:I'm wondering if instead I should somehow be creating multiple java classes for the UI? Or should I leave the entire UI in this one .java file?

I would suggest creating each composite as a separate Composite subclass. You can then embed those composites within your main class as needed. Here's a nice flash demo illustrating this.

You should also separate out your business logic as much as possible into other classes.
Eric Clayberg
Software Engineering Manager

Author: "Eclipse Plug-ins"
Eric Clayberg
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 1 guest