SWT Application/shell generation

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

SWT Application/shell generation

Postby kenlars99 » Wed Jun 09, 2004 12:13 am

When designer generates the code for an Application, it generates an open() method that does everything: creates the display, initializes the shell, and runs the message loop.

In my situation, I'm really using the Application like a Form Dialog, and I'd like a little more control. What would be ideal would be if there were a member that just created the shell.

So for example:

public class MyApplication
{
public void open()
{ Shell shell = createShell(new Display);
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
}
public Shell createShell(Display display)
{
// generated code to put controls in the Shell goes here...
}

}

(Now, I can do this myself, and it doesn't seem to trip the designer up... nice!)

Why do I want this functionality broken out? I should be able to create the dialog without running it. For example, I think a modeless dialog would not use the same dispatch code (would it?). Perhaps I'd want to pass a specific display rather than creating a new one. In my case, I need to be able to do some reflection on the shell to generate some other code I need.

So to have it automatically be able to split out the code, as some kind of a preference, would be nice. I have a lot of dialogs in my app...

Ken
kenlars99
 
Posts: 3
Joined: Tue Jun 08, 2004 11:51 pm

Re: SWT Application/shell generation

Postby Eric Clayberg » Wed Jun 09, 2004 9:44 am

kenlars99 wrote:When designer generates the code for an Application, it generates an open() method that does everything: creates the display, initializes the shell, and runs the message loop.

The above is only the case if you use the defaults from the SWT Application wizard. You also have the option of creating the shell and its contents in a createContents() method which is called by the open() method. That would seem to address your concern almost perfectly.

Ultimately, you could use almost any template for your windows. You don't need to use the SWT Application wizard provided by Designer. For example, you could pass the display as an argument to the createContents() method or change the name of the method to createShell(). Designer would not care about either change.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Postby kenlars99 » Wed Jun 09, 2004 9:58 am

When you say I have the option, do you mean by setting some option in the designer preferences, or by just changing the code myself?

Right now, I'm changing my code, and that seems to work ok. I guess the thing that is wierd is that SWT allows Composite to be subclassed to create a "user control", but does not allow Shell to be subclassed to create a "form"... (using microsoft terminology). So the programmer, the gui builder, are free to define any kind of class to use as a "form".... this is flexible, but is a little wierd and makes standardization harder.

Ken
kenlars99
 
Posts: 3
Joined: Tue Jun 08, 2004 11:51 pm

Postby Eric Clayberg » Wed Jun 09, 2004 12:43 pm

kenlars99 wrote:When you say I have the option, do you mean by setting some option in the designer preferences, or by just changing the code myself?

I was referring to the option that is in the SWT Application wizard itself (the three radio buttons at the bottom of the wizard). It provides for creating the window contents in the main() method, the open() method or the createContents() method. You can always change the code and refactor it later, if you need to.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
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